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

Python test_oauth.OAuthClient类代码示例

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

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



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

示例1: TestApiReviewer

class TestApiReviewer(BaseOAuth, ESTestCase):
    fixtures = fixture('webapp_337141', 'user_2519')

    def setUp(self, api_name='apps'):
        self.user = User.objects.get(pk=2519)
        self.profile = self.user.get_profile()
        self.profile.update(read_dev_agreement=datetime.now())
        self.grant_permission(self.profile, 'Apps:Review')

        self.access = Access.objects.create(key='foo', secret=generate(),
                                            user=self.user)
        self.client = OAuthClient(self.access, api_name=api_name)
        self.list_url = ('api_dispatch_list', {'resource_name': 'search'})

        self.webapp = Webapp.objects.get(pk=337141)
        self.category = Category.objects.create(name='test',
                                                type=amo.ADDON_WEBAPP)
        self.webapp.save()
        self.refresh()

    def test_status_reviewer(self):
        res = self.client.get(self.list_url + ({'status': 'public'},))
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['app_slug'], self.webapp.app_slug)

        res = self.client.get(self.list_url + ({'status': 'rejected'},))
        eq_(res.status_code, 200)
        objs = json.loads(res.content)['objects']
        eq_(len(objs), 0)
开发者ID:bsmedberg,项目名称:zamboni,代码行数:30,代码来源:test_api.py


示例2: test_owner_still_non_reviewer_access

 def test_owner_still_non_reviewer_access(self):
     user = Webapp.objects.get(pk=337141).authors.all()[0].user
     access = Access.objects.create(
         key='test_oauth_key_owner', secret=generate(), user=user)
     client = OAuthClient(access, api_name='reviewers')
     res = client.get(self.url)
     eq_(res.status_code, 401)
开发者ID:markh-bz,项目名称:zamboni,代码行数:7,代码来源:test_api.py


示例3: test_admin_get

 def test_admin_get(self):
     self.create_app()
     admin = UserProfile.objects.get(email="[email protected]")
     g = Group.objects.create(rules="*:*")
     GroupUser.objects.create(group=g, user=admin)
     ac = Access.objects.create(key="adminOauthKey", secret=generate(), user=admin.user)
     client = OAuthClient(ac, api_name="apps")
     r = client.get(self.get_url)
     eq_(r.status_code, 200)
开发者ID:kmaglione,项目名称:zamboni,代码行数:9,代码来源:test_handlers.py


示例4: test_reviewer_get

 def test_reviewer_get(self):
     self.create_app()
     editor = UserProfile.objects.get(email="[email protected]")
     g = Group.objects.create(rules="Apps:Review,Reviews:Edit")
     GroupUser.objects.create(group=g, user=editor)
     ac = Access.objects.create(key="adminOauthKey", secret=generate(), user=editor.user)
     client = OAuthClient(ac, api_name="apps")
     r = client.get(self.get_url)
     eq_(r.status_code, 200)
开发者ID:kmaglione,项目名称:zamboni,代码行数:9,代码来源:test_handlers.py


示例5: TestFeaturedHomeHandler

class TestFeaturedHomeHandler(BaseOAuth):

    def setUp(self):
        super(TestFeaturedHomeHandler, self).setUp()
        resource = 'featured/home'
        self.list_url = ('api_dispatch_list', {'resource_name': resource})
        self.get_url = None
        self.client = OAuthClient(None)

        self.cat = Category.objects.create(name='awesome',
                                           type=amo.ADDON_WEBAPP)

        # App, no category, worldwide region.
        self.app1 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 1')
        f1 = FeaturedApp.objects.create(app=self.app1, category=None)
        FeaturedAppRegion.objects.create(featured_app=f1,
                                         region=mkt.regions.WORLDWIDE.id)

        # App, with category, worldwide region. Mostly to ensure category
        # specific featured apps don't slip into the results.
        self.app2 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 2')
        AddonCategory.objects.create(category=self.cat, addon=self.app2)
        f2 = FeaturedApp.objects.create(app=self.app2, category=self.cat)
        FeaturedAppRegion.objects.create(featured_app=f2,
                                         region=mkt.regions.WORLDWIDE.id)

        # App, no category, US region.
        self.app3 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 3')
        f3 = FeaturedApp.objects.create(app=self.app3)
        FeaturedAppRegion.objects.create(featured_app=f3,
                                         region=mkt.regions.US.id)

    def test_verbs(self):
        self._allowed_verbs(self.list_url, ['get'])

    def test_get_featured(self):
        res = self.client.get(self.list_url)
        data = json.loads(res.content)
        eq_(res.status_code, 200)
        eq_(data['objects'][0]['app_slug'], self.app1.app_slug)

    def test_get_featured_region(self):
        # UK region should come up empty, so we backfill with worldwide.
        res = self.client.get(self.list_url, data=dict(region='uk'))
        data = json.loads(res.content)
        eq_(res.status_code, 200)
        eq_(data['objects'][0]['app_slug'], self.app1.app_slug)

        # US region should come have 1 plus worldwide.
        res = self.client.get(self.list_url, data=dict(region='us'))
        data = json.loads(res.content)
        eq_(res.status_code, 200)
        self.assertSetEqual([o['app_slug'] for o in data['objects']],
                            ['app-1', 'app-3'])
