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')
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'] == {}
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
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
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
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'])
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'] == {}
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'] == {}
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
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
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')
def buy(): finished('buy_text') return render_template('buy.html')
def test_can_serialize_session(self): ab_test('link_color', 'blue', 'red') finished('link_color') self.app.save_session(session, make_response())
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')
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())
def check_secondary_btn_click(): finished('secondary_btn_text') return render_template('thanks.html')