Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
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
Ejemplo n.º 12
0
 def test_control_is_the_first_alternative(self):
     experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
     experiment.save()
     assert experiment.control.name == 'Basket'
Ejemplo n.º 13
0
 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'
Ejemplo n.º 14
0
 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
Ejemplo n.º 15
0
    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
Ejemplo n.º 16
0
 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']
Ejemplo n.º 17
0
    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
Ejemplo n.º 18
0
 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
Ejemplo n.º 19
0
 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'
Ejemplo n.º 20
0
 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']
Ejemplo n.º 21
0
 def test_control_is_the_first_alternative(self):
     experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
     experiment.save()
     assert experiment.control.name == 'Basket'
Ejemplo n.º 22
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
Ejemplo n.º 23
0
 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
Ejemplo n.º 24
0
 def test_saves_to_redis(self):
     experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
     experiment.save()
     assert 'basket_text' in self.redis
Ejemplo n.º 25
0
 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
Ejemplo n.º 26
0
 def test_saves_to_redis(self):
     experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
     experiment.save()
     assert 'basket_text' in self.redis