开发者ID:sandy-slin,项目名称:zamboni,代码行数:57,代码来源:test_handlers.py


示例6: TestCategoryHandler

class TestCategoryHandler(BaseOAuth):

    def setUp(self):
        super(TestCategoryHandler, self).setUp()
        self.cat = Category.objects.create(name='Webapp',
                                           type=amo.ADDON_WEBAPP,
                                           slug='thewebapp')
        self.cat.name = {'fr': 'Le Webapp'}
        self.cat.save()
        self.other = Category.objects.create(name='other',
                                             type=amo.ADDON_EXTENSION)

        self.list_url = ('api_dispatch_list', {'resource_name': 'category'})
        self.get_url = ('api_dispatch_detail',
                        {'resource_name': 'category', 'pk': self.cat.pk})

        self.client = OAuthClient(None)

    def test_verbs(self):
        self._allowed_verbs(self.list_url, ['get'])
        self._allowed_verbs(self.get_url, ['get'])

    def test_weight(self):
        self.cat.update(weight=-1)
        res = self.client.get(self.list_url)
        data = json.loads(res.content)
        eq_(data['meta']['total_count'], 0)

    def test_get_categories(self):
        res = self.client.get(self.list_url)
        data = json.loads(res.content)
        eq_(data['meta']['total_count'], 1)
        eq_(data['objects'][0]['name'], 'Webapp')
        eq_(data['objects'][0]['slug'], 'thewebapp')

    def test_get_category(self):
        res = self.client.get(self.get_url)
        data = json.loads(res.content)
        eq_(data['name'], 'Webapp')

    def test_get_category_localised(self):
        res = self.client.get(self.get_url, HTTP_ACCEPT_LANGUAGE='fr')
        data = json.loads(res.content)
        eq_(data['name'], 'Le Webapp')

    def test_get_other_category(self):
        res = self.client.get(('api_dispatch_detail',
                              {'resource_name': 'category',
                               'pk': self.other.pk}))
        eq_(res.status_code, 404)
开发者ID:bsmedberg,项目名称:zamboni,代码行数:50,代码来源:test_handlers.py


示例7: setUp

 def setUp(self):
     self.create_switch('search-api-es')
     self.create_switch('buchets')
     self.client = OAuthClient(None)
     self.url = list_url('search')
     self.webapp = Webapp.objects.get(pk=337141)
     self.category = Category.objects.create(name='test',
                                             type=amo.ADDON_WEBAPP)
     # A typical desktop profile on Firefox with the following features:
     # {'apps': True,
     #  'audio': True,
     #  'battery': True,
     #  'device_storage': True,
     #  'fullscreen': True,
     #  'geolocation': True,
     #  'idle': True,
     #  'indexeddb': True,
     #  'light_events': True,
     #  'network_info': True,
     #  'orientation': True,
     #  'proximity': True,
     #  'push': True,
     #  'sms': True,
     #  'vibrate': True,
     #  'video_webm': True,
     #  'webaudio': True}
     self.profile = '8a7dd46c.32.1'
     self.qs = {'q': 'something', 'pro': self.profile, 'dev': 'firefoxos'}
开发者ID:MikeLing,项目名称:zamboni,代码行数:28,代码来源:test_api.py


