Esempio n. 1
0
    def test_list_extensions_json(self):
        app = router.APIRouter()
        request = webob.Request.blank("/fake/extensions")
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)

        # Make sure we have all the extensions, extra extensions being OK.
        data = jsonutils.loads(response.body)
        names = [str(x['name']) for x in data['extensions']
                 if str(x['name']) in self.ext_list]
        names.sort()
        self.assertEqual(self.ext_list, names)

        # Ensure all the timestamps are valid according to iso8601
        for ext in data['extensions']:
            iso8601.parse_date(ext['updated'])

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [
            x for x in data['extensions'] if x['alias'] == 'FOXNSOX']
        self.assertEqual(
            {'name': 'Fox In Socks',
             'updated': '2011-01-22T13:25:27-06:00',
             'description': 'The Fox In Socks Extension.',
             'alias': 'FOXNSOX',
             'links': []},
            fox_ext)

        for ext in data['extensions']:
            url = '/fake/extensions/%s' % ext['alias']
            request = webob.Request.blank(url)
            response = request.get_response(app)
            output = jsonutils.loads(response.body)
            self.assertEqual(ext['alias'], output['extension']['alias'])
Esempio n. 2
0
def wsgi_app(inner_app_v2=None,
             fake_auth=True,
             fake_auth_context=None,
             use_no_auth=False,
             ext_mgr=None):
    if not inner_app_v2:
        inner_app_v2 = router.APIRouter(ext_mgr)

    if fake_auth:
        if fake_auth_context is not None:
            ctxt = fake_auth_context
        else:
            ctxt = context.RequestContext('fake', 'fake', auth_token=True)
        api_v2 = fault.FaultWrapper(auth.InjectContext(ctxt, inner_app_v2))
    elif use_no_auth:
        api_v2 = fault.FaultWrapper(
            auth.NoAuthMiddleware(limits.RateLimitingMiddleware(inner_app_v2)))
    else:
        api_v2 = fault.FaultWrapper(
            auth.AuthMiddleware(limits.RateLimitingMiddleware(inner_app_v2)))

    mapper = urlmap.URLMap()
    mapper['/v2'] = api_v2
    mapper['/'] = fault.FaultWrapper(versions.Versions())
    return mapper
Esempio n. 3
0
def app():
    """API application.

    No auth, just let environ['manila.context'] pass through.
    """
    mapper = urlmap.URLMap()
    mapper['/v1'] = router_v1.APIRouter()
    mapper['/v2'] = router_v2.APIRouter()
    return mapper
    def test_versions_version_not_acceptable(self):
        req = fakes.HTTPRequest.blank('/', base_url='http://localhost/v2')
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = {version_header_name: '3.0'}

        response = req.get_response(router.APIRouter())

        self.assertEqual(406, response.status_int)
        self.assertEqual('3.0', response.headers[version_header_name])
        self.assertEqual(version_header_name, response.headers['Vary'])
Esempio n. 5
0
    def _bounce_id(self, test_id):
        class BounceController(object):
            def show(self, req, id):
                return id

        res_ext = extensions.ResourceExtension('bounce', BounceController())
        manager = StubExtensionManager(res_ext)
        app = router.APIRouter(manager)
        request = webob.Request.blank("/fake/bounce/%s" % test_id)
        response = request.get_response(app)
        return response.body
Esempio n. 6
0
    def test_get_extension_json(self):
        app = router.APIRouter()
        request = webob.Request.blank("/fake/extensions/FOXNSOX")
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)

        data = jsonutils.loads(response.body)
        self.assertEqual(
            {"name": "Fox In Socks",
             "updated": "2011-01-22T13:25:27-06:00",
             "description": "The Fox In Socks Extension.",
             "alias": "FOXNSOX",
             "links": []},
            data['extension'])
    def test_versions_v1(self, version):
        req = fakes.HTTPRequest.blank('/', base_url='http://localhost/v1')
        req.method = 'GET'
        req.content_type = 'application/json'
        req.headers = {version_header_name: version}

        response = req.get_response(router.APIRouter())
        self.assertEqual(200, response.status_int)
        body = jsonutils.loads(response.body)
        version_list = body['versions']

        ids = [v['id'] for v in version_list]
        self.assertEqual({'v1.0'}, set(ids))
        self.assertEqual('1.0', response.headers[version_header_name])
        self.assertEqual(version_header_name, response.headers['Vary'])
        self.assertEqual('', version_list[0].get('min_version'))
        self.assertEqual('', version_list[0].get('version'))
Esempio n. 8
0
    def test_get_extension_xml(self):
        app = router.APIRouter()
        request = webob.Request.blank("/fake/extensions/FOXNSOX")
        request.accept = "application/xml"
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)
        xml = response.body

        root = etree.XML(xml)
        self.assertEqual(root.tag.split('extension')[0], NS)
        self.assertEqual(root.get('alias'), 'FOXNSOX')
        self.assertEqual(root.get('name'), 'Fox In Socks')
        self.assertEqual(root.get('namespace'),
                         'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(root.findtext('{0}description'.format(NS)),
                         'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extension')
Esempio n. 9
0
    def test_list_extensions_xml(self):
        app = router.APIRouter()
        request = webob.Request.blank("/fake/extensions")
        request.accept = "application/xml"
        response = request.get_response(app)
        self.assertEqual(200, response.status_int)

        root = etree.XML(response.body)
        self.assertEqual(root.tag.split('extensions')[0], NS)

        # Make sure we have all the extensions, extras extensions being OK.
        exts = root.findall('{0}extension'.format(NS))
        self.assertTrue(len(exts) >= len(self.ext_list))

        # Make sure that at least Fox in Sox is correct.
        (fox_ext, ) = [x for x in exts if x.get('alias') == 'FOXNSOX']
        self.assertEqual(fox_ext.get('name'), 'Fox In Socks')
        self.assertEqual(fox_ext.get('namespace'),
                         'http://www.fox.in.socks/api/ext/pie/v1.0')
        self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00')
        self.assertEqual(fox_ext.findtext('{0}description'.format(NS)),
                         'The Fox In Socks Extension')

        xmlutil.validate_schema(root, 'extensions')
Esempio n. 10
0
 def test_get_non_existing_extension_json(self):
     app = router.APIRouter()
     request = webob.Request.blank("/fake/extensions/4")
     response = request.get_response(app)
     self.assertEqual(404, response.status_int)
 def setUp(self):
     super(VersionsControllerTestCase, self).setUp()
     self.wsgi_apps = (versions.VersionsRouter(), router.APIRouter())
Esempio n. 12
0
 def setUp(self):
     super(VolumeRouterTestCase, self).setUp()
     # NOTE(vish): versions is just returning text so, no need to stub.
     self.app = router.APIRouter()