本文整理汇总了Python中flask_split.models.Experiment.find_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.find_or_create方法的具体用法?Python Experiment.find_or_create怎么用?Python Experiment.find_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_split.models.Experiment
的用法示例。
在下文中一共展示了Experiment.find_or_create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finished_clears_out_users_participation_from_their_session
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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'] == {}
示例2: test_displays_the_start_date
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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))
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
response = self.client.get('/split/')
assert '2011-07-07' in response.data
示例3: test_allow_you_to_specify_a_winner
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_allow_you_to_specify_a_winner(self):
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')
assert experiment.winner.name == 'red'
示例4: test_finished_increments_completed_alternative_counter
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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
示例5: test_conversions_return_conversion_rates_for_alternatives
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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
示例6: test_finished_dont_incr_completed_twice_if_no_reset
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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
示例7: test_finished_dont_clear_out_the_users_session_if_reset_is_false
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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'])
示例8: test_next_alternative_always_returns_the_winner_if_one_exists
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_next_alternative_always_returns_the_winner_if_one_exists(self):
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')
assert experiment.next_alternative().name == 'green'
示例9: test_reset_an_experiment
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_reset_an_experiment(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
red = Alternative(self.redis, 'red', 'link_color')
blue = Alternative(self.redis, 'blue', 'link_color')
red.participant_count = 5
blue.participant_count = 6
response = self.client.post('/split/link_color/reset')
assert_redirects(response, '/split/')
assert red.participant_count == 0
assert blue.participant_count == 0
示例10: test_ab_test_increments_participation_counter_for_new_user
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_ab_test_increments_participation_counter_for_new_user(self):
Experiment.find_or_create(self.redis, 'link_color', 'blue', 'red')
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 = red.participant_count
new_blue_count = blue.participant_count
assert (new_red_count + new_blue_count ==
previous_red_count + previous_blue_count + 1)
示例11: test_saves_the_version_of_the_experiment_to_the_session
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_saves_the_version_of_the_experiment_to_the_session(self):
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}
示例12: test_loads_the_experiment_even_if_the_version_is_not_0
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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.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
示例13: test_mark_a_non_existing_alternative_as_the_winner
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_mark_a_non_existing_alternative_as_the_winner(self):
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'})
assert_redirects(response, '/split/')
assert experiment.winner is None
示例14: test_finished_clears_test_session_when_version_is_greater_than_0
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
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'] == {}
示例15: test_z_score_when_control_and_alternative_have_perfect_conversion
# 需要导入模块: from flask_split.models import Experiment [as 别名]
# 或者: from flask_split.models.Experiment import find_or_create [as 别名]
def test_z_score_when_control_and_alternative_have_perfect_conversion(self):
experiment = Experiment.find_or_create(
self.redis, 'link_color', 'blue', 'red')
experiment.save()
control = Alternative(self.redis, 'blue', 'link_color')
control.completed_count = 10
control.participant_count = 10
alternative = Alternative(self.redis, 'red', 'link_color')
alternative.completed_count = 8
alternative.participant_count = 8
assert alternative.z_score is None