本文整理汇总了Python中kitsune.users.tests.UserFactory.has_perm方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.has_perm方法的具体用法?Python UserFactory.has_perm怎么用?Python UserFactory.has_perm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitsune.users.tests.UserFactory
的用法示例。
在下文中一共展示了UserFactory.has_perm方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_image_no_permission
# 需要导入模块: from kitsune.users.tests import UserFactory [as 别名]
# 或者: from kitsune.users.tests.UserFactory import has_perm [as 别名]
def test_delete_image_no_permission(self):
"""Can't delete an image without permission."""
u = UserFactory(username='tagger')
assert not u.has_perm('upload.delete_imageattachment')
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
self.client.login(username='tagger', password='testpass')
r = self._make_post_request(args=[im.id])
eq_(403, r.status_code)
assert ImageAttachment.objects.exists()
示例2: setUp
# 需要导入模块: from kitsune.users.tests import UserFactory [as 别名]
# 或者: from kitsune.users.tests.UserFactory import has_perm [as 别名]
def setUp(self):
u = UserFactory()
add_permission(u, Question, 'change_question')
assert u.has_perm('questions.change_question')
self.user = u
p = ProductFactory()
t = TopicFactory(product=p)
q = QuestionFactory(product=p, topic=t)
self.product = p
self.topic = t
self.question = q
示例3: UploadImageTestCase
# 需要导入模块: from kitsune.users.tests import UserFactory [as 别名]
# 或者: from kitsune.users.tests.UserFactory import has_perm [as 别名]
class UploadImageTestCase(TestCase):
client_class = LocalizingClient
def setUp(self):
super(UploadImageTestCase, self).setUp()
self.user = UserFactory(username='berker')
self.question = QuestionFactory()
self.client.login(username=self.user.username, password='testpass')
def tearDown(self):
ImageAttachment.objects.all().delete()
super(UploadImageTestCase, self).tearDown()
def test_model_not_whitelisted(self):
"""Specifying a model we don't allow returns 400."""
r = self._make_post_request(image='', args=['wiki.Document', 123])
eq_(400, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Model not allowed.', json_r['message'])
def test_object_notexist(self):
"""Upload nothing returns 404 error and html content."""
r = self._make_post_request(image='', args=['questions.Question', 123])
eq_(404, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Object does not exist.', json_r['message'])
def test_empty_image(self):
"""Upload nothing returns 400 error and json content."""
r = self._make_post_request(image='')
eq_(400, r.status_code)
json_r = json.loads(r.content)
eq_('error', json_r['status'])
eq_('Invalid or no image received.', json_r['message'])
eq_('You have not selected an image to upload.',
json_r['errors']['image'][0])
def test_upload_image(self):
"""Uploading an image works."""
with open('kitsune/upload/tests/media/test.jpg') as f:
r = self._make_post_request(image=f)
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
file = json_r['file']
eq_('test.png', file['name'])
eq_(90, file['width'])
eq_(120, file['height'])
name = '098f6b.png'
message = 'Url "%s" does not contain "%s"' % (file['url'], name)
assert (name in file['url']), message
eq_(1, ImageAttachment.objects.count())
image = ImageAttachment.objects.all()[0]
eq_(self.user.username, image.creator.username)
eq_(150, image.file.width)
eq_(200, image.file.height)
eq_('question', image.content_type.model)
def test_upload_unicode_image(self):
"""Uploading an unicode image works."""
with open(u'kitsune/upload/tests/media/123ascii\u6709\u52b9.jpg', 'rb') as f:
r = self._make_post_request(image=f)
eq_(200, r.status_code)
json_r = json.loads(r.content)
eq_('success', json_r['status'])
def test_delete_image_logged_out(self):
"""Can't delete an image logged out."""
# Upload the image first
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
self.client.logout()
r = self._make_post_request(args=[im.id])
eq_(403, r.status_code)
assert ImageAttachment.objects.exists()
def test_delete_image_no_permission(self):
"""Can't delete an image without permission."""
u = UserFactory(username='tagger')
assert not u.has_perm('upload.delete_imageattachment')
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
self.client.login(username='tagger', password='testpass')
r = self._make_post_request(args=[im.id])
eq_(403, r.status_code)
assert ImageAttachment.objects.exists()
def test_delete_image_owner(self):
"""Users can delete their own images."""
self.test_upload_image()
im = ImageAttachment.objects.all()[0]
r = self._make_post_request(args=[im.id])
#.........这里部分代码省略.........