本文整理汇总了Python中users.tests.add_permission函数的典型用法代码示例。如果您正苦于以下问题:Python add_permission函数的具体用法?Python add_permission怎么用?Python add_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_permission函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sphinx_clickthrough_post
def test_sphinx_clickthrough_post(self):
"""Test Sphinx clickthrough write API."""
u = user(save=True)
add_permission(u, Metric, 'add_metric')
click_kind, search_kind = self._make_sphinx_metric_kinds()
# POST the new object:
url = reverse('api_dispatch_list',
kwargs={'resource_name': 'sphinx-clickthrough-rate',
'api_name': 'v1'})
auth = 'Basic ' + b64encode('%s:%s' % (u.username, 'testpass'))
response = self.client.post(url,
json.dumps({'start': '2000-01-02',
'searches': 1e8,
'clicks': 5e7}),
content_type='application/json',
HTTP_AUTHORIZATION=auth)
eq_(response.status_code, 201)
# Do a GET, and see if the round trip worked:
response = self.client.get(url + '?format=json')
self.assertContains( # Beware of dict order changes someday.
response,
'"objects": [{"clicks": 50000000, "resource_uri": "", '
'"searches": 100000000, "start": "2000-01-02"}]')
示例2: setUp
def setUp(self, switch_is_active):
switch_is_active.return_value = True
super(KarmaAPITests, self).setUp()
try:
self.mgr = KarmaManager()
redis_client('karma').flushdb()
except RedisError:
raise SkipTest
self.user1 = user(save=True)
self.user2 = user(save=True)
self.user3 = user(save=True)
TestAction1(user=self.user1).save()
TestAction2(user=self.user2).save()
TestAction2(user=self.user2).save()
TestAction1(user=self.user3).save()
TestAction1(user=self.user3).save()
TestAction1(user=self.user3).save()
self.mgr.update_top()
self.client.login(username=self.user1.username, password='testpass')
add_permission(self.user1, models.Title, 'view_dashboard')
示例3: test_vote
def test_vote(self):
"""Test vote API call."""
u = user(save=True)
add_permission(u, Profile, 'view_kpi_dashboard')
r = revision(save=True)
helpful_vote(revision=r, save=True)
helpful_vote(revision=r, save=True)
helpful_vote(revision=r, helpful=True, save=True)
a = answer(save=True)
answer_vote(answer=a, save=True)
answer_vote(answer=a, helpful=True, save=True)
answer_vote(answer=a, helpful=True, save=True)
url = reverse('api_dispatch_list',
kwargs={'resource_name': 'kpi_vote',
'api_name': 'v1'})
self.client.login(username=u.username, password='testpass')
response = self.client.get(url + '?format=json')
eq_(200, response.status_code)
r = json.loads(response.content)
eq_(r['objects'][0]['kb_helpful'], 1)
eq_(r['objects'][0]['kb_votes'], 3)
eq_(r['objects'][0]['ans_helpful'], 2)
eq_(r['objects'][0]['ans_votes'], 3)
示例4: test_needs_change
def test_needs_change(self):
"""Test setting and unsetting the needs change flag"""
# Create a new document and edit it, setting needs_change.
comment = 'Please update for Firefix.next'
doc = revision(save=True).document
data = new_document_data()
data.update({'needs_change': True,
'needs_change_comment': comment,
'form': 'doc'})
# Verify that needs_change can't be set if the user doesn't have
# the permission.
self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
doc = Document.uncached.get(pk=doc.pk)
assert not doc.needs_change
assert not doc.needs_change_comment
# Give the user permission, now it should work.
add_permission(self.u, Document, 'edit_needs_change')
self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
doc = Document.uncached.get(pk=doc.pk)
assert doc.needs_change
eq_(comment, doc.needs_change_comment)
# Clear out needs_change.
data.update({'needs_change': False,
'needs_change_comment': comment})
self.client.post(reverse('wiki.edit_document', args=[doc.slug]), data)
doc = Document.uncached.get(pk=doc.pk)
assert not doc.needs_change
eq_('', doc.needs_change_comment)
示例5: setUp
def setUp(self):
super(AddRemoveLeaderTests, self).setUp()
self.locale = locale(locale='es', save=True)
self.user = user(save=True)
add_permission(self.user, Locale, 'change_locale')
self.leader = user(save=True)
self.client.login(username=self.user.username, password='testpass')
示例6: setUp
def setUp(self):
super(AddRemoveLeaderTests, self).setUp()
self.user = user(save=True)
add_permission(self.user, GroupProfile, 'change_groupprofile')
self.leader = user(save=True)
self.group_profile = group_profile(group=group(save=True), save=True)
self.client.login(username=self.user.username, password='testpass')
示例7: test_percent
def test_percent(self, switch_is_active):
"""Test user API with all defaults."""
switch_is_active.return_value = True
u = user()
u.save()
add_permission(u, Profile, 'view_kpi_dashboard')
question = Question(title='Test Question',
content='Lorem Ipsum Dolor',
creator_id=u.id)
question.save()
answer = Answer(question=question, creator_id=u.id,
content="Test Answer")
answer.save()
question.solution = answer
question.save()
url = reverse('api_dispatch_list',
kwargs={'resource_name': 'kpi_solution',
'api_name': 'v1'})
self.client.login(username=u.username, password='testpass')
response = self.client.get(url + '?format=json')
eq_(200, response.status_code)
r = json.loads(response.content)
eq_(r['objects'][0]['with_solutions'], 1)
eq_(r['objects'][0]['without_solutions'], 0)
示例8: setUp
def setUp(self):
super(AddRemoveContributorTests, self).setUp()
self.user = user(save=True)
self.contributor = user(save=True)
add_permission(self.user, Document, 'change_document')
self.client.login(username=self.user.username, password='testpass')
self.revision = revision(save=True)
self.document = self.revision.document
示例9: test_delete_image
def test_delete_image(self):
"""Deleting an uploaded image works."""
im = image()
u = user(save=True)
add_permission(u, Image, 'delete_image')
self.client.login(username=u.username, password='testpass')
r = post(self.client, 'gallery.delete_media', args=['image', im.id])
eq_(200, r.status_code)
eq_(0, Image.objects.count())
示例10: test_solution_with_perm
def test_solution_with_perm(self):
"""Test marking a solution with 'change_solution' permission."""
u = user(save=True)
add_permission(u, Question, 'change_solution')
self.client.login(username=u.username, password='testpass')
answer = self.question.answers.all()[0]
post(self.client, 'questions.solution',
args=[self.question.id, answer.id])
q = Question.uncached.get(pk=self.question.id)
eq_(q.solution, answer)
示例11: test_edit_image_with_permissions
def test_edit_image_with_permissions(self):
"""Editing image sets the updated_by field."""
img = image()
u = user(save=True)
add_permission(u, Image, 'change_image')
self.client.login(username=u.username, password='testpass')
r = post(self.client, 'gallery.edit_media', {'description': 'arrr'},
args=['image', img.id])
eq_(200, r.status_code)
eq_(u.username, Image.objects.get().updated_by.username)
示例12: test_schedule_rebuild_kb_on_delete
def test_schedule_rebuild_kb_on_delete(self, schedule_rebuild_kb):
"""KB rebuild scheduled on delete"""
im = image()
u = user(save=True)
add_permission(u, Image, 'delete_image')
self.client.login(username=u.username, password='testpass')
r = post(self.client, 'gallery.delete_media', args=['image', im.id])
eq_(200, r.status_code)
eq_(0, Image.objects.count())
assert schedule_rebuild_kb.called
示例13: setUp
def setUp(self):
super(FlaggedQueueTestCase, self).setUp()
q = question(creator=user(save=True), save=True)
self.answer = answer(question=q,
creator=user(save=True),
save=True)
self.flagger = user(save=True)
u = user(save=True)
add_permission(u, FlaggedObject, 'can_moderate')
self.client.login(username=u.username, password='testpass')
示例14: test_flag_kbforum_post
def test_flag_kbforum_post(self):
p = Post.objects.all()[0]
f = FlaggedObject(content_object=p, reason='spam', creator_id=118577)
f.save()
# Make sure flagit queue page works
u = user(save=True)
add_permission(u, FlaggedObject, 'can_moderate')
self.client.login(username=u.username, password='testpass')
response = get(self.client, 'flagit.queue')
eq_(200, response.status_code)
doc = pq(response.content)
eq_(1, len(doc('#flagged-queue li')))
示例15: test_permission_required
def test_permission_required(self):
url = reverse('flagit.queue', force_locale=True)
resp = self.client.get(url)
eq_(302, resp.status_code)
self.client.login(username=self.user.username, password='testpass')
resp = self.client.get(url)
eq_(403, resp.status_code)
add_permission(self.user, FlaggedObject, 'can_moderate')
resp = self.client.get(url)
eq_(200, resp.status_code)