~stephen-stewart/ubuntu-webcatalog/unfubar-js

« back to all changes in this revision

Viewing changes to src/webcatalog/tests/test_api.py

  • Committer: Tarmac
  • Author(s): anthony.lenton at canonical
  • Date: 2012-09-28 11:43:17 UTC
  • mfrom: (170.1.1 metadata_api)
  • Revision ID: noreply@canonical.com-20120928114317-lgxx18hhysfzo5uw
[r=elachuni],[bug=1052103] Added a public extensible metadata api.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
__metaclass__ = type
23
23
__all__ = [
 
24
    'AppMetadataTestCase',
24
25
    'DeleteMachineTestCase',
25
26
    'GetMachineTestCase',
26
27
    'ListPackagesTestCase',
30
31
    'UpdatePackageListTestCase',
31
32
]
32
33
 
 
34
import json
33
35
from django.utils import simplejson
34
 
 
35
36
from django.test import TestCase
36
37
from oauth.oauth import (
37
38
    OAuthRequest,
256
257
            **self.auth_header_for_user(url, user=otheruser))
257
258
 
258
259
        self.assertEqual(404, response.status_code)
 
260
 
 
261
 
 
262
class AppMetadataTestCase(TestCaseWithFactory):
 
263
    def test_is_public(self):
 
264
        response = self.client.get('/cat/api/1.0/apps-meta/')
 
265
 
 
266
        self.assertEqual(200, response.status_code)
 
267
 
 
268
    def test_contains_right_fields(self):
 
269
        self.factory.make_application(is_latest=True)
 
270
 
 
271
        response = self.client.get('/cat/api/1.0/apps-meta/')
 
272
 
 
273
        data = json.loads(response.content)
 
274
        self.assertEqual(1, len(data))
 
275
        expected = set(('package_name', 'categories'))
 
276
        self.assertEqual(expected, set(data[0].keys()))
 
277
 
 
278
    def test_gzipped_content(self):
 
279
        # Generate some content so that we gzip the content
 
280
        distroseries = self.factory.make_distroseries(code_name='rabbid')
 
281
        for i in range(4):
 
282
            self.factory.make_application(distroseries=distroseries)
 
283
        url = '/cat/api/1.0/apps-meta/%s/' % distroseries.code_name
 
284
 
 
285
        response = self.client.get(url, HTTP_ACCEPT_ENCODING='gzip')
 
286
 
 
287
        self.assertEqual('gzip', response['content-encoding'])