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


Python HttpRequest.GET['username']方法代码示例

本文整理汇总了Python中django.http.HttpRequest.GET['username']方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.GET['username']方法的具体用法?Python HttpRequest.GET['username']怎么用?Python HttpRequest.GET['username']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.GET['username']方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_is_authenticated

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
 def test_is_authenticated(self):
     auth = ApiKeyAuthentication()
     request = HttpRequest()
     
     # No username/api_key details should fail.
     self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)
     
     # Wrong username details.
     request.GET['username'] = 'foo'
     self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)
     
     # No api_key.
     request.GET['username'] = 'daniel'
     self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)
     
     # Wrong user/api_key.
     request.GET['username'] = 'daniel'
     request.GET['api_key'] = 'foo'
     self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)
     
     # Correct user/api_key.
     john_doe = User.objects.get(username='johndoe')
     john_doe.save()
     request.GET['username'] = 'johndoe'
     request.GET['api_key'] = john_doe.api_key.key
     self.assertEqual(auth.is_authenticated(request), True)
开发者ID:Concert,项目名称:django-tastypie,代码行数:28,代码来源:authentication.py

示例2: test_is_authenticated_get_params

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_is_authenticated_get_params(self):
        auth = ApiKeyAuthentication()
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = User.objects.get(username='johndoe')
        create_api_key(User, instance=john_doe, created=True)

        # No username/api_key details should fail.
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Wrong username details.
        request.GET['username'] = 'foo'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # No api_key.
        request.GET['username'] = 'daniel'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Wrong user/api_key.
        request.GET['username'] = 'daniel'
        request.GET['api_key'] = 'foo'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Correct user/api_key.
        john_doe = User.objects.get(username='johndoe')
        request.GET['username'] = 'johndoe'
        request.GET['api_key'] = john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), 'johndoe')
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:32,代码来源:authentication.py

示例3: test_is_authenticated_get_params

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_is_authenticated_get_params(self):
        auth = ApiKeyAuthentication()
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = CustomUser.objects.get(pk=1)
        create_api_key(CustomUser, instance=john_doe, created=True)

        # No username/api_key details should fail.
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Wrong username (email) details.
        request.GET['username'] = '[email protected]'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # No api_key.
        request.GET['username'] = john_doe.email
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Wrong user/api_key.
        request.GET['username'] = john_doe.email
        request.GET['api_key'] = 'foo'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Correct user/api_key.
        ApiKey.objects.all().delete()
        create_api_key(CustomUser, instance=john_doe, created=True)
        request.GET['username'] = john_doe.email
        request.GET['api_key'] = john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), john_doe.email)
开发者ID:mjschultz,项目名称:django-tastefulpy,代码行数:33,代码来源:custom_user.py

示例4: test_apikey_and_basic_auth

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_apikey_and_basic_auth(self):
        auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
        request = HttpRequest()
        john_doe = User.objects.get(username='johndoe')

        # No API Key or HTTP Basic auth details should fail.
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Basic Auth still returns appropriately.
        self.assertEqual(auth.is_authenticated(request)['WWW-Authenticate'], 'Basic Realm="django-tastypie"')

        # API Key Auth works.
        request = HttpRequest()
        request.GET['username'] = 'johndoe'
        request.GET['api_key'] = john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), 'johndoe')


        # Basic Auth works.
        request = HttpRequest()
        john_doe = User.objects.get(username='johndoe')
        john_doe.set_password('pass')
        john_doe.save()
        request.META['HTTP_AUTHORIZATION'] = 'Basic %s' % base64.b64encode('johndoe:pass'.encode('utf-8')).decode('utf-8')
        self.assertEqual(auth.is_authenticated(request), True)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:28,代码来源:authentication.py

示例5: test_authentication

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_authentication(self):
        request = HttpRequest()
        auth = ApiKeyOrGuestAuthentication()
        self.assertTrue(auth.is_authenticated(request))

        request.GET['username'] = self.staff_user.email
        request.GET['api_key'] = self.staff_user.api_key.key
        self.assertTrue(auth.is_authenticated(request))
开发者ID:Alex201310,项目名称:pythondotorg,代码行数:10,代码来源:test_resources.py

