本文整理汇总了Python中factories.AnonymousTaskRunFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python AnonymousTaskRunFactory.create方法的具体用法?Python AnonymousTaskRunFactory.create怎么用?Python AnonymousTaskRunFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类factories.AnonymousTaskRunFactory
的用法示例。
在下文中一共展示了AnonymousTaskRunFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_webhook_handler_all
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_webhook_handler_all(self, q):
"""Test WEBHOOK requeing all works."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user, webhook='server')
task = TaskFactory.create(project=project, n_answers=1)
AnonymousTaskRunFactory.create(project=project, task=task)
payload = self.payload(project, task)
wh1 = Webhook(project_id=project.id, payload=payload,
response='error', response_status_code=500)
webhook_repo.save(wh1)
wh2 = Webhook(project_id=project.id, payload=payload,
response='ok', response_status_code=200)
webhook_repo.save(wh2)
wh3 = Webhook(project_id=project.id, payload=payload,
response='ok', response_status_code=200)
webhook_repo.save(wh3)
whs = webhook_repo.filter_by(project_id=project.id)
url = "/project/%s/webhook?all=true" % (project.short_name)
res = self.app.get(url)
assert res.status_code == 200, res.status_code
calls = []
for w in whs:
calls.append(call(webhook, project.webhook,
w.payload, w.id, True))
q.assert_has_calls(calls)
示例2: test_n_total_task_runs_site_returns_total_number_of_answers
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_n_total_task_runs_site_returns_total_number_of_answers(self):
AnonymousTaskRunFactory.create()
TaskRunFactory.create()
task_runs = stats.n_task_runs_site()
assert task_runs == 2, task_runs
示例3: test_stats_users
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_stats_users(self):
"""Test CACHE PROJECT STATS user stats works."""
pr = ProjectFactory.create()
TaskRunFactory.create(project=pr)
AnonymousTaskRunFactory.create(project=pr)
users, anon_users, auth_users = stats_users(pr.id)
assert len(users) == 2, len(users)
assert len(anon_users) == 1, len(anon_users)
assert len(auth_users) == 1, len(auth_users)
示例4: create_mock_ip_addresses
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def create_mock_ip_addresses(self, geoip_mock):
geoip_instance = MagicMock()
locs = [{'latitude': 1, 'longitude': 1, 'country_name': 'England',
'city': 'London', 'continent': 'Europe'},
{'latitude': 2, 'longitude': 2, 'country_name': 'France',
'city': 'Paris', 'continent': 'Europe'}]
geoip_instance.record_by_addr.side_effect = locs
geoip_mock.return_value = geoip_instance
AnonymousTaskRunFactory.create(info={'ip_address': '1.1.1.1'})
TaskRunFactory.create(info={'ip_address': '2.2.2.2'})
示例5: test_stats_users_with_period
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_stats_users_with_period(self):
"""Test CACHE PROJECT STATS user stats with period works."""
pr = ProjectFactory.create()
d = date.today() - timedelta(days=6)
TaskRunFactory.create(project=pr, created=d, finish_time=d)
d = date.today() - timedelta(days=16)
AnonymousTaskRunFactory.create(project=pr, created=d, finish_time=d)
users, anon_users, auth_users = stats_users(pr.id, '1 week')
assert len(users) == 2, len(users)
assert len(anon_users) == 0, len(anon_users)
assert len(auth_users) == 1, len(auth_users)
示例6: test_webhook_handler_post_oid_404
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_webhook_handler_post_oid_404(self):
"""Test WEBHOOK post oid 404 works."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
task = TaskFactory.create(project=project, n_answers=1)
AnonymousTaskRunFactory.create(project=project, task=task)
payload = self.payload(project, task)
webhook = Webhook(project_id=project.id, payload=payload,
response='OK', response_status_code=200)
webhook_repo.save(webhook)
url = "/project/%s/webhook/%s" % (project.short_name, 9999)
res = self.app.post(url)
assert res.status_code == 404, res.status_code
示例7: test_stats_dates
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_stats_dates(self):
"""Test CACHE PROJECT STATS date works."""
pr = ProjectFactory.create()
task = TaskFactory.create(project=pr, n_answers=1)
today = datetime.now(pytz.utc)
TaskFactory.create()
TaskRunFactory.create(project=pr, task=task)
AnonymousTaskRunFactory.create(project=pr)
dates, dates_anon, dates_auth = stats_dates(pr.id)
assert len(dates) == 15, len(dates)
assert len(dates_anon) == 15, len(dates_anon)
assert len(dates_auth) == 15, len(dates_auth)
assert dates[today.strftime('%Y-%m-%d')] == 1
assert dates_anon[today.strftime('%Y-%m-%d')] == 1
assert dates_auth[today.strftime('%Y-%m-%d')] == 1
示例8: test_stats_dates_with_period
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_stats_dates_with_period(self):
"""Test CACHE PROJECT STATS dates with period works."""
pr = ProjectFactory.create()
d = date.today() - timedelta(days=6)
task = TaskFactory.create(project=pr, n_answers=1, created=d)
TaskRunFactory.create(project=pr, task=task, created=d, finish_time=d)
dd = date.today() - timedelta(days=16)
AnonymousTaskRunFactory.create(project=pr, created=dd, finish_time=dd)
dates, dates_anon, dates_auth = stats_dates(pr.id, '1 week')
assert len(dates) == 7, len(dates)
assert len(dates_anon) == 7, len(dates_anon)
assert len(dates_auth) == 7, len(dates_auth)
assert dates[d.strftime('%Y-%m-%d')] == 1
assert dates_anon[d.strftime('%Y-%m-%d')] == 0
assert dates_auth[d.strftime('%Y-%m-%d')] == 1
示例9: test_authenticated_user_delete_anonymous_taskrun
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_authenticated_user_delete_anonymous_taskrun(self):
"""Test authenticated users cannot delete an anonymously posted taskrun"""
anonymous_taskrun = AnonymousTaskRunFactory.create()
assert_raises(Forbidden,
ensure_authorized_to, 'delete', anonymous_taskrun)
示例10: test_admin_update_anonymous_taskrun
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_admin_update_anonymous_taskrun(self):
"""Test admins cannot update anonymously posted taskruns"""
anonymous_taskrun = AnonymousTaskRunFactory.create()
assert_raises(Forbidden,
ensure_authorized_to, 'update', anonymous_taskrun)
示例11: test_anonymous_user_update_anoymous_taskrun
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_anonymous_user_update_anoymous_taskrun(self):
"""Test anonymous users cannot update an anonymously posted taskrun"""
anonymous_taskrun = AnonymousTaskRunFactory.create()
assert_raises(Unauthorized,
ensure_authorized_to, 'update', anonymous_taskrun)
示例12: test_user_progress_anonymous
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_user_progress_anonymous(self):
"""Test API userprogress as anonymous works"""
user = UserFactory.create()
app = AppFactory.create(owner=user)
tasks = TaskFactory.create_batch(2, app=app)
for task in tasks:
taskruns = AnonymousTaskRunFactory.create_batch(2, task=task)
taskruns = db.session.query(TaskRun)\
.filter(TaskRun.app_id == app.id)\
.filter(TaskRun.user_ip == '127.0.0.1')\
.all()
res = self.app.get('/api/app/1/userprogress', follow_redirects=True)
data = json.loads(res.data)
error_msg = "The reported total number of tasks is wrong"
assert len(tasks) == data['total'], error_msg
error_msg = "The reported number of done tasks is wrong"
assert len(taskruns) == data['done'], data
# Add a new TaskRun and check again
taskrun = AnonymousTaskRunFactory.create(task=tasks[0], info={'answer': u'hello'})
res = self.app.get('/api/app/1/userprogress', follow_redirects=True)
data = json.loads(res.data)
error_msg = "The reported total number of tasks is wrong"
assert len(tasks) == data['total'], error_msg
error_msg = "Number of done tasks is wrong: %s" % len(taskruns)
assert len(taskruns) + 1 == data['done'], error_msg
示例13: test_user_progress_anonymous
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_user_progress_anonymous(self):
"""Test API userprogress as anonymous works"""
user = UserFactory.create()
project = ProjectFactory.create(owner=user)
tasks = TaskFactory.create_batch(2, project=project)
taskruns = []
for task in tasks:
taskruns.extend(AnonymousTaskRunFactory.create_batch(2, task=task))
res = self.app.get('/api/project/1/userprogress', follow_redirects=True)
data = json.loads(res.data)
error_msg = "The reported total number of tasks is wrong"
assert len(tasks) == data['total'], error_msg
error_msg = "The reported number of done tasks is wrong"
assert len(taskruns) == data['done'], data
# Add a new TaskRun and check again
taskrun = AnonymousTaskRunFactory.create(task=tasks[0], info={'answer': u'hello'})
res = self.app.get('/api/project/1/userprogress', follow_redirects=True)
data = json.loads(res.data)
error_msg = "The reported total number of tasks is wrong"
assert len(tasks) == data['total'], error_msg
error_msg = "Number of done tasks is wrong: %s" % len(taskruns)
assert len(taskruns) + 1 == data['done'], error_msg
示例14: test_anonymous_user_create_repeated_taskrun
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_anonymous_user_create_repeated_taskrun(self):
"""Test anonymous user cannot create two taskruns for the same task"""
task = TaskFactory.create()
taskrun1 = AnonymousTaskRunFactory.create(task=task)
taskrun2 = AnonymousTaskRunFactory.build(task=task)
assert_raises(Forbidden, ensure_authorized_to, 'create', taskrun2)
示例15: test_admin_delete_anonymous_taskrun
# 需要导入模块: from factories import AnonymousTaskRunFactory [as 别名]
# 或者: from factories.AnonymousTaskRunFactory import create [as 别名]
def test_admin_delete_anonymous_taskrun(self):
"""Test admins can delete anonymously posted taskruns"""
anonymous_taskrun = AnonymousTaskRunFactory.create()
assert_not_raises(Exception,
ensure_authorized_to, 'delete', anonymous_taskrun)