本文整理汇总了Python中test_utils.RequestFactory.groups方法的典型用法代码示例。如果您正苦于以下问题:Python RequestFactory.groups方法的具体用法?Python RequestFactory.groups怎么用?Python RequestFactory.groups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test_utils.RequestFactory
的用法示例。
在下文中一共展示了RequestFactory.groups方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: req_factory_factory
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import groups [as 别名]
def req_factory_factory(url, user=None):
"""Creates a request factory, logged in with the user."""
req = RequestFactory().get(url)
if user:
req.user = user.user
req.groups = req.user.get_profile().groups.all()
return req
示例2: check_permissions
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import groups [as 别名]
def check_permissions(self):
req = RequestFactory().get(reverse('comm-thread-detail',
kwargs={'pk': self.thread.pk}))
req.user = self.user
req.amo_user = self.profile
req.groups = req.amo_user.groups.all()
return ThreadPermission().has_object_permission(
req, 'comm-thread-detail', self.thread)
示例3: req_factory_factory
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import groups [as 别名]
def req_factory_factory(url, user=None, post=False, data=None):
"""Creates a request factory, logged in with the user."""
req = RequestFactory()
if post:
req = req.post(url, data or {})
else:
req = req.get(url, data or {})
if user:
req.amo_user = user
req.user = user.user
req.groups = req.user.get_profile().groups.all()
return req
示例4: req_factory_factory
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import groups [as 别名]
def req_factory_factory(url, user=None, post=False, data=None):
"""Creates a request factory, logged in with the user."""
req = RequestFactory()
if post:
req = req.post(url, data or {})
else:
req = req.get(url, data or {})
if user:
req.amo_user = UserProfile.objects.get(id=user.id)
req.user = user
req.groups = user.groups.all()
req.check_ownership = partial(check_ownership, req)
return req
示例5: req_factory_factory
# 需要导入模块: from test_utils import RequestFactory [as 别名]
# 或者: from test_utils.RequestFactory import groups [as 别名]
def req_factory_factory(url='', user=None, post=False, data=None, **kwargs):
"""Creates a request factory, logged in with the user."""
req = RequestFactory()
if post:
req = req.post(url, data or {})
else:
req = req.get(url, data or {})
if user:
req.user = UserProfile.objects.get(id=user.id)
req.groups = user.groups.all()
else:
req.user = AnonymousUser()
req.check_ownership = partial(check_ownership, req)
req.REGION = kwargs.pop('region', mkt.regions.REGIONS_CHOICES[0][1])
req.API_VERSION = 2
for key in kwargs:
setattr(req, key, kwargs[key])
return req