<s> from django . conf import settings <EOL> from django_lean . experiments . models import Experiment <EOL> from django_lean . experiments . tests . utils import TestCase , TestUser <EOL> class TestParticipants ( TestCase ) : <EOL> def testDisabledExperiment ( self ) : <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> user = TestUser ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertTrue ( Experiment . control ( "<STR_LIT>" , user ) ) <EOL> def testUnknownExperiment ( self ) : <EOL> user = TestUser ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertTrue ( Experiment . control ( "<STR_LIT>" , user ) ) <EOL> try : <EOL> settings . DEBUG = True <EOL> self . assertRaises ( Exception , <EOL> lambda : Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertRaises ( Exception , <EOL> lambda : Experiment . control ( "<STR_LIT>" , user ) ) <EOL> finally : <EOL> settings . DEBUG = False <EOL> def testPromotedExperiment ( self ) : <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . PROMOTED_STATE <EOL> experiment . save ( ) <EOL> user = TestUser ( username = "<STR_LIT>" ) <EOL> self . assertTrue ( Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertFalse ( Experiment . control ( "<STR_LIT>" , user ) ) <EOL> def testAnonymousUser ( self ) : <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> user = TestUser ( ) <EOL> in_test = Experiment . test ( "<STR_LIT>" , user ) <EOL> anonymous_id = user . get_anonymous_id ( ) <EOL> self . assertNotEqual ( None , anonymous_id ) <EOL> in_control = Experiment . control ( "<STR_LIT>" , user ) <EOL> self . assertEqual ( user . get_anonymous_id ( ) , anonymous_id ) <EOL> self . assertNotEqual ( in_test , in_control ) <EOL> self . assertEqual ( in_test , Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertEqual ( user . get_anonymous_id ( ) , anonymous_id ) <EOL> self . assertEqual ( in_control , Experiment . control ( "<STR_LIT>" , user ) ) <EOL> self . assertEqual ( user . get_anonymous_id ( ) , anonymous_id ) <EOL> if in_test : <EOL> test_user = user <EOL> if in_control : <EOL> control_user = user <EOL> self . assertTrue ( test_user and control_user ) <EOL> user = TestUser ( ) <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> self . assertFalse ( Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertEqual ( None , user . get_anonymous_id ( ) ) <EOL> def testEnabledPromotedAndDisabledExperiment ( self ) : <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> test_user = None <EOL> control_user = None <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> user = TestUser ( username = "<STR_LIT>" % i ) <EOL> in_test = Experiment . test ( "<STR_LIT>" , user ) <EOL> in_control = Experiment . control ( "<STR_LIT>" , user ) <EOL> self . assertNotEqual ( in_test , in_control ) <EOL> self . assertEqual ( in_test , Experiment . test ( "<STR_LIT>" , user ) ) <EOL> self . assertEqual ( in_control , Experiment . control ( "<STR_LIT>" , user ) ) <EOL> if in_test : <EOL> test_user = user <EOL> if in_control : <EOL> control_user = user <EOL> self . assertNotEqual ( None , test_user ) <EOL> self . assertNotEqual ( None , control_user ) <EOL> self . assertNotEqual ( test_user , control_user ) <EOL> experiment . state = Experiment . PROMOTED_STATE <EOL> experiment . save ( ) <EOL> self . assertFalse ( Experiment . control ( "<STR_LIT>" , control_user ) ) <EOL> self . assertFalse ( Experiment . control ( "<STR_LIT>" , test_user ) ) <EOL> self . assertTrue ( Experiment . test ( "<STR_LIT>" , control_user ) ) <EOL> self . assertTrue ( Experiment . test ( "<STR_LIT>" , test_user ) ) <EOL> experiment . state = Experiment . DISABLED_STATE <EOL> experiment . save ( ) <EOL> self . assertTrue ( Experiment . control ( "<STR_LIT>" , control_user ) ) <EOL> self . assertTrue ( Experiment . control ( "<STR_LIT>" , test_user ) ) <EOL> self . assertFalse ( Experiment . test ( "<STR_LIT>" , control_user ) ) <EOL> self . assertFalse ( Experiment . test ( "<STR_LIT>" , test_user ) ) </s>
