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


Python test_oauth.OAuthClient类代码示例

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


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


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