示例6: test_multiauth_apikey_and_basic_auth__api_key_works_in_query

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_multiauth_apikey_and_basic_auth__api_key_works_in_query(self):
        auth = MultiAuthentication(BasicAuthentication(), ApiKeyAuthentication())
        request = HttpRequest()
        john_doe = User.objects.get(username='johndoe')

        request.GET['username'] = john_doe.username
        request.GET['api_key'] = john_doe.api_key.key

        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), john_doe.username)
开发者ID:Adusei,项目名称:django-tastypie,代码行数:12,代码来源:authentication.py

示例7: test_apikey_and_authentication

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_apikey_and_authentication(self):
        auth = MultiAuthentication(ApiKeyAuthentication(), Authentication())
        request = HttpRequest()

        john_doe = User.objects.get(username='johndoe')

        # No username/api_key details should pass.
        self.assertEqual(auth.is_authenticated(request), True)

        # The identifier should be the basic auth stock.
        self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')

        # Wrong username details.
        request = HttpRequest()
        request.GET['username'] = 'foo'

        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')

        # No api_key.
        request = HttpRequest()
        request.GET['username'] = 'daniel'

        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')

        # Wrong user/api_key.
        request = HttpRequest()
        request.GET['username'] = 'daniel'
        request.GET['api_key'] = 'foo'

        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), 'noaddr_nohost')

        request = HttpRequest()
        request.GET['username'] = 'johndoe'
        request.GET['api_key'] = john_doe.api_key.key

        self.assertEqual(auth.is_authenticated(request), True)
        self.assertEqual(auth.get_identifier(request), john_doe.username)
开发者ID:Adusei,项目名称:django-tastypie,代码行数:42,代码来源:authentication.py

示例8: test_is_authenticated_get_params

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_is_authenticated_get_params(self):
        auth = ApiKeyAuthentication()
        request = HttpRequest()

        # No username/api_key details should fail.
        self.assertFalse(auth.is_authenticated(request))

        # Wrong username details.
        request.GET['username'] = 'foo'
        self.assertFalse(auth.is_authenticated(request))

        # No api_key.
        request.GET['username'] = self.user.username
        self.assertFalse(auth.is_authenticated(request))

        # Wrong user/api_key.
        request.GET['username'] = self.user.username
        request.GET['api_key'] = 'foo'
        self.assertFalse(auth.is_authenticated(request))

        # Correct user/api_key.
        request.GET['username'] = self.user.username
        request.GET['api_key'] = self.user.api_key.key
        self.assertTrue(auth.is_authenticated(request))
开发者ID:pombredanne,项目名称:django-restify,代码行数:26,代码来源:test_authentication.py

示例9: test_api_token

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_api_token(self):
        auth = APITokenAuthentication()
        request = HttpRequest()
        request.META = {}
        request.GET = {}
        self.assertTrue(not auth.is_authenticated(request))
        request.POST = {}
        self.assertTrue(not auth.is_authenticated(request))

        api_token = APIToken.get_user_token(self.user)
        request.GET['token'] = api_token
        request.GET['username'] = self.user.username
        self.assertTrue(auth.is_authenticated(request))

        request.GET = {}
        request.POST['token'] = api_token
        request.POST['username'] = self.user.username
        self.assertTrue(auth.is_authenticated(request))
开发者ID:ftao,项目名称:kns,代码行数:20,代码来源:tests.py

示例10: test_whitelisting

# 需要导入模块: from django.http import HttpRequest [as 别名]
# 或者: from django.http.HttpRequest import GET['username'] [as 别名]
    def test_whitelisting(self):
        auth = ApiKeyAuthentication(whitelisted_methods=['a_method'])
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = User.objects.get(username='johndoe')
        create_api_key(User, instance=john_doe, created=True)

        # Calling with a whitelisted method_name without credentials should work
        self.assertEqual(auth.is_authenticated(request, method_name='a_method'), True)
        
        # Calling any other method should require the Api Key
        self.assertEqual(isinstance(auth.is_authenticated(request, method_name='another_method'), HttpUnauthorized), True)

        # Correct user/api_key
        john_doe = User.objects.get(username='johndoe')
        request.GET['username'] = 'johndoe'
        request.GET['api_key'] = john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request, method_name="another_method"), True)
        self.assertEqual(auth.get_identifier(request), 'johndoe')
        self.assertEqual(auth.is_authenticated(request, method_name="a_method"), True)
        self.assertEqual(auth.get_identifier(request), 'johndoe')
开发者ID:YACFirm,项目名称:django-tastypie,代码行数:24,代码来源:authentication.py


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