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


Python models.create_api_key函数代码示例

本文整理汇总了Python中tastypie.models.create_api_key函数的典型用法代码示例。如果您正苦于以下问题:Python create_api_key函数的具体用法?Python create_api_key怎么用?Python create_api_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: setUp

 def setUp(self):
     super(UserResourceTestCase, self).setUp()
     create_api_key(User, instance=self.user, created=True)
     self.client = TestClient(
         path="/api/v1/user/",
         data={"email": "[email protected]", "username": self.user.email, "api_key": self.user.api_key.key},
     )
开发者ID:DirectEmployers,项目名称:MyJobs,代码行数:7,代码来源:test_api.py

示例2: test_is_authenticated_get_params

    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:Alexander-Attar,项目名称:django-tastypie,代码行数:31,代码来源:custom_user.py

示例3: test_is_authenticated_get_params

    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,代码行数:30,代码来源:authentication.py

示例4: test_is_authenticated

    def test_is_authenticated(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)
开发者ID:thepeopleseason,项目名称:django-tastypie,代码行数:29,代码来源:authentication.py

示例5: test_whitelisting

    def test_whitelisting(self):
        auth = DigestAuthentication(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 digest
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            john_doe.username,
            request.method,
            '/', # uri
            1,   # nonce_count
            digest_challenge=auth.is_authenticated(request)['WWW-Authenticate'],
            password=john_doe.api_key.key
        )
        self.assertEqual(auth.is_authenticated(request, method_name="another_method"), True)
        self.assertEqual(auth.is_authenticated(request, method_name="a_method"), True)
开发者ID:YACFirm,项目名称:django-tastypie,代码行数:26,代码来源:authentication.py

示例6: test_is_authenticated_header

    def test_is_authenticated_header(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.META['HTTP_AUTHORIZATION'] = 'foo'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

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

        # Wrong user/api_key.
        request.META['HTTP_AUTHORIZATION'] = 'ApiKey daniel:pass'
        self.assertEqual(isinstance(auth.is_authenticated(request), HttpUnauthorized), True)

        # Correct user/api_key.
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = 'ApiKey johndoe:%s' % john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), True)

        # Capitalization shouldn't matter.
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = 'aPiKeY johndoe:%s' % john_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), True)
开发者ID:10to8,项目名称:django-tastypie,代码行数:32,代码来源:authentication.py

示例7: test_check_active_true

    def test_check_active_true(self):
        auth = ApiKeyAuthentication()
        request = HttpRequest()

        bob_doe = User.objects.get(username="bobdoe")
        create_api_key(User, instance=bob_doe, created=True)
        request.META["HTTP_AUTHORIZATION"] = "ApiKey bobdoe:%s" % bob_doe.api_key.key
        self.assertEqual(auth.is_authenticated(request), False)
开发者ID:mattbriancon,项目名称:django-tastypie,代码行数:8,代码来源:authentication.py

示例8: setUp

 def setUp(self):
     self.user = UserFactory()
     self.client = TestClient()
     create_api_key(User, instance=self.user, created=True)
     self.data = {'email': '[email protected]',
                  'username': self.user.email,
                  'api_key': self.user.api_key.key
     }
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:8,代码来源:api.py

示例9: setUp

 def setUp(self):
     super(UserResourceTests, self).setUp()
     create_api_key(User, instance=self.user, created=True)
     self.client = TestClient(
         path='/api/v1/user/',
         data={'email': '[email protected]',
               'username': self.user.email,
               'api_key': self.user.api_key.key})
开发者ID:kepinq,项目名称:MyJobs,代码行数:8,代码来源:test_api.py

示例10: test_check_active_false

    def test_check_active_false(self):
        auth = BasicAuthentication(require_active=False)
        request = HttpRequest()

        bob_doe = User.objects.get(username='bobdoe')
        create_api_key(User, instance=bob_doe, created=True)
        request.META['HTTP_AUTHORIZATION'] = 'ApiKey bobdoe:%s' % bob_doe.api_key.key
        self.assertTrue(auth.is_authenticated(request))
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:8,代码来源:authentication.py

示例11: setUp

 def setUp(self):
     user = User.objects.create_user(username='[email protected]', email='[email protected]', password=None)
     client = Clients.objects.get(pk=1)
     Clients2Users.objects.create(user=Users.objects.get(email='[email protected]'), client=client)
     try:
         create_api_key(sender=User, instance=user, created=True)
     except:
         pass
     self.data = {'username':user.email, 'api_key':user.api_key.key}
开发者ID:daudmabena,项目名称:WebFinance,代码行数:9,代码来源:test_invoices.py

示例12: setUp

    def setUp(self):
        super(ApiKeyAuthenticationTestCase, self).setUp()
        ApiKey.objects.all().delete()
        self.auth = ApiKeyAuthentication()
        self.request = HttpRequest()

        # Simulate sending the signal.
        user = User.objects.get(username='apiuser')
        create_api_key(User, instance=user, created=True)
开发者ID:Kami,项目名称:codespeed,代码行数:9,代码来源:tests_api.py

示例13: setUp

 def setUp(self):
     """
     Creates an api key for test user(from fixture) and sets permission to add logmessages
     """
     super(RestTest, self).setUp()
     ApiKey.objects.all().delete()
     create_api_key(User, instance=User.objects.get(username=self.username), created=True)
     add_logmessage = Permission.objects.get(codename='add_logmessage')
     User.objects.get(username=self.username).user_permissions.add(add_logmessage)
开发者ID:monlog,项目名称:monlog,代码行数:9,代码来源:tests.py

示例14: test_check_active_false

    def test_check_active_false(self):
        user_class = get_user_model()
        auth = BasicAuthentication(require_active=False)
        request = HttpRequest()

        bob_doe = user_class.objects.get(**{user_class.USERNAME_FIELD: 'bobdoe'})
        create_api_key(User, instance=bob_doe, created=True)
        request.META['HTTP_AUTHORIZATION'] = 'ApiKey bobdoe:%s' % bob_doe.api_key.key
        self.assertTrue(auth.is_authenticated(request))
开发者ID:amitu,项目名称:django-tastypie,代码行数:9,代码来源:authentication.py

示例15: setUp

    def setUp(self):
        super(SavedSearchResourceTests, self).setUp()
        self.user = UserFactory()
        self.client = TestClient(
            path='/api/v1/savedsearch/',
            data={'email': '[email protected]',
                  'url': 'www.my.jobs/jobs'})
        create_api_key(User, instance=self.user, created=True)

        self.credentials = (self.user.email, self.user.api_key.key)

        self.patcher = patch('urllib2.urlopen', return_file())
        self.patcher.start()
开发者ID:AstroMatchDynamics,项目名称:MyJobs,代码行数:13,代码来源:test_api.py


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