本文整理汇总了Python中pybossa.core.user_repo.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_project_report_delete_existing_report
def test_project_report_delete_existing_report(self, mock_zip_exists):
"""Test project report is generated with deleting existing report zip"""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export?type=project&format=csv' % project.short_name
res = self.app.get(url, follow_redirects=True)
示例2: newsletter_subscribe
def newsletter_subscribe():
"""
Register method for subscribing user to PyBossa newsletter.
Returns a Jinja2 template
"""
# Save that we've prompted the user to sign up in the newsletter
if newsletter.is_initialized() and current_user.is_authenticated():
next_url = request.args.get('next') or url_for('home.home')
user = user_repo.get(current_user.id)
if current_user.newsletter_prompted is False:
user.newsletter_prompted = True
user_repo.update(user)
if request.args.get('subscribe') == 'True':
newsletter.subscribe_user(user)
flash("You are subscribed to our newsletter!")
return redirect(next_url)
elif request.args.get('subscribe') == 'False':
return redirect(next_url)
else:
return render_template('account/newsletter.html',
title=gettext("Subscribe to our Newsletter"),
next=next_url)
else:
return abort(404)
示例3: test_get_inactive_users_returns_jobs
def test_get_inactive_users_returns_jobs(self):
"""Test JOB get inactive users returns a list of jobs."""
today = datetime.datetime.today()
old_date = today - datetime.timedelta(days=120)
date_str = old_date.strftime('%Y-%m-%dT%H:%M:%S.%f')
one_year = today - datetime.timedelta(days=365)
one_year_str = one_year.strftime('%Y-%m-%dT%H:%M:%S.%f')
user = UserFactory.create()
# 3 months old contribution
tr = TaskRunFactory.create(finish_time=date_str)
# 1 year old contribution
TaskRunFactory.create(finish_time=one_year_str)
# User with a contribution from a long time ago
TaskRunFactory.create(finish_time="2010-08-08T18:23:45.714110",
user=user)
# User with a recent contribution
TaskRunFactory.create(user=user)
user = user_repo.get(tr.user_id)
jobs_generator = get_inactive_users_jobs()
jobs = []
for job in jobs_generator:
jobs.append(job)
msg = "There should be one job."
print jobs
assert len(jobs) == 1, msg
job = jobs[0]
args = job['args'][0]
assert job['queue'] == 'quaterly', job['queue']
assert len(args['recipients']) == 1
assert args['recipients'][0] == user.email_addr, args['recipients'][0]
assert "UNSUBSCRIBE" in args['body']
assert "Update" in args['html']
示例4: test_webhook_handler_admin
def test_webhook_handler_admin(self):
"""Test WEBHOOK view works for admin."""
# Admin
self.register()
self.signout()
# User
self.register(name="user", password="user")
owner = user_repo.get(2)
self.signout()
# Access as admin
self.signin()
project = ProjectFactory.create(owner=owner)
url = "/project/%s/webhook" % project.short_name
res = self.app.get(url)
assert res.status_code == 200, res.status_code
assert "Created" in res.data
assert "Payload" in res.data
url = "/project/%s/webhook?all=true" % project.short_name
res = self.app.get(url)
assert res.status_code == 200, res.status_code
assert "Created" in res.data
assert "Payload" in res.data
url = "/project/%s/webhook?failed=true" % project.short_name
res = self.app.get(url)
assert res.status_code == 200, res.status_code
assert "Created" in res.data
assert "Payload" in res.data
示例5: test_webhook_handler_all
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)
示例6: test_project_report_no_zip_without_uploader
def test_project_report_no_zip_without_uploader(self, mock_no_up):
"""Test project report does not returns zip with no uploader instance """
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export?type=project&format=csv' % project.short_name
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 500, res.data
示例7: test_admin_owner_can_access_project_report_with_params
def test_admin_owner_can_access_project_report_with_params(self):
"""Test project report works when accessed with correct params"""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export?type=project&format=csv' % project.short_name
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 200, res.data
示例8: test_project_report_with_bad_format_results_415
def test_project_report_with_bad_format_results_415(self):
"""Test project report accessed with bad format returns 415"""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export?type=project&format=badfmt' % project.short_name
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 415, res.data
示例9: test_project_report_with_bad_params_results_404
def test_project_report_with_bad_params_results_404(self):
"""Test project report accessed with incorrect params returns 404"""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export?badparam=badval' % project.short_name
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 404, res.data
示例10: test_admin_owner_can_access_project_report
def test_admin_owner_can_access_project_report(self):
"""Test admin can access project report"""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = '/project/%s/projectreport/export' % project.short_name
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 200, res.data
示例11: test_stream_uri_private_auth
def test_stream_uri_private_auth(self):
"""Test stream URI private auth but not owner works."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
self.signout()
self.register(fullname='Juan', name='juan', password='juana')
private_uri = '/project/%s/privatestream' % project.short_name
res = self.app.get(private_uri, follow_redirects=True)
assert res.status_code == 403, res.data
示例12: test_webhook_handler_auth
def test_webhook_handler_auth(self):
"""Test WEBHOOK view works for authenticated not owner."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
self.signout()
res = self.register(name="juan")
url = "/project/%s/webhook" % project.short_name
res = self.app.get(url)
assert res.status_code == 403, res.status_code
示例13: test_stream_uri_private_owner_404
def test_stream_uri_private_owner_404(self):
"""Test stream URI private return 404 when SSE disabled
for owner works."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
private_uri = '/project/%s/privatestream' % project.short_name
with patch.dict(self.flask_app.config, {'SSE': False}):
res = self.app.get(private_uri, follow_redirects=True)
assert res.status_code == 404
示例14: test_stream_uri_private_owner
def test_stream_uri_private_owner(self, mock_response, mock_sse):
"""Test stream URI private owner works."""
mock_sse.return_value = self.fake_sse_response
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
private_uri = '/project/%s/privatestream' % project.short_name
self.app.get(private_uri, follow_redirects=True)
assert mock_sse.called
assert mock_sse.called_once_with(project.short_name, 'private')
示例15: test_webhook_handler_owner
def test_webhook_handler_owner(self):
"""Test WEBHOOK view works for owner."""
self.register()
user = user_repo.get(1)
project = ProjectFactory.create(owner=user)
url = "/project/%s/webhook" % project.short_name
res = self.app.get(url)
assert res.status_code == 200, res.status_code
assert "Created" in res.data
assert "Payload" in res.data