Ejemplo n.º 1
0
 def test_finished_raises_an_exception_without_db_failover(self):
     self.app.config['SPLIT_DB_FAILOVER'] = False
     (flexmock(Redis)
         .should_receive('execute_command')
         .and_raise(ConnectionError))
     with raises(ConnectionError):
         finished('link_color')
Ejemplo n.º 2
0
    def test_finished_clears_out_users_participation_from_their_session(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        assert session['split'] == {"link_color": alternative_name}
        finished('link_color')
        assert session['split'] == {}
Ejemplo n.º 3
0
    def test_finished_clears_out_users_participation_from_their_session(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        assert session['split'] == {"link_color": alternative_name}
        finished('link_color')
        assert session['split'] == {}
Ejemplo n.º 4
0
 def test_finished_raises_an_exception_without_db_failover(self):
     self.app.config['SPLIT_DB_FAILOVER'] = False
     (flexmock(Redis)
         .should_receive('execute_command')
         .and_raise(ConnectionError))
     with raises(ConnectionError):
         finished('link_color')
Ejemplo n.º 5
0
 def test_finished_increments_completed_alternative_counter(self):
     Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
     alternative_name = ab_test('link_color', 'blue', 'red')
     alternative = Alternative(self.redis, alternative_name, 'link_color')
     previous_completion_count = alternative.completed_count
     finished('link_color')
     new_completion_count = alternative.completed_count
     assert new_completion_count == previous_completion_count + 1
Ejemplo n.º 6
0
 def test_finished_increments_completed_alternative_counter(self):
     Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
     alternative_name = ab_test('link_color', 'blue', 'red')
     alternative = Alternative(self.redis, alternative_name, 'link_color')
     previous_completion_count = alternative.completed_count
     finished('link_color')
     new_completion_count = alternative.completed_count
     assert new_completion_count == previous_completion_count + 1
Ejemplo n.º 7
0
    def test_conversions_return_conversion_rates_for_alternatives(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        alternative = Alternative(self.redis, alternative_name, 'link_color')
        assert alternative.conversion_rate == 0.0

        finished('link_color')

        assert alternative.conversion_rate == 1.0
Ejemplo n.º 8
0
    def test_finished_dont_incr_completed_twice_if_no_reset(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')

        alternative_name = ab_test('link_color', 'blue', 'red')
        finished('link_color', reset=False)
        finished('link_color', reset=False)

        alternative = Alternative(self.redis, alternative_name, 'link_color')
        completion_count = alternative.completed_count
        assert completion_count == 1
Ejemplo n.º 9
0
    def test_finished_dont_clear_out_the_users_session_if_reset_is_false(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        assert session['split'] == {"link_color": alternative_name}
        finished('link_color', reset=False)
        assert session['split'] == {
            "link_color": alternative_name,
        }
        assert session['split_finished'] == set(['link_color'])
Ejemplo n.º 10
0
    def test_finished_clears_test_session_when_version_is_greater_than_0(self):
        experiment = Experiment.find_or_create(self.redis, 'link_color',
                                               'blue', 'red')
        experiment.increment_version()

        alternative_name = ab_test('link_color', 'blue', 'red')
        assert session['split'] == {"link_color:1": alternative_name}

        finished('link_color')
        assert session['split'] == {}
Ejemplo n.º 11
0
    def test_finished_dont_clear_out_the_users_session_if_reset_is_false(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        assert session['split'] == {"link_color": alternative_name}
        finished('link_color', reset=False)
        assert session['split'] == {
            "link_color": alternative_name,
        }
        assert session['split_finished'] == set(['link_color'])
Ejemplo n.º 12
0
    def test_conversions_return_conversion_rates_for_alternatives(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')

        alternative = Alternative(self.redis, alternative_name, 'link_color')
        assert alternative.conversion_rate == 0.0

        finished('link_color')

        assert alternative.conversion_rate == 1.0
Ejemplo n.º 13
0
    def test_finished_dont_incr_completed_twice_if_no_reset(self):
        Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')

        alternative_name = ab_test('link_color', 'blue', 'red')
        finished('link_color', reset=False)
        finished('link_color', reset=False)

        alternative = Alternative(self.redis, alternative_name, 'link_color')
        completion_count = alternative.completed_count
        assert completion_count == 1
Ejemplo n.º 14
0
    def test_finished_clears_test_session_when_version_is_greater_than_0(self):
        experiment = Experiment.find_or_create(
            self.redis, 'link_color', 'blue', 'red')
        experiment.increment_version()

        alternative_name = ab_test('link_color', 'blue', 'red')
        assert session['split'] == {"link_color:1": alternative_name}

        finished('link_color')
        assert session['split'] == {}
Ejemplo n.º 15
0
    def test_only_counts_completion_of_users_on_the_current_version(self):
        experiment = Experiment.find_or_create(
            self.redis, 'link_color', 'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')
        assert session['split'] == {'link_color': alternative_name}
        alternative = Alternative(self.redis, alternative_name, 'link_color')

        experiment.reset()
        assert experiment.version == 1

        finished('link_color')
        alternative = Alternative(self.redis, alternative_name, 'link_color')
        assert alternative.completed_count == 0
Ejemplo n.º 16
0
    def test_only_counts_completion_of_users_on_the_current_version(self):
        experiment = Experiment.find_or_create(self.redis, 'link_color',
                                               'blue', 'red')
        alternative_name = ab_test('link_color', 'blue', 'red')
        assert session['split'] == {'link_color': alternative_name}
        alternative = Alternative(self.redis, alternative_name, 'link_color')

        experiment.reset()
        assert experiment.version == 1

        finished('link_color')
        alternative = Alternative(self.redis, alternative_name, 'link_color')
        assert alternative.completed_count == 0
Ejemplo n.º 17
0
 def test_finished_does_nothing_if_experiment_was_not_started_by_the_user(
         self):
     session['split'] = None
     finished('some_experiment_not_started_by_the_user')
Ejemplo n.º 18
0
def buy():
    finished('buy_text')
    return render_template('buy.html')
Ejemplo n.º 19
0
 def test_can_serialize_session(self):
     ab_test('link_color', 'blue', 'red')
     finished('link_color')
     self.app.save_session(session, make_response())
Ejemplo n.º 20
0
 def test_finished_does_nothing_if_experiment_was_not_started_by_the_user(self):
     session['split'] = None
     finished('some_experiment_not_started_by_the_user')
Ejemplo n.º 21
0
 def test_can_serialize_session(self):
     ab_test('link_color', 'blue', 'red')
     finished('link_color')
     self.app.session_interface.save_session(self.app, session, make_response())
Ejemplo n.º 22
0
def check_secondary_btn_click():
    finished('secondary_btn_text')
    return render_template('thanks.html')