示例8: setUp

 def setUp(self):
     super(TestAccount, self).setUp(api_name='reviewers')
     self.list_url = list_url('reviewing')
     self.anon = OAuthClient(None, api_name='reviewers')
     self.user = UserProfile.objects.get(pk=2519)
     self.req = RequestFactory().get('/')
     self.req.amo_user = self.user
开发者ID:chenzihui,项目名称:zamboni,代码行数:7,代码来源:test_api.py


示例9: test_multiple_fails

    def test_multiple_fails(self):
        client = OAuthClient(Mock(key='foo', secret='bar'))
        req = RequestFactory().get('/',
                HTTP_HOST='api',
                HTTP_AUTHORIZATION=client.header('GET', 'http://foo/'))
        req.user = AnonymousUser()
        next_auth = Mock()
        self.resource._meta.authentication = (
                # OAuth fails because there are bogus auth headers.
                authentication.OAuthAuthentication(),
                next_auth)

        with self.assertRaises(ImmediateHttpResponse):
            eq_(self.resource.is_authenticated(req), None)
        # This never even got called.
        ok_(not next_auth.is_authenticated.called)
开发者ID:flyun,项目名称:zamboni,代码行数:16,代码来源:test_authentication.py


示例10: setUp

    def setUp(self):
        super(TestFeaturedHomeHandler, self).setUp()
        resource = 'featured/home'
        self.list_url = ('api_dispatch_list', {'resource_name': resource})
        self.get_url = None
        self.client = OAuthClient(None)

        self.cat = Category.objects.create(name='awesome',
                                           type=amo.ADDON_WEBAPP)

        # App, no category, worldwide region.
        self.app1 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 1')
        f1 = FeaturedApp.objects.create(app=self.app1, category=None)
        FeaturedAppRegion.objects.create(featured_app=f1,
                                         region=mkt.regions.WORLDWIDE.id)

        # App, with category, worldwide region. Mostly to ensure category
        # specific featured apps don't slip into the results.
        self.app2 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 2')
        AddonCategory.objects.create(category=self.cat, addon=self.app2)
        f2 = FeaturedApp.objects.create(app=self.app2, category=self.cat)
        FeaturedAppRegion.objects.create(featured_app=f2,
                                         region=mkt.regions.WORLDWIDE.id)

        # App, no category, US region.
        self.app3 = Webapp.objects.create(status=amo.STATUS_PUBLIC,
                                          name='App 3')
        f3 = FeaturedApp.objects.create(app=self.app3)
        FeaturedAppRegion.objects.create(featured_app=f3,
                                         region=mkt.regions.US.id)
开发者ID:sandy-slin,项目名称:zamboni,代码行数:32,代码来源:test_handlers.py


示例11: setUp

 def setUp(self):
     self.client = OAuthClient(None)
     self.list_url = ("api_dispatch_list", {"resource_name": "search"})
     self.webapp = Webapp.objects.get(pk=337141)
     self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP)
     self.webapp.save()
     self.refresh()
开发者ID:almet,项目名称:zamboni,代码行数:7,代码来源:test_api.py


示例12: TestSuggestionsApi

