Exemplo n.º 1
0
 def _path_req(self, path, method='GET', data=None,
               query_string=None,
               admin_context=True):
     content_type = 'application/%s' % self.fmt
     body = None
     if data is not None:  # empty dict is valid
         body = Serializer().serialize(data, content_type)
     if admin_context:
         return create_request(
             path, body, content_type, method, query_string=query_string)
     else:
         return create_request(
             path, body, content_type, method, query_string=query_string,
             context=context.Context('', 'tenant_id'))
Exemplo n.º 2
0
 def _path_req(self, path, method='GET', data=None,
               query_string=None,
               admin_context=True):
     content_type = 'application/%s' % self.fmt
     body = None
     if data is not None:  # empty dict is valid
         body = Serializer().serialize(data, content_type)
     if admin_context:
         return create_request(
             path, body, content_type, method, query_string=query_string)
     else:
         return create_request(
             path, body, content_type, method, query_string=query_string,
             context=context.Context('', 'tenant_id'))
Exemplo n.º 3
0
    def _req(self, method, resource, data=None, fmt='json',
             id=None, subresource=None, sub_id=None, params=None, action=None):
        if id and action:
            path = '/lb/%(resource)s/%(id)s/%(action)s.%(fmt)s' % locals()
        elif id and subresource and sub_id:
            path = (
                '/lb/%(resource)s/%(id)s/%(subresource)s/'
                '%(sub_id)s.%(fmt)s') % locals()
        elif id and subresource:
            path = (
                '/lb/%(resource)s/%(id)s/'
                '%(subresource)s.%(fmt)s') % locals()
        elif id:
            path = '/lb/%(resource)s/%(id)s.%(fmt)s' % locals()
        else:
            path = '/lb/%(resource)s.%(fmt)s' % locals()

        content_type = 'application/%s' % fmt
        body = None
        if data is not None:  # empty dict is valid
            body = Serializer().serialize(data, content_type)

        req = create_request(path,
                             body,
                             content_type,
                             method,
                             query_string=params)
        return req
Exemplo n.º 4
0
 def _req(self, method, resource, data=None, fmt='json', id=None):
     if id:
         path = '/%(resource)s/%(id)s.%(fmt)s' % locals()
     else:
         path = '/%(resource)s.%(fmt)s' % locals()
     content_type = 'application/%s' % fmt
     body = None
     if data:
         body = Serializer().serialize(data, content_type)
     return create_request(path, body, content_type, method)
Exemplo n.º 5
0
 def _req(self, method, resource, data=None, fmt='json', id=None):
     if id:
         path = '/%(resource)s/%(id)s.%(fmt)s' % locals()
     else:
         path = '/%(resource)s.%(fmt)s' % locals()
     content_type = 'application/%s' % fmt
     body = None
     if data:
         body = Serializer().serialize(data, content_type)
     return create_request(path, body, content_type, method)
    def _do_request(self, method, path, data=None, params=None, action=None):
        content_type = "application/json"
        body = None
        if data is not None:  # empty dict is valid
            body = wsgi.Serializer().serialize(data, content_type)

        req = testlib_api.create_request(path, body, content_type, method, query_string=params)
        res = req.get_response(self._api)
        if res.status_code >= 400:
            raise webexc.HTTPClientError(detail=res.body, code=res.status_code)
        if res.status_code != webexc.HTTPNoContent.code:
            return res.json
Exemplo n.º 7
0
    def _test_unparsable_data(self, fmt):
        LOG.debug("_test_unparsable_data - fmt:%s - START", fmt)

        data = "this is not json or xml"
        method = "POST"
        content_type = "application/%s" % fmt
        tenant_id = self.tenant_id
        path = "/tenants/%(tenant_id)s/networks.%(fmt)s" % locals()
        network_req = testlib.create_request(path, data, content_type, method)
        network_res = network_req.get_response(self.api)
        self.assertEqual(network_res.status_int, 400)

        LOG.debug("_test_unparsable_data - fmt:%s - END", fmt)
Exemplo n.º 8
0
    def _do_request(self, method, path, data=None, params=None, action=None):
        content_type = 'application/json'
        body = None
        if data is not None:  # empty dict is valid
            body = wsgi.Serializer().serialize(data, content_type)

        req = testlib_api.create_request(
            path, body, content_type,
            method, query_string=params)
        res = req.get_response(self._api)
        if res.status_code >= 400:
            raise webexc.HTTPClientError(detail=res.body, code=res.status_code)
        if res.status_code != webexc.HTTPNoContent.code:
            return res.json
Exemplo n.º 9
0
 def test_invalid_version(self):
     req = testlib.create_request('/v99.99/tenants/tenantX/networks',
                                  '',
                                  'application/json')
     response = self.app(req)
     self.assertEquals(response.status_int, 404)
Exemplo n.º 10
0
 def _test_root_responds_with_versions(self, content_type):
     req = testlib.create_request('/', '', content_type)
     response = self.app(req)
     self.assertEquals(response.status_int, 200)
     return response.body
Exemplo n.º 11
0
 def request(self, method, action, body, headers):
     # TODO: remove version prefix from action!
     parts = action.split('/', 2)
     path = '/' + parts[2]
     self._req = testlib_api.create_request(path, body, "application/json",
                                            method)
Exemplo n.º 12
0
 def test_invalid_version(self):
     req = testlib.create_request('/v99.99/tenants/tenantX/networks',
                                  '',
                                  'application/json')
     response = self.app(req)
     self.assertEquals(response.status_int, 404)
Exemplo n.º 13
0
 def _test_root_responds_with_versions(self, content_type):
     req = testlib.create_request('/', '', content_type)
     response = self.app(req)
     self.assertEquals(response.status_int, 200)
     return response.body
Exemplo n.º 14
0
 def request(self, method, action, body, headers):
     # TODO: remove version prefix from action!
     parts = action.split('/', 2)
     path = '/' + parts[2]
     self._req = testlib_api.create_request(path, body, "application/json",
                                            method)
Exemplo n.º 15
0
 def assert_net_not_found(base_path, method, fmt):
     content_type = "application/%s" % fmt
     full_path = "%s.%s" % (base_path, fmt)
     req = testlib.create_request(full_path, None, content_type)
     res = req.get_response(self.api)
     self.assertEqual(res.status_int, self._network_not_found_code)