def test_know_if_it_is_the_control_of_an_experiment(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() alternative = Alternative(self.redis, 'Basket', 'basket_text') assert alternative.is_control alternative = Alternative(self.redis, 'Cart', 'basket_text') assert not alternative.is_control
def test_increment_completed_count(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', "Cart") experiment.save() alternative = Alternative(self.redis, 'Basket', 'basket_text') old_completed_count = alternative.participant_count alternative.increment_completion() assert alternative.completed_count == old_completed_count + 1
def test_saves_the_start_time_to_redis(self): experiment_start_time = datetime(2012, 3, 9, 22, 01, 34) (flexmock(Experiment).should_receive('_get_time').and_return( experiment_start_time)) experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert experiment.start_time == experiment_start_time
def test_saves_the_start_time_to_redis(self): experiment_start_time = datetime(2012, 3, 9, 22, 01, 34) (flexmock(Experiment) .should_receive('_get_time') .and_return(experiment_start_time)) experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert experiment.start_time == experiment_start_time
def test_handles_not_having_a_start_time(self): experiment_start_time = datetime(2012, 3, 9, 22, 01, 34) (flexmock(Experiment).should_receive('_get_time').and_return( experiment_start_time)) experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() self.redis.hdel('experiment_start_times', experiment.name) assert experiment.start_time is None
def test_handles_not_having_a_start_time(self): experiment_start_time = datetime(2012, 3, 9, 22, 01, 34) (flexmock(Experiment) .should_receive('_get_time') .and_return(experiment_start_time)) experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() self.redis.hdel('experiment_start_times', experiment.name) assert experiment.start_time is None
def test_reset_an_experiment_if_loaded_with_different_alternatives(self): experiment = Experiment(self.redis, 'link_color', 'blue', 'red', 'green') experiment.save() blue = Alternative(self.redis, 'blue', 'link_color') blue.participant_count = 5 blue.save() same_experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'yellow', 'orange') alternative_names = [a.name for a in same_experiment.alternatives] assert alternative_names == ['blue', 'yellow', 'orange'] new_blue = Alternative(self.redis, 'blue', 'link_color') assert new_blue.participant_count == 0
def test_reset_an_experiment_if_loaded_with_different_alternatives(self): experiment = Experiment( self.redis, 'link_color', 'blue', 'red', 'green') experiment.save() blue = Alternative(self.redis, 'blue', 'link_color') blue.participant_count = 5 blue.save() same_experiment = Experiment.find_or_create( self.redis, 'link_color', 'blue', 'yellow', 'orange') alternative_names = [a.name for a in same_experiment.alternatives] assert alternative_names == ['blue', 'yellow', 'orange'] new_blue = Alternative(self.redis, 'blue', 'link_color') assert new_blue.participant_count == 0
def test_belong_to_an_experiment(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() alternative = Alternative(self.redis, 'Basket', 'basket_text') assert alternative.experiment.name == experiment.name
def test_control_is_the_first_alternative(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert experiment.control.name == 'Basket'
def test_find_returns_an_existing_experiment(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert Experiment.find(self.redis, 'basket_text').name == 'basket_text'
def test_is_new_record_knows_if_it_has_been_saved_yet(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert not experiment.is_new_record
def test_deleting_should_delete_itself(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() experiment.delete() assert 'basket_text' not in self.redis
def test_does_not_create_duplicates_when_saving_multiple_times(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() experiment.save() assert 'basket_text' in self.redis assert self.redis.lrange('basket_text', 0, -1) == ['Basket', 'Cart']
def test_z_score_is_none_when_the_control_has_no_participations(self): experiment = Experiment(self.redis, 'link_color', 'blue', 'red') experiment.save() alternative = Alternative(self.redis, 'red', 'link_color') assert alternative.z_score is None
def test_saves_to_redis(self): experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart') experiment.save() assert 'basket_text' in self.redis