class TestSuggestionsApi(ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.url = list_url('suggest')
        self.refresh('webapp')
        self.client = OAuthClient(None)

    def test_suggestions(self):
        app1 = Webapp.objects.get(pk=337141)
        app1.save()
        app2 = app_factory(name=u"Second âpp", description=u"Second dèsc" * 25,
                           created=self.days_ago(3))
        self.refresh('webapp')

        response = self.client.get(self.url)
        parsed = json.loads(response.content)
        eq_(parsed[0], '')
        eq_(parsed[1], [unicode(app1.name), unicode(app2.name)])
        eq_(parsed[2], [unicode(app1.description),
                        unicode(truncate(app2.description))])
        eq_(parsed[3], [absolutify(app1.get_detail_url()),
                        absolutify(app2.get_detail_url())])
        eq_(parsed[4], [app1.get_icon_url(64), app2.get_icon_url(64)])

        # Cleanup to remove these from the index.
        unindex_webapps([app1.id, app2.id])
        app1.delete()
        app2.delete()
开发者ID:at13,项目名称:zamboni,代码行数:29,代码来源:test_api.py


示例13: setUp

 def setUp(self):
     self.create_switch('soft_delete')
     self.client = OAuthClient(None)
     self.url = list_url('search')
     self.webapp = Webapp.objects.get(pk=337141)
     self.category = Category.objects.create(name='test', slug='test',
                                             type=amo.ADDON_WEBAPP)
     self.webapp.save()
     self.refresh('webapp')
开发者ID:at13,项目名称:zamboni,代码行数:9,代码来源:test_api.py


示例14: TestCategoryHandler

class TestCategoryHandler(BaseOAuth):
    def setUp(self):
        super(TestCategoryHandler, self).setUp()
        self.cat = Category.objects.create(name="Webapp", type=amo.ADDON_WEBAPP, slug="thewebapp")
        self.cat.name = {"fr": "Le Webapp"}
        self.cat.save()
        self.other = Category.objects.create(name="other", type=amo.ADDON_EXTENSION)

        self.list_url = ("api_dispatch_list", {"resource_name": "category"})
        self.get_url = ("api_dispatch_detail", {"resource_name": "category", "pk": self.cat.pk})

        self.client = OAuthClient(None)

    def test_verbs(self):
        self._allowed_verbs(self.list_url, ["get"])
        self._allowed_verbs(self.get_url, ["get"])

    def test_weight(self):
        self.cat.update(weight=-1)
        res = self.client.get(self.list_url)
        data = json.loads(res.content)
        eq_(data["meta"]["total_count"], 0)

    def test_get_categories(self):
        res = self.client.get(self.list_url)
        data = json.loads(res.content)
        eq_(data["meta"]["total_count"], 1)
        eq_(data["objects"][0]["name"], "Webapp")
        eq_(data["objects"][0]["slug"], "thewebapp")

    def test_get_category(self):
        res = self.client.get(self.get_url)
        data = json.loads(res.content)
        eq_(data["name"], "Webapp")

    def test_get_category_localised(self):
        res = self.client.get(self.get_url, HTTP_ACCEPT_LANGUAGE="fr")
        data = json.loads(res.content)
        eq_(data["name"], "Le Webapp")

    def test_get_other_category(self):
        res = self.client.get(("api_dispatch_detail", {"resource_name": "category", "pk": self.other.pk}))
        eq_(res.status_code, 404)
开发者ID:almet,项目名称:zamboni,代码行数:43,代码来源:test_handlers.py


示例15: setUp

    def setUp(self):
        super(TestDeviceTypeHandler, self).setUp()

        self.dt = DeviceType.objects.create(name='Phone')
        self.dt.name = {'fr': 'Le phone'}
        self.dt.save()
        self.list_url = ('api_dispatch_list', {'resource_name': 'devicetype'})
        self.get_url = ('api_dispatch_detail',
                        {'resource_name': 'devicetype', 'pk': self.dt.pk})

        self.client = OAuthClient(None)
开发者ID:ominds,项目名称:zamboni,代码行数:11,代码来源:test_handlers.py


示例16: setUp

 def setUp(self):
     self.client = OAuthClient(None)
     self.url = list_url('search')
     self.webapp = Webapp.objects.get(pk=337141)
     self.category = Category.objects.create(name='test',
                                             type=amo.ADDON_WEBAPP)
     # Pick a few common device features.
     self.profile = FeatureProfile(apps=True, audio=True, fullscreen=True,
                                   geolocation=True, indexeddb=True,
                                   sms=True).to_signature()
     self.qs = {'q': 'something', 'pro': self.profile, 'dev': 'firefoxos'}
开发者ID:chenliu0831,项目名称:zamboni,代码行数:11,代码来源:test_api.py


示例17: setUp

    def setUp(self):
        super(TestCategoryHandler, self).setUp()
        self.cat = Category.objects.create(name="Webapp", type=amo.ADDON_WEBAPP, slug="thewebapp")
        self.cat.name = {"fr": "Le Webapp"}
        self.cat.save()
        self.other = Category.objects.create(name="other", type=amo.ADDON_EXTENSION)

        self.list_url = ("api_dispatch_list", {"resource_name": "category"})
        self.get_url = ("api_dispatch_detail", {"resource_name": "category", "pk": self.cat.pk})

        self.client = OAuthClient(None)
开发者ID:almet,项目名称:zamboni,代码行数:11,代码来源:test_handlers.py


示例18: TestApiFlags

class TestApiFlags(BaseOAuth, ESTestCase):
    fixtures = fixture('webapp_337141')
    url = list_url('search')

    def setUp(self):
        self.create_switch('search-api-es')
        self.client = OAuthClient(None)
        self.webapp = Webapp.objects.get(pk=337141)

    def _flag(self, adult=False, child=False):
        Flag.objects.create(addon=self.webapp, adult_content=adult,
                            child_content=child)
        self.webapp.save()
        self.refresh('webapp')

    def test_no_flags(self):
        self.webapp.save()
        self.refresh('webapp')
        res = self.client.get(self.url + ({'q': 'something'},))
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)

    def test_adult(self):
        self._flag(adult=True)
        res = self.client.get(self.url + (
            {'q': 'something',
             'region': list(mkt.regions.ADULT_EXCLUDED)[0].slug},))
        eq_(res.status_code, 200)
        objs = json.loads(res.content)['objects']
        eq_(len(objs), 0, 'App with adult_content not removed from search.')

    def test_child(self):
        self._flag(child=True)
        res = self.client.get(self.url + (
            {'q': 'something',
             'region': list(mkt.regions.CHILD_EXCLUDED)[0].slug},))
        eq_(res.status_code, 200)
        objs = json.loads(res.content)['objects']
        eq_(len(objs), 0, 'App with child_content not removed from search.')
开发者ID:mitramichaeljade,项目名称:zamboni,代码行数:40,代码来源:test_api.py


示例19: TestAccount

class TestAccount(BaseOAuth):
    fixtures = fixture('user_2519', 'user_10482', 'webapp_337141')

    def setUp(self):
        super(TestAccount, self).setUp()
        self.list_url = list_url('account')
        self.get_url = get_url('account', '2519')
        self.anon = OAuthClient(None, api_name='apps')
        self.user = UserProfile.objects.get(pk=2519)

    def test_verbs(self):
        self._allowed_verbs(self.list_url, ())
        self._allowed_verbs(self.get_url, ('get',))

    def test_not_allowed(self):
        eq_(self.anon.get(self.get_url).status_code, 401)

    def test_allowed(self):
        res = self.client.get(self.get_url)
        eq_(res.status_code, 200, res.content)
        data = json.loads(res.content)
        eq_(data['display_name'], self.user.display_name)
        eq_(data['installed'], [])

    def test_install(self):
        ins = Installed.objects.create(user=self.user, addon_id=337141)
        res = self.client.get(self.get_url)
        eq_(res.status_code, 200, res.content)
        data = json.loads(res.content)
        eq_(data['installed'],
            [get_absolute_url(get_url('app', ins.addon.pk), absolute=False)])

    def test_install_reviewer(self):
        Installed.objects.create(user=self.user, addon_id=337141,
                                 install_type=INSTALL_TYPE_REVIEWER)
        res = self.client.get(self.get_url)
        eq_(res.status_code, 200, res.content)
        data = json.loads(res.content)
        eq_(data['installed'], [])

    def test_other(self):
        eq_(self.client.get(get_url('account', '10482')).status_code, 403)

    def test_own(self):
        res = self.client.get(get_url('account', 'mine'))
        eq_(res.status_code, 200)
        data = json.loads(res.content)
        eq_(data['display_name'], self.user.display_name)
开发者ID:almet,项目名称:zamboni,代码行数:48,代码来源:test_api.py


示例20: setUp

    def setUp(self, api_name="reviewers"):
        super(TestApiReviewer, self).setUp(api_name=api_name)
        self.user = User.objects.get(pk=2519)
        self.profile = self.user.get_profile()
        self.profile.update(read_dev_agreement=datetime.now())
        self.grant_permission(self.profile, "Apps:Review")

        self.access = Access.objects.create(key="test_oauth_key", secret=generate(), user=self.user)
        self.client = OAuthClient(self.access, api_name=api_name)
        self.url = list_url("search")

        self.webapp = Webapp.objects.get(pk=337141)
        self.category = Category.objects.create(name="test", type=amo.ADDON_WEBAPP)

        self.webapp.update(status=amo.STATUS_PENDING)
        self.refresh("webapp")
开发者ID:pombredanne,项目名称:zamboni,代码行数:16,代码来源:test_api.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python test_oauth.RestOAuth类代码示例发布时间:2022-05-27
下一篇:
Python test_oauth.get_absolute_url函数代码示例发布时间: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