@@ -315,6 +315,76 @@ def test_using_rbs_in_excluded(self):
315315 assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 316316 ctx = evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
317317 assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 318+
319+ @pytest .mark .asyncio
320+ async def test_evaluate_treatment_with_rbs_in_condition_async (self ):
321+ e = evaluator .Evaluator (splitters .Splitter ())
322+ splits_storage = InMemorySplitStorageAsync ()
323+ rbs_storage = InMemoryRuleBasedSegmentStorageAsync ()
324+ segment_storage = InMemorySegmentStorageAsync ()
325+ evaluation_facctory = AsyncEvaluationDataFactory (splits_storage , segment_storage , rbs_storage )
326+
327+ rbs_segments = os .path .join (os .path .dirname (__file__ ), 'files' , 'rule_base_segments.json' )
328+ with open (rbs_segments , 'r' ) as flo :
329+ data = json .loads (flo .read ())
330+
331+ mocked_split = Split ('some' , 12345 , False , 'off' , 'user' , Status .ACTIVE , 12 , split_conditions , 1.2 , 100 , 1234 , {}, None , False )
332+ rbs = rule_based_segments .from_raw (data ["rbs" ]["d" ][0 ])
333+ rbs2 = rule_based_segments .from_raw (data ["rbs" ]["d" ][1 ])
334+ await rbs_storage .update ([rbs , rbs2 ], [], 12 )
335+ await splits_storage .update ([mocked_split ], [], 12 )
336+
337+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
338+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 339+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
340+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "off" 341+
342+ @pytest .mark .asyncio
343+ async def test_using_segment_in_excluded_async (self ):
344+ rbs_segments = os .path .join (os .path .dirname (__file__ ), 'files' , 'rule_base_segments3.json' )
345+ with open (rbs_segments , 'r' ) as flo :
346+ data = json .loads (flo .read ())
347+ e = evaluator .Evaluator (splitters .Splitter ())
348+ splits_storage = InMemorySplitStorageAsync ()
349+ rbs_storage = InMemoryRuleBasedSegmentStorageAsync ()
350+ segment_storage = InMemorySegmentStorageAsync ()
351+ evaluation_facctory = AsyncEvaluationDataFactory (splits_storage , segment_storage , rbs_storage )
352+
353+ mocked_split = Split ('some' , 12345 , False , 'off' , 'user' , Status .ACTIVE , 12 , split_conditions , 1.2 , 100 , 1234 , {}, None , False )
354+ rbs = rule_based_segments .from_raw (data ["rbs" ]["d" ][0 ])
355+ await rbs_storage .update ([rbs ], [], 12 )
356+ await splits_storage .update ([mocked_split ], [], 12 )
357+ segment = segments .
from_raw ({
'name' :
'segment1' ,
'added' : [
'[email protected] ' ],
'removed' : [],
'till' :
123 })
358+ await segment_storage .put (segment )
359+
360+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
361+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 362+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
363+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "off" 364+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
365+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "off" 366+
367+ @pytest .mark .asyncio
368+ async def test_using_rbs_in_excluded_async (self ):
369+ rbs_segments = os .path .join (os .path .dirname (__file__ ), 'files' , 'rule_base_segments2.json' )
370+ with open (rbs_segments , 'r' ) as flo :
371+ data = json .loads (flo .read ())
372+ e = evaluator .Evaluator (splitters .Splitter ())
373+ splits_storage = InMemorySplitStorageAsync ()
374+ rbs_storage = InMemoryRuleBasedSegmentStorageAsync ()
375+ segment_storage = InMemorySegmentStorageAsync ()
376+ evaluation_facctory = AsyncEvaluationDataFactory (splits_storage , segment_storage , rbs_storage )
377+
378+ mocked_split = Split ('some' , 12345 , False , 'off' , 'user' , Status .ACTIVE , 12 , split_conditions , 1.2 , 100 , 1234 , {}, None , False )
379+ rbs = rule_based_segments .from_raw (data ["rbs" ]["d" ][0 ])
380+ rbs2 = rule_based_segments .from_raw (data ["rbs" ]["d" ][1 ])
381+ await rbs_storage .update ([rbs , rbs2 ], [], 12 )
382+ await splits_storage .update ([mocked_split ], [], 12 )
383+
384+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
385+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 386+ ctx = await evaluation_facctory .
context_for (
'[email protected] ' , [
'some' ])
387+ assert e .
eval_with_context (
'[email protected] ' ,
'[email protected] ' ,
'some' , {
'email' :
'[email protected] ' },
ctx )[
'treatment' ]
== "on" 318388
319389class EvaluationDataFactoryTests (object ):
320390 """Test evaluation factory class."""
0 commit comments