• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.create_api_key函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: banyanuser_post_save

def banyanuser_post_save(sender, **kwargs):
    from tastypie.models import create_api_key
    from accounts.tasks import new_user, update_user_groups

    user = kwargs.get('instance')
    
    create_api_key(sender, **kwargs)
    
    update_user_groups.delay(user)
    
    if kwargs.get('created') is False:
        return
    
    user = kwargs.get('instance')
    new_user.delay(user)
开发者ID:adminus,项目名称:banyan-web,代码行数:15,代码来源:signals.py


示例17: create_api_key_ignore_dberrors

def create_api_key_ignore_dberrors(*args, **kwargs):
    try:
        return create_api_key(*args, **kwargs)
    except DatabaseError:
        # no such table yet, first syncdb
        from django.db import transaction
        transaction.rollback_unless_managed()
开发者ID:deejay1,项目名称:ralph,代码行数:7,代码来源:models.py


示例18: test_check_active_true

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

        bob_doe = User.objects.get(username='bobdoe')
        create_api_key(User, instance=bob_doe, created=True)
        auth_request = auth.is_authenticated(request)
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            bob_doe.username,
            request.method,
            '/', # uri
            1,   # nonce_count
            digest_challenge=auth_request['WWW-Authenticate'],
            password=bob_doe.api_key.key
        )
        auth_request = auth.is_authenticated(request)
        self.assertFalse(auth_request)
开发者ID:10to8,项目名称:django-tastypie,代码行数:17,代码来源:authentication.py


示例19: test_is_authenticated

    def test_is_authenticated(self):
        auth = DigestAuthentication()
        request = HttpRequest()

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

        # No HTTP Basic auth details should fail.
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # HttpUnauthorized with auth type and realm
        self.assertEqual(auth_request['WWW-Authenticate'].find('Digest'), 0)
        self.assertEqual(auth_request['WWW-Authenticate'].find(' realm="django-tastypie"') > 0, True)
        self.assertEqual(auth_request['WWW-Authenticate'].find(' opaque=') > 0, True)
        self.assertEqual(auth_request['WWW-Authenticate'].find('nonce=') > 0, True)

        # Wrong basic auth details.
        request.META['HTTP_AUTHORIZATION'] = 'abcdefg'
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # No password.
        request.META['HTTP_AUTHORIZATION'] = base64.b64encode('daniel'.encode('utf-8')).decode('utf-8')
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Wrong user/password.
        request.META['HTTP_AUTHORIZATION'] = base64.b64encode('daniel:pass'.encode('utf-8')).decode('utf-8')
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Correct user/password.
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            username=john_doe.username,
            method=request.method,
            uri='/',
            nonce_count=1,
            digest_challenge=python_digest.parse_digest_challenge(auth_request['WWW-Authenticate']),
            password=john_doe.api_key.key
        )
        auth_request = auth.is_authenticated(request)
        self.assertEqual(auth_request, True)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:45,代码来源:authentication.py


示例20: test_is_authenticated

    def test_is_authenticated(self):
        auth = DigestAuthentication()
        request = HttpRequest()

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

        # No HTTP Basic auth details should fail.
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # HttpUnauthorized with auth type and realm
        self.assertEqual(auth_request["WWW-Authenticate"].find("Digest"), 0)
        self.assertEqual(auth_request["WWW-Authenticate"].find(' realm="django-tastypie"') > 0, True)
        self.assertEqual(auth_request["WWW-Authenticate"].find(" opaque=") > 0, True)
        self.assertEqual(auth_request["WWW-Authenticate"].find("nonce=") > 0, True)

        # Wrong basic auth details.
        request.META["HTTP_AUTHORIZATION"] = "abcdefg"
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # No password.
        request.META["HTTP_AUTHORIZATION"] = base64.b64encode("daniel")
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Wrong user/password.
        request.META["HTTP_AUTHORIZATION"] = base64.b64encode("daniel:pass")
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Correct user/password.
        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_request["WWW-Authenticate"],
            password=john_doe.api_key.key,
        )
        auth_request = auth.is_authenticated(request)
        self.assertEqual(auth_request, True)
开发者ID:coffindragger,项目名称:django-tastypie,代码行数:45,代码来源:authentication.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python paginator.Paginator类代码示例发布时间:2022-05-27
下一篇:
Python bundle.Bundle类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap