本文整理汇总了Python中django.http.request.HttpRequest.META['SERVER_PORT']方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.META['SERVER_PORT']方法的具体用法?Python HttpRequest.META['SERVER_PORT']怎么用?Python HttpRequest.META['SERVER_PORT']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.META['SERVER_PORT']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_permission_required
# 需要导入模块: from django.http.request import HttpRequest [as 别名]
# 或者: from django.http.request.HttpRequest import META['SERVER_PORT'] [as 别名]
def test_permission_required(self):
self.group = Group(name='Group A')
self.group.save()
request = HttpRequest()
setattr(request, 'user', self.user)
request.META['SERVER_NAME'] = 'beedesk.com'
request.META['SERVER_PORT'] = 80
# test a) has_perms() == False
mock = Mock(return_value='Response')
has_perms = Mock(return_value=False)
self.user.has_perms = has_perms
decorated_func = permission_required(
'auth.read_group',
fieldlookups_kwargs={'pk': 'pk'},
raise_exception=False
)(mock)
response = decorated_func(request, pk=self.group.pk)
self.assertFalse(mock.called)
self.assertTrue(response.status_code, 403)
self.assertTrue(has_perms.called)
self.assertEqual(has_perms.call_args[0][0], ('auth.read_group',))
filter = has_perms.call_args[0][1]
self.assertIsNotNone(filter)
self.assertEqual(filter.count(), 1)
self.assertEqual(filter.first().pk, self.group.pk)
# test b) has_perms() == False
mock = Mock(return_value='Response')
has_perms = Mock(return_value=True)
self.user.has_perms = has_perms
decorated_func = permission_required(
'auth.read_group',
fieldlookups_kwargs={'pk': 'pk'}
)(mock)
response = decorated_func(request, pk=self.group.pk)
self.assertTrue(mock.called)
mock.assert_called_with(request, pk=self.group.pk)
self.assertEqual(response, 'Response')
self.assertEqual(has_perms.call_args[0][0], ('auth.read_group',))
filter = has_perms.call_args[0][1]
self.assertIsNotNone(filter)
self.assertEqual(filter.count(), 1)
self.assertEqual(filter.first().pk, self.group.pk)