@@ -25,7 +25,7 @@ class TestEventFrequencyCountCondition(ConditionTestCase):
25
25
def setUp (self ):
26
26
super ().setUp ()
27
27
self .condition = Condition .EVENT_FREQUENCY_COUNT
28
- self .payload : dict [str , int | str ] = {
28
+ self .payload : dict [str , str | int | float ] = {
29
29
"interval" : "1h" ,
30
30
"id" : EventFrequencyCondition .id ,
31
31
"value" : 50 ,
@@ -74,14 +74,14 @@ def test_count_with_filters(self):
74
74
results = [dc .comparison ["value" ] - 1 ]
75
75
self .assert_slow_condition_does_not_pass (dc , results )
76
76
77
- def _test_dual_write (self , value : int ):
77
+ def _test_dual_write (self , value ):
78
78
dcg = self .create_data_condition_group ()
79
79
dc = self .translate_to_data_condition (self .payload , dcg )
80
80
81
81
assert dc .type == self .condition
82
82
assert dc .comparison == {
83
83
"interval" : self .payload ["interval" ],
84
- "value" : value ,
84
+ "value" : self . payload [ " value" ] ,
85
85
}
86
86
assert dc .condition_result is True
87
87
assert dc .condition_group == dcg
@@ -93,22 +93,21 @@ def _test_dual_write(self, value: int):
93
93
assert dc .type == self .condition
94
94
assert dc .comparison == {
95
95
"interval" : self .payload ["interval" ],
96
- "value" : value ,
96
+ "value" : self . payload [ " value" ] ,
97
97
}
98
98
assert dc .condition_result is True
99
99
assert dc .condition_group == dcg
100
100
101
101
def test_dual_write_count (self ):
102
- self ._test_dual_write (int ( self .payload ["value" ]) )
102
+ self ._test_dual_write (self .payload ["value" ])
103
103
104
104
def test_dual_write_count__string_value (self ):
105
- self .payload ["value" ] = str (self .payload ["value" ])
106
- self ._test_dual_write (int (self .payload ["value" ]))
105
+ self ._test_dual_write (str (self .payload ["value" ]))
107
106
108
107
def test_dual_write__value_floor (self ):
109
108
# forces negative to zero for migration
110
- self .payload ["value" ] = - 1
111
- self ._test_dual_write (0 )
109
+ self .payload ["value" ] = 0 # expected value
110
+ self ._test_dual_write (- 1 )
112
111
113
112
def test_json_schema (self ):
114
113
with pytest .raises (ValidationError ):
@@ -161,7 +160,7 @@ def test_json_schema(self):
161
160
class TestEventFrequencyPercentCondition (ConditionTestCase ):
162
161
def setUp (self ):
163
162
self .condition = Condition .EVENT_FREQUENCY_PERCENT
164
- self .payload : dict [str , int | str ] = {
163
+ self .payload : dict [str , str | int | float ] = {
165
164
"interval" : "1h" ,
166
165
"id" : EventFrequencyCondition .id ,
167
166
"value" : 50 ,
@@ -218,30 +217,29 @@ def test_percent_with_filters(self):
218
217
results = [10 , 10 ]
219
218
self .assert_slow_condition_does_not_pass (dc , results )
220
219
221
- def _test_dual_write (self , value : int ):
220
+ def _test_dual_write (self , value ):
222
221
dcg = self .create_data_condition_group ()
223
222
dc = self .translate_to_data_condition (self .payload , dcg )
224
223
225
224
assert dc .type == self .condition
226
225
assert dc .comparison == {
227
226
"interval" : self .payload ["interval" ],
228
- "value" : value ,
227
+ "value" : self . payload [ " value" ] ,
229
228
"comparison_interval" : self .payload ["comparisonInterval" ],
230
229
}
231
230
assert dc .condition_result is True
232
231
assert dc .condition_group == dcg
233
232
234
233
def test_dual_write_percent (self ):
235
- self ._test_dual_write (int ( self .payload ["value" ]) )
234
+ self ._test_dual_write (self .payload ["value" ])
236
235
237
236
def test_dual_write_percent__string_value (self ):
238
- self .payload ["value" ] = str (self .payload ["value" ])
239
- self ._test_dual_write (int (self .payload ["value" ]))
237
+ self ._test_dual_write (str (self .payload ["value" ]))
240
238
241
239
def test_dual_write__value_floor (self ):
242
240
# forces negative to zero for migration
243
- self .payload ["value" ] = - 1
244
- self ._test_dual_write (0 )
241
+ self .payload ["value" ] = 0 # expected value
242
+ self ._test_dual_write (- 1 )
245
243
246
244
def test_json_schema (self ):
247
245
with pytest .raises (ValidationError ):
@@ -318,7 +316,7 @@ class TestEventUniqueUserFrequencyCountCondition(TestEventFrequencyCountConditio
318
316
def setUp (self ):
319
317
super ().setUp ()
320
318
self .condition = Condition .EVENT_UNIQUE_USER_FREQUENCY_COUNT
321
- self .payload : dict [str , int | str ] = {
319
+ self .payload : dict [str , str | int | float ] = {
322
320
"interval" : "1h" ,
323
321
"id" : EventUniqueUserFrequencyCondition .id ,
324
322
"value" : 50 ,
@@ -330,7 +328,7 @@ class TestEventUniqueUserFrequencyPercentCondition(TestEventFrequencyPercentCond
330
328
def setUp (self ):
331
329
super ().setUp ()
332
330
self .condition = Condition .EVENT_UNIQUE_USER_FREQUENCY_PERCENT
333
- self .payload : dict [str , int | str ] = {
331
+ self .payload : dict [str , str | int | float ] = {
334
332
"interval" : "1h" ,
335
333
"id" : EventUniqueUserFrequencyCondition .id ,
336
334
"value" : 50 ,
@@ -343,10 +341,10 @@ class TestPercentSessionsCountCondition(TestEventFrequencyCountCondition):
343
341
def setUp (self ):
344
342
super ().setUp ()
345
343
self .condition = Condition .PERCENT_SESSIONS_COUNT
346
- self .payload : dict [str , int | str ] = {
344
+ self .payload : dict [str , str | int | float ] = {
347
345
"interval" : "30m" , # only percent sessions allows 30m
348
346
"id" : EventFrequencyPercentCondition .id ,
349
- "value" : 17 ,
347
+ "value" : 17.2 ,
350
348
"comparisonType" : ComparisonType .COUNT ,
351
349
}
352
350
self .intervals = PERCENT_INTERVALS
@@ -363,10 +361,10 @@ class TestPercentSessionsPercentCondition(TestEventFrequencyPercentCondition):
363
361
def setUp (self ):
364
362
super ().setUp ()
365
363
self .condition = Condition .PERCENT_SESSIONS_PERCENT
366
- self .payload : dict [str , int | str ] = {
364
+ self .payload : dict [str , str | int | float ] = {
367
365
"interval" : "30m" , # only percent sessions allows 30m
368
366
"id" : EventFrequencyPercentCondition .id ,
369
- "value" : 17 ,
367
+ "value" : 17.2 ,
370
368
"comparisonType" : ComparisonType .PERCENT ,
371
369
"comparisonInterval" : "1d" ,
372
370
}
@@ -385,7 +383,7 @@ class TestEventUniqueUserFrequencyConditionWithConditions(ConditionTestCase):
385
383
def setUp (self ):
386
384
super ().setUp ()
387
385
self .condition = Condition .EVENT_UNIQUE_USER_FREQUENCY_COUNT
388
- self .payload : dict [str , int | str ] = {
386
+ self .payload : dict [str , str | int | float ] = {
389
387
"interval" : "1h" ,
390
388
"id" : EventUniqueUserFrequencyConditionWithConditions .id ,
391
389
"value" : 50 ,
@@ -426,33 +424,32 @@ def setUp(self):
426
424
]
427
425
self .dcg = self .create_data_condition_group ()
428
426
429
- def _test_dual_write_count (self , value : int ):
427
+ def _test_dual_write_count (self , value ):
430
428
dc = create_event_unique_user_frequency_condition_with_conditions (
431
429
self .payload , self .dcg , self .conditions
432
430
)
433
431
434
432
assert dc .type == self .condition
435
433
assert dc .comparison == {
436
434
"interval" : self .payload ["interval" ],
437
- "value" : value ,
435
+ "value" : self . payload [ " value" ] ,
438
436
"filters" : self .expected_filters ,
439
437
}
440
438
assert dc .condition_result is True
441
439
assert dc .condition_group == self .dcg
442
440
443
441
def test_dual_write_count (self ):
444
- self ._test_dual_write_count (int ( self .payload ["value" ]) )
442
+ self ._test_dual_write_count (self .payload ["value" ])
445
443
446
444
def test_dual_write_count__string_value (self ):
447
- self .payload ["value" ] = str (self .payload ["value" ])
448
- self ._test_dual_write_count (int (self .payload ["value" ]))
445
+ self ._test_dual_write_count (str (self .payload ["value" ]))
449
446
450
447
def test_dual_write_count__value_floor (self ):
451
448
# forces negative to zero for migration
452
- self .payload ["value" ] = - 1
453
- self ._test_dual_write_count (0 )
449
+ self .payload ["value" ] = 0 # expected
450
+ self ._test_dual_write_count (- 1 )
454
451
455
- def _test_dual_write_percent (self , value : int ):
452
+ def _test_dual_write_percent (self , value ):
456
453
self .payload .update ({"comparisonType" : ComparisonType .PERCENT , "comparisonInterval" : "1d" })
457
454
dc = create_event_unique_user_frequency_condition_with_conditions (
458
455
self .payload , self .dcg , self .conditions
@@ -461,24 +458,23 @@ def _test_dual_write_percent(self, value: int):
461
458
assert dc .type == Condition .EVENT_UNIQUE_USER_FREQUENCY_PERCENT
462
459
assert dc .comparison == {
463
460
"interval" : self .payload ["interval" ],
464
- "value" : value ,
461
+ "value" : self . payload [ " value" ] ,
465
462
"comparison_interval" : self .payload ["comparisonInterval" ],
466
463
"filters" : self .expected_filters ,
467
464
}
468
465
assert dc .condition_result is True
469
466
assert dc .condition_group == self .dcg
470
467
471
468
def test_dual_write_percent (self ):
472
- self ._test_dual_write_percent (int ( self .payload ["value" ]) )
469
+ self ._test_dual_write_percent (self .payload ["value" ])
473
470
474
471
def test_dual_write_percent__string_value (self ):
475
- self .payload ["value" ] = str (self .payload ["value" ])
476
- self ._test_dual_write_percent (int (self .payload ["value" ]))
472
+ self ._test_dual_write_percent (str (self .payload ["value" ]))
477
473
478
474
def test_dual_write_count__percent_floor (self ):
479
475
# forces negative to zero for migration
480
- self .payload ["value" ] = - 1
481
- self ._test_dual_write_percent (0 )
476
+ self .payload ["value" ] = 0 # expected
477
+ self ._test_dual_write_percent (- 1 )
482
478
483
479
def test_dual_write__invalid (self ):
484
480
with pytest .raises (KeyError ):
0 commit comments