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


Python RestOAuthClient.get方法代码示例

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


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

示例1: TestSuggestionsApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestSuggestionsApi(ESTestCase):
    fixtures = fixture("webapp_337141")

    def setUp(self):
        self.url = reverse("suggestions-search-api")
        self.refresh("webapp")
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.save()
        self.app2 = app_factory(
            name=u"Second âpp", description=u"Second dèsc" * 25, icon_type="image/png", created=self.days_ago(3)
        )
        self.refresh("webapp")

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_suggestions(self):
        response = self.client.get(self.url, data={"lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(parsed[0], "")
        self.assertSetEqual(parsed[1], [unicode(self.app1.name), unicode(self.app2.name)])
        self.assertSetEqual(parsed[2], [unicode(self.app1.description), unicode(truncate(self.app2.description))])
        self.assertSetEqual(parsed[3], [absolutify(self.app1.get_detail_url()), absolutify(self.app2.get_detail_url())])
        self.assertSetEqual(parsed[4], [self.app1.get_icon_url(64), self.app2.get_icon_url(64)])

    def test_suggestions_filtered(self):
        response = self.client.get(self.url, data={"q": "Second", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(parsed[1], [unicode(self.app2.name)])
开发者ID:vinu76jsr,项目名称:zamboni,代码行数:35,代码来源:test_api.py

示例2: test_owner_still_non_reviewer_access

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
 def test_owner_still_non_reviewer_access(self):
     user = Webapp.objects.get(pk=337141).authors.all()[0]
     access = Access.objects.create(
         key='test_oauth_key_owner', secret='super secret', user=user)
     client = RestOAuthClient(access)
     res = client.get(self.url)
     eq_(res.status_code, 403)
开发者ID:Witia1,项目名称:zamboni,代码行数:9,代码来源:test_views_api.py

示例3: test_admin_get

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
    def test_admin_get(self):
        app = self.create_app()
        data = self.base_data()
        self.client.put(self.get_url, data=json.dumps(data))

        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)
        client = RestOAuthClient(ac)
        r = client.get(self.get_url)
        eq_(r.status_code, 200)

        res = client.get(reverse("app-privacy-policy-detail", args=[app.pk]))
        eq_(r.status_code, 200)
        eq_(res.json["privacy_policy"], data["privacy_policy"])
开发者ID:kylewu,项目名称:zamboni,代码行数:18,代码来源:test_handlers.py

示例4: TestRocketbarApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestRocketbarApi(ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.url = reverse('rocketbar-search-api')
        self.refresh('webapp')
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.save()
        self.app2 = app_factory(name=u'Second âpp',
                                description=u'Second dèsc' * 25,
                                icon_type='image/png',
                                created=self.days_ago(3),
                                manifest_url='http://testrocketbar.example.com')
        self.refresh('webapp')

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_suggestions_filtered(self):
        response = self.client.get(self.url, data={'q': 'Second',
                                                   'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(parsed, [{'manifest_url': self.app2.get_manifest_url(),
                      'icon': self.app2.get_icon_url(64),
                      'name': unicode(self.app2.name),
                      'slug': self.app2.app_slug}])
开发者ID:bdacode,项目名称:zamboni,代码行数:32,代码来源:test_api.py

示例5: test_admin_get

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
    def test_admin_get(self):
        app = self.create_app(privacy_policy=u'élolà')

        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='admin secret',
                                   user=admin)
        client = RestOAuthClient(ac)
        r = client.get(self.get_url)
        eq_(r.status_code, 200)

        res = client.get(reverse('app-privacy-policy-detail',
                                 args=[app.pk]))
        eq_(r.status_code, 200)
        eq_(res.json['privacy_policy'], u'élolà')
开发者ID:jasonthomas,项目名称:zamboni,代码行数:18,代码来源:test_handlers.py

示例6: test_admin_get

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
 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 = RestOAuthClient(ac)
     r = client.get(self.get_url)
     eq_(r.status_code, 200)
开发者ID:hardikj,项目名称:zamboni,代码行数:11,代码来源:test_handlers.py

示例7: test_reviewer_get

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
    def test_reviewer_get(self):
        app = self.create_app()
        data = self.base_data()
        self.client.put(self.get_url, data=json.dumps(data))

        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 = RestOAuthClient(ac)
        r = client.get(self.get_url)
        eq_(r.status_code, 200)

        res = client.get(reverse('app-privacy-policy-detail',
                                 args=[app.pk]))
        eq_(r.status_code, 200)
        eq_(res.json['privacy_policy'], data['privacy_policy'])
开发者ID:BIGGANI,项目名称:zamboni,代码行数:20,代码来源:test_handlers.py

示例8: test_reviewer_get

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
 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 = RestOAuthClient(ac)
     r = client.get(self.get_url)
     eq_(r.status_code, 200)
开发者ID:hardikj,项目名称:zamboni,代码行数:11,代码来源:test_handlers.py

示例9: TestSuggestionsApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestSuggestionsApi(ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.url = reverse('suggestions-api')
        self.refresh('webapp')
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.save()
        self.app2 = app_factory(name=u'Second âpp',
                                description=u'Second dèsc' * 25,
                                created=self.days_ago(3))
        self.refresh('webapp')

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_suggestions(self):
        response = self.client.get(self.url, data={'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(parsed[0], '')
        self.assertSetEqual(
            parsed[1],
            [unicode(self.app1.name), unicode(self.app2.name)])
        self.assertSetEqual(
            parsed[2],
            [unicode(self.app1.description),
             unicode(truncate(self.app2.description))])
        self.assertSetEqual(
            parsed[3],
            [absolutify(self.app1.get_detail_url()),
             absolutify(self.app2.get_detail_url())])
        self.assertSetEqual(
            parsed[4],
            [self.app1.get_icon_url(64), self.app2.get_icon_url(64)])

    def test_suggestions_filtered(self):
        response = self.client.get(self.url, data={'q': 'Second',
                                                   'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(parsed[1], [unicode(self.app2.name)])
开发者ID:hardikj,项目名称:zamboni,代码行数:46,代码来源:test_api.py

示例10: TestRocketbarApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestRocketbarApi(ESTestCase):
    fixtures = fixture("webapp_337141")

    def setUp(self):
        self.url = reverse("rocketbar-search-api")
        self.refresh("webapp")
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.save()
        self.app2 = app_factory(
            name=u"Second âpp",
            description=u"Second dèsc" * 25,
            icon_type="image/png",
            created=self.days_ago(3),
            manifest_url="http://testrocketbar.example.com",
        )
        self.refresh("webapp")

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_suggestions_filtered(self):
        response = self.client.get(self.url, data={"q": "Second", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(
            parsed,
            [
                {
                    "manifest_url": self.app2.get_manifest_url(),
                    "icon": self.app2.get_icon_url(64),
                    "name": unicode(self.app2.name),
                    "slug": self.app2.app_slug,
                }
            ],
        )
开发者ID:vinu76jsr,项目名称:zamboni,代码行数:40,代码来源:test_api.py

示例11: TestApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestApi(RestOAuth, ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.client = RestOAuthClient(None)
        self.url = reverse('search-api')
        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')

    def tearDown(self):
        unindex_webapps(list(Webapp.with_deleted.values_list('id', flat=True)))
        Webapp.objects.all().delete()
        super(TestApi, self).tearDown()

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

    def test_has_cors(self):
        self.assertCORS(self.client.get(self.url), 'get')

    def test_meta(self):
        res = self.client.get(self.url)
        eq_(res.status_code, 200)
        eq_(set(res.json.keys()), set(['objects', 'meta']))
        eq_(res.json['meta']['total_count'], 1)

    def test_wrong_category(self):
        res = self.client.get(self.url,
                              data={'cat': self.category.slug + 'xq'})
        eq_(res.status_code, 400)
        eq_(res['Content-Type'], 'application/json')

    def test_wrong_weight(self):
        self.category.update(weight=-1)
        res = self.client.get(self.url, data={'cat': self.category.slug})
        eq_(res.status_code, 200)
        eq_(len(res.json['objects']), 0)

    def test_wrong_sort(self):
        res = self.client.get(self.url, data={'sort': 'awesomeness'})
        eq_(res.status_code, 400)

    def test_sort(self):
        # Mocked version, to make sure we are calling ES with the parameters
        # we want.
        with patch('mkt.webapps.models.Webapp.from_search') as mocked_search:
            mocked_qs = MagicMock()
            mocked_search.return_value = mocked_qs
            for api_sort, es_sort in DEFAULT_SORTING.items():
                res = self.client.get(self.url, [('sort', api_sort)])
                eq_(res.status_code, 200, res.content)
                mocked_qs.order_by.assert_called_with(es_sort)

        # Unmocked version, to make sure elasticsearch is actually accepting
        # the params.
        for api_sort, es_sort in DEFAULT_SORTING.items():
            res = self.client.get(self.url, [('sort', api_sort)])
            eq_(res.status_code, 200)

    def test_right_category(self):
        res = self.client.get(self.url, data={'cat': self.category.pk})
        eq_(res.status_code, 200)
        eq_(res.json['objects'], [])

    def create(self):
        AddonCategory.objects.create(addon=self.webapp, category=self.category)
        self.webapp.save()
        self.refresh('webapp')

    def test_right_category_present(self):
        self.create()
        res = self.client.get(
            self.url, data={'cat': self.category.pk})
        eq_(res.status_code, 200)
        objs = res.json['objects']
        eq_(len(objs), 1)

    def test_user_info_with_shared_secret(self):
        user = UserProfile.objects.all()[0]

        def fakeauth(auth, req, **kw):
            req.user = user.user
            req.amo_user = user

        with patch('mkt.api.middleware.RestSharedSecretMiddleware'
                   '.process_request', fakeauth):
            with self.settings(SITE_URL=''):
                self.create()
            res = self.client.get(
                self.url, data={'cat': self.category.pk})
            obj = res.json['objects'][0]
            assert 'user' in obj

    def test_dehydrate(self):
        with self.settings(SITE_URL='http://hy.fr'):
            self.create()
            res = self.client.get(self.url, data={'cat': self.category.pk})
#.........这里部分代码省略.........
开发者ID:bdacode,项目名称:zamboni,代码行数:103,代码来源:test_api.py

示例12: TestApiFeatures

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestApiFeatures(RestOAuth, ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.client = RestOAuthClient(None)
        self.url = reverse('search-api')
        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'}

    def test_no_features(self):
        # Base test to make sure we find the app.
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, data=self.qs)
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)

    def test_one_good_feature(self):
        # Enable an app feature that matches one in our profile.
        self.webapp.current_version.features.update(has_geolocation=True)
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, data=self.qs)
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)

    def test_one_bad_feature(self):
        # Enable an app feature that doesn't match one in our profile.
        self.webapp.current_version.features.update(has_pay=True)
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, data=self.qs)
        eq_(res.status_code, 200)
        objs = json.loads(res.content)['objects']
        eq_(len(objs), 0)

    def test_all_good_features(self):
        # Enable app features so they exactly match our device profile.
        fp = FeatureProfile.from_signature(self.profile)
        self.webapp.current_version.features.update(
            **dict(('has_%s' % k, v) for k, v in fp.items()))
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, data=self.qs)
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)

    def test_bad_profile_on_desktop(self):
        # Enable an app feature that doesn't match one in our profile.
        qs = self.qs.copy()
        del qs['dev']  # Desktop doesn't send a device.
        self.webapp.current_version.features.update(has_pay=True)
        self.webapp.save()
        self.refresh('webapp')

        res = self.client.get(self.url, data=qs)
        eq_(res.status_code, 200)
        obj = json.loads(res.content)['objects'][0]
        eq_(obj['slug'], self.webapp.app_slug)
开发者ID:bdacode,项目名称:zamboni,代码行数:74,代码来源:test_api.py

示例13: TestRocketbarApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestRocketbarApi(ESTestCase):
    fixtures = fixture("webapp_337141")

    def setUp(self):
        self.url = reverse("rocketbar-search-api")
        self.refresh("webapp")
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        self.app1.save()

        self.app2 = app_factory(
            name=u"Something Second Something Something",
            description=u"Second dèsc" * 25,
            icon_type="image/png",
            icon_hash="fakehash",
            created=self.days_ago(3),
            manifest_url="http://rocket.example.com",
        )
        self.app2.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        self.app2.save()
        self.refresh("webapp")

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_no_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={"q": "whatever", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(parsed, [])

    def test_suggestions(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={"q": "Something Second", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(
            parsed[0],
            {
                "manifest_url": self.app2.get_manifest_url(),
                "icon": self.app2.get_icon_url(64),
                "name": unicode(self.app2.name),
                "slug": self.app2.app_slug,
            },
        )
        ok_(self.app2.get_icon_url(64).endswith("?modified=fakehash"))

    def test_suggestion_default_locale(self):
        self.app2.name.locale = "es"
        self.app2.name.save()
        self.app2.default_locale = "es"
        self.app2.save()
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={"q": "Something Second", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(
            parsed[0],
            {
                "manifest_url": self.app2.get_manifest_url(),
                "icon": self.app2.get_icon_url(64),
                "name": unicode(self.app2.name),
                "slug": self.app2.app_slug,
            },
        )

    def test_suggestions_multiple_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={"q": "Something", "lang": "en-US"})
        parsed = json.loads(response.content)
        eq_(len(parsed), 2)
        eq_(
            parsed[0],
            {
                "manifest_url": self.app1.get_manifest_url(),
                "icon": self.app1.get_icon_url(64),
                "name": unicode(self.app1.name),
                "slug": self.app1.app_slug,
            },
        )
        eq_(
            parsed[1],
            {
                "manifest_url": self.app2.get_manifest_url(),
                "icon": self.app2.get_icon_url(64),
                "name": unicode(self.app2.name),
                "slug": self.app2.app_slug,
            },
        )

    def test_suggestion_non_gaia_apps(self):
        AddonDeviceType.objects.all().delete()
        self.app1.save()
        self.app2.save()
        self.refresh("webapp")
        with self.assertNumQueries(0):
#.........这里部分代码省略.........
开发者ID:nearlyfreeapps,项目名称:zamboni,代码行数:103,代码来源:test_api.py

示例14: TestRocketbarApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestRocketbarApi(ESTestCase):
    fixtures = fixture('webapp_337141')

    def setUp(self):
        self.url = reverse('rocketbar-search-api')
        self.refresh('webapp')
        self.client = RestOAuthClient(None)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        self.app1.save()

        self.app2 = app_factory(name=u'Something Second Something Something',
                                description=u'Second dèsc' * 25,
                                icon_type='image/png',
                                created=self.days_ago(3),
                                manifest_url='http://rocket.example.com')
        self.app2.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        self.app2.save()
        self.refresh('webapp')

    def tearDown(self):
        # Cleanup to remove these from the index.
        unindex_webapps([self.app1.id, self.app2.id])
        self.app1.delete()
        self.app2.delete()

    def test_no_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'whatever',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(parsed, [])

    def test_suggestions(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'Something Second',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(parsed[0], {'manifest_url': self.app2.get_manifest_url(),
                        'icon': self.app2.get_icon_url(64),
                        'name': unicode(self.app2.name),
                        'slug': self.app2.app_slug})

    def test_suggestions_multiple_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'Something',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(len(parsed), 2)
        eq_(parsed[0], {'manifest_url': self.app1.get_manifest_url(),
                        'icon': self.app1.get_icon_url(64),
                        'name': unicode(self.app1.name),
                      'slug': self.app1.app_slug})
        eq_(parsed[1], {'manifest_url': self.app2.get_manifest_url(),
                        'icon': self.app2.get_icon_url(64),
                        'name': unicode(self.app2.name),
                        'slug': self.app2.app_slug})

    def test_suggestion_non_gaia_apps(self):
        AddonDeviceType.objects.all().delete()
        self.app1.save()
        self.app2.save()
        self.refresh('webapp')
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'something'})
        parsed = json.loads(response.content)
        eq_(parsed, [])

    def test_suggestions_limit(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'something',
                                                       'lang': 'en-US',
                                                       'limit': 1})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(parsed[0], {'manifest_url': self.app1.get_manifest_url(),
                        'icon': self.app1.get_icon_url(64),
                        'name': unicode(self.app1.name),
                        'slug': self.app1.app_slug})
开发者ID:AALEKH,项目名称:zamboni,代码行数:82,代码来源:test_api.py

示例15: TestRocketbarApi

# 需要导入模块: from mkt.api.tests.test_oauth import RestOAuthClient [as 别名]
# 或者: from mkt.api.tests.test_oauth.RestOAuthClient import get [as 别名]
class TestRocketbarApi(ESTestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.url = reverse('rocketbar-search-api')
        self.refresh('webapp')
        self.client = RestOAuthClient(None)
        self.profile = UserProfile.objects.get(pk=2519)
        self.app1 = Webapp.objects.get(pk=337141)
        self.app1.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        self.app1.save()

        self.app2 = app_factory(name=u'Something Second Something Something',
                                description=u'Second dèsc' * 25,
                                icon_type='image/png',
                                icon_hash='fakehash',
                                created=self.days_ago(3),
                                manifest_url='http://rocket.example.com')
        self.app2.addondevicetype_set.create(device_type=amo.DEVICE_GAIA.id)
        # Add 2 installed records so this app is boosted higher than app1.
        Installed.objects.create(user=self.profile, addon=self.app2)
        Installed.objects.create(user=amo.tests.user_factory(),
                                 addon=self.app2)
        self.app2.save()
        self.refresh('webapp')

    def tearDown(self):
        # Cleanup to remove these from the index.
        self.app1.delete()
        self.app2.delete()
        unindex_webapps([self.app1.id, self.app2.id])
        # Required to purge the suggestions data structure. In Lucene, a
        # document is not deleted from a segment, just marked as deleted.
        WebappIndexer.get_es().optimize(WebappIndexer.get_index(),
                                        only_expunge_deletes=True)

    def test_no_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'whatever',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(parsed, [])

    def test_suggestions(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'Something Second',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(parsed[0], {'manifest_url': self.app2.get_manifest_url(),
                        'icon': self.app2.get_icon_url(64),
                        'name': unicode(self.app2.name),
                        'slug': self.app2.app_slug})
        ok_(self.app2.get_icon_url(64).endswith('?modified=fakehash'))

    def test_suggestion_default_locale(self):
        self.app2.name.locale = 'es'
        self.app2.name.save()
        self.app2.default_locale = 'es'
        self.app2.save()
        self.refresh()
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'Something Second',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(len(parsed), 1)
        eq_(parsed[0], {'manifest_url': self.app2.get_manifest_url(),
                        'icon': self.app2.get_icon_url(64),
                        'name': unicode(self.app2.name),
                        'slug': self.app2.app_slug})

    def test_suggestions_multiple_results(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'Something',
                                                       'lang': 'en-US'})
        parsed = json.loads(response.content)
        eq_(len(parsed), 2)
        # Show app2 first since it gets boosted higher b/c of installs.
        eq_(parsed[0], {'manifest_url': self.app2.get_manifest_url(),
                        'icon': self.app2.get_icon_url(64),
                        'name': unicode(self.app2.name),
                        'slug': self.app2.app_slug})
        eq_(parsed[1], {'manifest_url': self.app1.get_manifest_url(),
                        'icon': self.app1.get_icon_url(64),
                        'name': unicode(self.app1.name),
                        'slug': self.app1.app_slug})

    def test_suggestion_non_gaia_apps(self):
        AddonDeviceType.objects.all().delete()
        self.app1.save()
        self.app2.save()
        self.refresh('webapp')
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'something'})
        parsed = json.loads(response.content)
        eq_(parsed, [])

    def test_suggestions_limit(self):
        with self.assertNumQueries(0):
            response = self.client.get(self.url, data={'q': 'something',
#.........这里部分代码省略.........
开发者ID:Dreadchild,项目名称:zamboni,代码行数:103,代码来源:test_views.py


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