Browse files

pep8

  • Loading branch information...
1 parent 2830a88 commit 14ebacfe9c76b605d96d8ab86760dc171048c2b4 @jpvanhal committed Jun 3, 2012
Showing with 144 additions and 87 deletions.
  1. +2 −1 flask_split/core.py
  2. +16 −12 tests/test_dashboard.py
  3. +87 −52 tests/test_extension.py
  4. +39 −22 tests/test_models.py
View
3 flask_split/core.py
@@ -126,7 +126,8 @@ def finished(experiment_name, reset=True):
if 'split_finished' not in session:
session['split_finished'] = set()
if experiment.key not in session['split_finished']:
- alternative = Alternative(redis, alternative_name, experiment_name)
+ alternative = Alternative(
+ redis, alternative_name, experiment_name)
alternative.increment_completion()
if reset:
_get_session().pop(experiment.key, None)
View
28 tests/test_dashboard.py
@@ -24,11 +24,8 @@ def test_reset_an_experiment(self):
response = self.client.post('/split/link_color/reset')
assert_redirects(response, '/split/')
- new_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- new_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
-
- assert new_blue_count == 0
- assert new_red_count == 0
+ assert red.participant_count == 0
+ assert blue.participant_count == 0
def test_reset_a_non_existing_experiment(self):
response = self.client.post('/split/foobar/reset')
@@ -45,30 +42,37 @@ def test_delete_a_non_existing_experiment(self):
assert_redirects(response, '/split/')
def test_mark_an_alternative_as_the_winner(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
assert experiment.winner is None
- response = self.client.post('/split/link_color', data={'alternative': 'red'})
+ response = self.client.post('/split/link_color',
+ data={'alternative': 'red'})
assert_redirects(response, '/split/')
assert experiment.winner.name == 'red'
def test_mark_a_non_existing_alternative_as_the_winner(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
assert experiment.winner is None
- response = self.client.post('/split/link_color', data={'alternative': 'foobar'})
+ response = self.client.post('/split/link_color',
+ data={'alternative': 'foobar'})
assert_redirects(response, '/split/')
assert experiment.winner is None
- def test_mark_an_alternative_as_the_winner_for_non_existing_experiment(self):
- response = self.client.post('/split/foobar', data={'alternative': 'red'})
+ def test_mark_alternative_as_winner_for_non_existing_experiment(self):
+ response = self.client.post('/split/foobar',
+ data={'alternative': 'red'})
assert_redirects(response, '/split/')
def test_displays_the_start_date(self):
experiment_start_time = datetime(2011, 7, 7)
- flexmock(Experiment).should_receive('_get_time').and_return(experiment_start_time)
+ (flexmock(Experiment)
+ .should_receive('_get_time')
+ .and_return(experiment_start_time))
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
response = self.client.get('/split/')
assert '2011-07-07' in response.data
View
139 tests/test_extension.py
@@ -41,13 +41,16 @@ def test_ab_test_assigns_random_alternative_to_a_new_user(self):
def test_ab_test_increments_participation_counter_for_new_user(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
- previous_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- previous_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ red = Alternative(self.redis, 'red', 'link_color')
+ blue = Alternative(self.redis, 'blue', 'link_color')
+
+ previous_red_count = red.participant_count
+ previous_blue_count = blue.participant_count
ab_test('link_color', 'blue', 'red')
- new_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- new_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ new_red_count = red.participant_count
+ new_blue_count = blue.participant_count
assert (new_red_count + new_blue_count ==
previous_red_count + previous_blue_count + 1)
@@ -59,7 +62,8 @@ def test_ab_test_returns_the_given_alternative_for_an_existing_user(self):
assert alternative == repeat_alternative
def test_ab_test_always_returns_the_winner_if_one_is_present(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.winner = "orange"
assert ab_test('link_color', 'blue', 'red') == 'orange'
@@ -77,7 +81,7 @@ def test_ab_test_only_lets_user_participate_in_one_experiment(self):
small = Alternative(self.redis, 'small', 'button_size')
assert small.participant_count == 0
- def test_lets_user_participate_in_many_experiments_with_allow_multiple_experiments_option(self):
+ def test_can_participate_in_many_experiments_with_allow_multiple_experiments(self):
self.app.config['SPLIT_ALLOW_MULTIPLE_EXPERIMENTS'] = True
link_color = ab_test('link_color', 'blue', 'red')
button_size = ab_test('button_size', 'small', 'big')
@@ -88,12 +92,13 @@ def test_lets_user_participate_in_many_experiments_with_allow_multiple_experimen
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')
- previous_completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ alternative = Alternative(self.redis, alternative_name, 'link_color')
+ previous_completion_count = alternative.completed_count
finished('link_color')
- new_completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ new_completion_count = alternative.completed_count
assert new_completion_count == previous_completion_count + 1
- def test_finished_clears_out_the_users_participation_from_their_session(self):
+ 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')
@@ -102,7 +107,8 @@ def test_finished_clears_out_the_users_participation_from_their_session(self):
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 = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.increment_version()
alternative_name = ab_test('link_color', 'blue', 'red')
@@ -111,7 +117,7 @@ def test_finished_clears_test_session_when_version_is_greater_than_0(self):
finished('link_color')
assert session['split'] == {}
- def test_finished_does_not_clear_out_the_users_session_if_reset_is_false(self):
+ 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')
@@ -126,18 +132,20 @@ 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_finished_dont_incr_completed_twice_if_reset_is_false(self):
+ 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)
- completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ alternative = Alternative(self.redis, alternative_name, 'link_color')
+ completion_count = alternative.completed_count
assert completion_count == 1
- def test_finished_does_not_incr_completed_twice_if_version_is_greater_than_0_and_reset_is_false(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ def test_finished_dont_incr_completed_twice_if_ver_gt_0_and_no_reset(self):
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.increment_version()
alternative_name = ab_test('link_color', 'blue', 'red')
@@ -146,20 +154,20 @@ def test_finished_does_not_incr_completed_twice_if_version_is_greater_than_0_and
alternative_name = ab_test('link_color', 'blue', 'red')
finished('link_color', reset=False)
- completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ alternative = Alternative(self.redis, alternative_name, 'link_color')
+ completion_count = alternative.completed_count
assert 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')
- previous_convertion_rate = Alternative(self.redis, alternative_name, 'link_color').conversion_rate
- assert previous_convertion_rate == 0.0
+ alternative = Alternative(self.redis, alternative_name, 'link_color')
+ assert alternative.conversion_rate == 0.0
finished('link_color')
- new_convertion_rate = Alternative(self.redis, alternative_name, 'link_color').conversion_rate
- assert new_convertion_rate == 1.0
+ assert alternative.conversion_rate == 1.0
class TestExtensionWhenUserIsARobot(TestCase):
@@ -171,33 +179,38 @@ def make_test_request_context(self):
)
def test_ab_test_return_the_control(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
alternative = ab_test('link_color', 'blue', 'red')
assert alternative == experiment.control.name
def test_ab_test_does_not_increment_the_participation_count(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
- previous_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- previous_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ red = Alternative(self.redis, 'red', 'link_color')
+ blue = Alternative(self.redis, 'blue', 'link_color')
+
+ previous_red_count = red.participant_count
+ previous_blue_count = blue.participant_count
ab_test('link_color', 'blue', 'red')
- new_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- new_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ new_red_count = red.participant_count
+ new_blue_count = blue.participant_count
assert (new_red_count + new_blue_count ==
previous_red_count + previous_blue_count)
def test_finished_does_not_increment_the_completed_count(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(self.redis, alternative_name, 'link_color').completed_count
+ previous_completion_count = alternative.completed_count
finished('link_color')
- new_completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ new_completion_count = alternative.completed_count
assert new_completion_count == previous_completion_count
@@ -213,62 +226,71 @@ def make_test_request_context(self):
})
def test_ab_test_return_the_control(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
alternative = ab_test('link_color', 'blue', 'red')
assert alternative == experiment.control.name
def test_ab_test_does_not_increment_the_participation_count(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
- previous_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- previous_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ red = Alternative(self.redis, 'red', 'link_color')
+ blue = Alternative(self.redis, 'blue', 'link_color')
+
+ previous_red_count = red.participant_count
+ previous_blue_count = blue.participant_count
ab_test('link_color', 'blue', 'red')
- new_red_count = Alternative(self.redis, 'red', 'link_color').participant_count
- new_blue_count = Alternative(self.redis, 'blue', 'link_color').participant_count
+ new_red_count = red.participant_count
+ new_blue_count = blue.participant_count
assert (new_red_count + new_blue_count ==
previous_red_count + previous_blue_count)
def test_finished_does_not_increment_the_completed_count(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(self.redis, alternative_name, 'link_color').completed_count
+ previous_completion_count = alternative.completed_count
finished('link_color')
- new_completion_count = Alternative(self.redis, alternative_name, 'link_color').completed_count
+ new_completion_count = alternative.completed_count
assert new_completion_count == previous_completion_count
class TestVersionedExperiments(TestCase):
def test_uses_version_zero_if_no_version_is_present(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
alternative_name = ab_test('link_color', 'blue', 'red')
assert experiment.version == 0
assert session['split'] == {'link_color': alternative_name}
def test_saves_the_version_of_the_experiment_to_the_session(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.reset()
assert experiment.version == 1
alternative_name = ab_test('link_color', 'blue', 'red')
assert session['split'] == {'link_color:1': alternative_name}
def test_loads_the_experiment_even_if_the_version_is_not_0(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.reset()
assert experiment.version == 1
alternative_name = ab_test('link_color', 'blue', 'red')
assert session['split'] == {'link_color:1': alternative_name}
return_alternative_name = ab_test('link_color', 'blue', 'red')
assert return_alternative_name == alternative_name
- def test_resets_the_session_of_a_user_on_an_older_version_of_the_experiment(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ def test_resets_users_session_on_an_older_version_of_the_experiment(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')
@@ -281,11 +303,13 @@ def test_resets_the_session_of_a_user_on_an_older_version_of_the_experiment(self
new_alternative_name = ab_test('link_color', 'blue', 'red')
assert session['split']['link_color:1'] == new_alternative_name
- new_alternative = Alternative(self.redis, new_alternative_name, 'link_color')
+ new_alternative = Alternative(
+ self.redis, new_alternative_name, 'link_color')
assert new_alternative.participant_count == 1
def test_cleans_up_old_versions_of_experiments_from_the_session(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ 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')
@@ -300,7 +324,8 @@ def test_cleans_up_old_versions_of_experiments_from_the_session(self):
assert session['split'] == {'link_color:1': new_alternative_name}
def test_only_counts_completion_of_users_on_the_current_version(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ 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')
@@ -314,31 +339,41 @@ def test_only_counts_completion_of_users_on_the_current_version(self):
class TestExtensionWhenRedisNotAvailable(TestCase):
- def test_ab_test_raises_an_exception_when_db_failover_is_off(self):
+ def test_ab_test_raises_an_exception_without_db_failover(self):
self.app.config['SPLIT_DB_FAILOVER'] = False
- flexmock(Redis).should_receive('execute_command').and_raise(ConnectionError)
+ (flexmock(Redis)
+ .should_receive('execute_command')
+ .and_raise(ConnectionError))
with raises(ConnectionError):
ab_test('link_color', 'blue', 'red')
- def test_finished_raises_an_exception_when_db_failover_is_off(self):
+ 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)
+ (flexmock(Redis)
+ .should_receive('execute_command')
+ .and_raise(ConnectionError))
with raises(ConnectionError):
finished('link_color')
- def test_ab_test_does_not_raise_an_exception_when_db_failover_is_on(self):
+ def test_ab_test_does_not_raise_an_exception_with_db_failover(self):
self.app.config['SPLIT_DB_FAILOVER'] = True
- flexmock(Redis).should_receive('execute_command').and_raise(ConnectionError)
+ (flexmock(Redis)
+ .should_receive('execute_command')
+ .and_raise(ConnectionError))
ab_test('link_color', 'blue', 'red')
- def test_ab_test_always_uses_first_alternative_when_db_failover_is_on(self):
+ def test_ab_test_always_uses_first_alternative_with_db_failover(self):
self.app.config['SPLIT_DB_FAILOVER'] = True
- flexmock(Redis).should_receive('execute_command').and_raise(ConnectionError)
+ (flexmock(Redis)
+ .should_receive('execute_command')
+ .and_raise(ConnectionError))
assert ab_test('link_color', 'blue', 'red') == 'blue'
assert ab_test('link_color', ('blue', 0.01), ('red', 0.2)) == 'blue'
assert ab_test('link_color', ('blue', 0.8), ('red', 20)) == 'blue'
- def test_finished_does_not_raise_an_exception_when_db_failover_is_on(self):
+ def test_finished_does_not_raise_an_exception_with_db_failover(self):
self.app.config['SPLIT_DB_FAILOVER'] = True
- flexmock(Redis).should_receive('execute_command').and_raise(ConnectionError)
+ (flexmock(Redis)
+ .should_receive('execute_command')
+ .and_raise(ConnectionError))
finished('link_color')
View
61 tests/test_models.py
@@ -39,7 +39,6 @@ def test_increment_participation_count(self):
old_participant_count = alternative.participant_count
alternative.increment_participation()
assert alternative.participant_count == old_participant_count + 1
- assert Alternative(self.redis, 'Basket', 'basket_text').participant_count == old_participant_count + 1
def test_increment_completed_count(self):
experiment = Experiment(self.redis, 'basket_text', 'Basket', "Cart")
@@ -48,7 +47,6 @@ def test_increment_completed_count(self):
old_completed_count = alternative.participant_count
alternative.increment_completion()
assert alternative.completed_count == old_completed_count + 1
- assert Alternative(self.redis, 'Basket', 'basket_text').completed_count == old_completed_count + 1
def test_can_be_reset(self):
alternative = Alternative(self.redis, 'Basket', 'basket_text')
@@ -78,7 +76,8 @@ def test_conversion_rate_does_something(self):
assert alternative.conversion_rate == 0.4
def test_z_score_is_none_for_the_control(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
assert experiment.control.z_score is None
def test_z_score_is_none_when_the_control_has_no_participations(self):
@@ -88,13 +87,15 @@ def test_z_score_is_none_when_the_control_has_no_participations(self):
assert alternative.z_score is None
def test_z_score_is_none_when_alternative_has_no_participations(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.save()
alternative = Alternative(self.redis, 'red', 'link_color')
assert alternative.z_score is None
def test_z_score_when_control_and_alternative_have_perfect_conversion(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.save()
control = Alternative(self.redis, 'blue', 'link_color')
control.completed_count = 10
@@ -146,20 +147,24 @@ def test_saves_to_redis(self):
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)
+ (flexmock(Experiment)
+ .should_receive('_get_time')
+ .and_return(experiment_start_time))
experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
experiment.save()
- assert Experiment.find(self.redis, 'basket_text').start_time == experiment_start_time
+ 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)
+ (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.find(self.redis, 'basket_text').start_time is None
+ assert experiment.start_time is None
def test_does_not_create_duplicates_when_saving_multiple_times(self):
experiment = Experiment(self.redis, 'basket_text', 'Basket', 'Cart')
@@ -176,7 +181,8 @@ def test_deleting_should_delete_itself(self):
assert 'basket_text' not in self.redis
def test_deleting_should_increment_the_version(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
assert experiment.version == 0
experiment.delete()
assert experiment.version == 1
@@ -204,18 +210,22 @@ def test_control_is_the_first_alternative(self):
assert experiment.control.name == 'Basket'
def test_have_no_winner_initially(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
assert experiment.winner is None
def test_allow_you_to_specify_a_winner(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
experiment.winner = 'red'
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red')
assert experiment.winner.name == 'red'
def test_reset_should_reset_all_alternatives(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
green = Alternative(self.redis, 'green', 'link_color')
experiment.winner = 'green'
@@ -229,7 +239,8 @@ def test_reset_should_reset_all_alternatives(self):
assert reset_green.completed_count == 0
def test_reset_should_reset_the_winner(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
green = Alternative(self.redis, 'green', 'link_color')
experiment.winner = 'green'
@@ -241,29 +252,35 @@ def test_reset_should_reset_the_winner(self):
assert experiment.winner is None
def test_reset_should_increment_the_version(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
assert experiment.version == 0
experiment.reset()
assert experiment.version == 1
def test_next_alternative_always_returns_the_winner_if_one_exists(self):
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
green = Alternative(self.redis, 'green', 'link_color')
experiment.winner = 'green'
assert experiment.next_alternative().name == 'green'
green.increment_participation()
- experiment = Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red', 'green')
+ experiment = Experiment.find_or_create(
+ self.redis, 'link_color', 'blue', 'red', 'green')
assert experiment.next_alternative().name == 'green'
- def test_reset_an_experiment_if_it_is_loaded_with_different_alternatives(self):
- experiment = Experiment(self.redis, 'link_color', 'blue', 'red', 'green')
+ 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')
- assert [a.name for a in same_experiment.alternatives] == ['blue', 'yellow', 'orange']
+ 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

0 comments on commit 14ebacf

Please sign in to comment.