当前位置: 首页>>代码示例>>Python>>正文


Python HttpRequest.META['SERVER_PORT']方法代码示例

本文整理汇总了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)
开发者ID:charleslee98006,项目名称:django-trusts,代码行数:51,代码来源:tests.py


注:本文中的django.http.request.HttpRequest.META['SERVER_PORT']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。