<s> from django . test import TestCase <EOL> from django . contrib . auth import get_user_model <EOL> from experiments . models import Experiment , ENABLED_STATE <EOL> from experiments . signals import user_enrolled <EOL> from experiments . utils import participant <EOL> EXPERIMENT_NAME = '<STR_LIT>' <EOL> class WatchSignal ( object ) : <EOL> def __init__ ( self , signal ) : <EOL> self . signal = signal <EOL> self . called = False <EOL> def __enter__ ( self ) : <EOL> self . signal . connect ( self . signal_handler ) <EOL> return self <EOL> def __exit__ ( self , * args ) : <EOL> self . signal . disconnect ( self . signal_handler ) <EOL> def signal_handler ( self , * args , ** kwargs ) : <EOL> self . called = True <EOL> class SignalsTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . experiment = Experiment . objects . create ( name = EXPERIMENT_NAME , state = ENABLED_STATE ) <EOL> User = get_user_model ( ) <EOL> self . user = User . objects . create ( username = '<STR_LIT>' ) <EOL> def test_sends_enroll_signal ( self ) : <EOL> with WatchSignal ( user_enrolled ) as signal : <EOL> participant ( user = self . user ) . enroll ( EXPERIMENT_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( signal . called ) <EOL> def test_does_not_send_enroll_signal_again ( self ) : <EOL> participant ( user = self . user ) . enroll ( EXPERIMENT_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with WatchSignal ( user_enrolled ) as signal : <EOL> participant ( user = self . user ) . enroll ( EXPERIMENT_NAME , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertFalse ( signal . called ) </s>
