def test_standard_responder_with_mount(self, request): responder = OpenStackResponder('/mount/point', 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'POST' req.relative_uri = '/mount/point/path/to/resource' responder.on_get(req, resp) request.assert_called_with(req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=ANY, headers=req.headers, stream=True)
def test_standard_responder_with_mount(self, request): responder = OpenStackResponder('/mount/point', 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'POST' req.relative_uri = '/mount/point/path/to/resource' responder.on_get(req, resp) request.assert_called_with( req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=ANY, headers=req.headers, stream=True)
def test_standard_responder_post(self, request): request.return_value = make_response(body='TEST BODY') responder = OpenStackResponder(None, 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'POST' req.relative_uri = '/path/to/resource' responder.on_get(req, resp) request.assert_called_with(req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=ANY, headers=req.headers, stream=True) self.assertEqual(resp.status, 200) self.assertEqual(resp.content_type, 'application/json') self.assertEqual(resp.stream_len, '10') resp.set_headers.assert_called_with({}) self.assertEqual(resp.stream.read(), 'TEST BODY')
def test_standard_responder_plain_text_hack(self, request): request.return_value = make_response(content_type='text/html') responder = OpenStackResponder(None, 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'GET' req.relative_uri = '/path/to/resource' responder.on_get(req, resp) request.assert_called_with(req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=None, headers=req.headers, stream=True) self.assertEqual(resp.status, 200) self.assertEqual(resp.content_type, 'text/plain; charset=UTF-8') self.assertEqual(resp.stream_len, '0') resp.set_headers.assert_called_with({}) self.assertEqual(resp.stream.read(), '')
def test_standard_responder_post(self, request): request.return_value = make_response(body='TEST BODY') responder = OpenStackResponder(None, 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'POST' req.relative_uri = '/path/to/resource' responder.on_get(req, resp) request.assert_called_with( req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=ANY, headers=req.headers, stream=True) self.assertEquals(resp.status, 200) self.assertEquals(resp.content_type, 'application/json') self.assertEquals(resp.stream_len, '10') resp.set_headers.assert_called_with({}) self.assertEquals(resp.stream.read(), 'TEST BODY')
def test_standard_responder_plain_text_hack(self, request): request.return_value = make_response(content_type='text/html') responder = OpenStackResponder(None, 'http://127.0.0.1:1234/v2') req, resp = MagicMock(), MagicMock() req.method = 'GET' req.relative_uri = '/path/to/resource' responder.on_get(req, resp) request.assert_called_with( req.method, 'http://127.0.0.1:1234/v2/path/to/resource', data=None, headers=req.headers, stream=True) self.assertEquals(resp.status, 200) self.assertEquals(resp.content_type, 'text/plain; charset=UTF-8') self.assertEquals(resp.stream_len, '0') resp.set_headers.assert_called_with({}) self.assertEquals(resp.stream.read(), '')
def test_init(self): responder = OpenStackResponder('/mount-point', 'http://127.0.0.1:1234/v2') self.assertEqual(responder.mount, '/mount-point') self.assertEqual(responder.endpoint, 'http://127.0.0.1:1234/v2')