本文整理汇总了Python中unittest.mock.Mock.has_listed_versions方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.has_listed_versions方法的具体用法?Python Mock.has_listed_versions怎么用?Python Mock.has_listed_versions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.has_listed_versions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_listed_version_reviewer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_no_listed_version_reviewer(self):
user = user_factory()
self.grant_permission(user, 'Addons:Review')
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: False
for method in self.safe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
# It doesn't work with the object though, since
# has_listed_versions() is returning False, we don't have enough
# permissions, being a "simple" reviewer.
assert not self.permission.has_object_permission(
request, myview, obj)
for method in self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
# As above it doesn't work with the object though.
assert not self.permission.has_object_permission(
request, myview, obj)
示例2: test_authenticated_but_not_reviewer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_authenticated_but_not_reviewer(self):
request = self.request_factory.get('/')
request.user = user_factory()
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
assert self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)
示例3: test_object_with_no_unlisted_versions_and_no_listed_versions
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_object_with_no_unlisted_versions_and_no_listed_versions(self):
self.request.user = user_factory()
self.grant_permission(self.request.user, 'Addons:ReviewUnlisted')
obj = Mock(spec=[])
obj.has_unlisted_versions = lambda: False
obj.has_listed_versions = lambda: False
assert self.permission.has_permission(self.request, myview)
assert self.permission.has_object_permission(
self.request, myview, obj)
示例4: test_user_cannot_be_anonymous
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_user_cannot_be_anonymous(self):
request = self.request_factory.get('/')
request.user = AnonymousUser()
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
assert not self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)
示例5: test_admin
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_admin(self):
user = user_factory()
self.grant_permission(user, '*:*')
for method in self.safe_methods + self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
assert self.permission.has_permission(request, myview)
assert self.permission.has_object_permission(
request, myview, obj)
示例6: test_reviewer_tools_access_read_only
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_reviewer_tools_access_read_only(self):
user = user_factory()
self.grant_permission(user, 'ReviewerTools:View')
obj = Mock(spec=[])
obj.type = amo.ADDON_EXTENSION
obj.has_listed_versions = lambda: True
for method in self.safe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
assert self.permission.has_permission(request, myview)
assert self.permission.has_object_permission(
request, myview, obj)
for method in self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)
示例7: test_theme_reviewer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import has_listed_versions [as 别名]
def test_theme_reviewer(self):
user = user_factory()
self.grant_permission(user, 'Addons:ThemeReview')
obj = Mock(spec=[])
obj.type = amo.ADDON_STATICTHEME
obj.has_listed_versions = lambda: True
for method in self.safe_methods + self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
assert self.permission.has_permission(request, myview)
assert self.permission.has_object_permission(
request, myview, obj)
# Does not have access to other extensions.
obj.type = amo.ADDON_EXTENSION
for method in self.safe_methods + self.unsafe_methods:
request = getattr(self.request_factory, method)('/')
request.user = user
# When not checking the object, we have permission because we're
# authenticated.
assert self.permission.has_permission(request, myview)
assert not self.permission.has_object_permission(
request, myview, obj)