def test_init(self): x = http.Request('http://foo', method='POST') self.assertEqual(x.url, 'http://foo') self.assertEqual(x.method, 'POST') x = http.Request('x', max_redirects=100) self.assertEqual(x.max_redirects, 100) self.assertIsInstance(x.headers, http.Headers) h = http.Headers() x = http.Request('x', headers=h) self.assertIs(x.headers, h) self.assertIsInstance(x.on_ready, promise)
def test_init(self): x = http.Request('http://foo', method='POST') assert x.url == 'http://foo' assert x.method == 'POST' x = http.Request('x', max_redirects=100) assert x.max_redirects == 100 assert isinstance(x.headers, http.Headers) h = http.Headers() x = http.Request('x', headers=h) assert x.headers is h assert isinstance(x.on_ready, promise)
def test_init(self): req = http.Request('http://foo') r = http.Response(req, 200) self.assertEqual(r.status, 'OK') self.assertEqual(r.effective_url, 'http://foo') r.raise_for_error()
def test_then(self): callback = PromiseMock(name='callback') x = http.Request('http://foo') x.then(callback) x.on_ready(1) callback.assert_called_with(1)
def test_init(self): req = http.Request('http://foo') r = http.Response(req, 200) assert r.status == 'OK' assert r.effective_url == 'http://foo' r.raise_for_error()
def test_raise_for_error(self): req = http.Request('http://foo') r = http.Response(req, 404) self.assertEqual(r.status, 'Not Found') self.assertTrue(r.error) with self.assertRaises(HttpError): r.raise_for_error()
def test_raise_for_error(self): req = http.Request('http://foo') r = http.Response(req, 404) assert r.status == 'Not Found' assert r.error with pytest.raises(HttpError): r.raise_for_error()
def test_perform(self): c = BaseClient(Mock(name='hub')) c.add_request = Mock(name='add_request') c.perform('http://foo') self.assertTrue(c.add_request.called) self.assertIsInstance(c.add_request.call_args[0][0], http.Request) req = http.Request('http://bar') c.perform(req) c.add_request.assert_called_with(req)
def test_get_body(self): req = http.Request('http://foo') req.buffer = BytesIO() req.buffer.write(b'hello') rn = http.Response(req, 200, buffer=None) self.assertIsNone(rn.body) r = http.Response(req, 200, buffer=req.buffer) self.assertIsNone(r._body) self.assertEqual(r.body, b'hello') self.assertEqual(r._body, b'hello') self.assertEqual(r.body, b'hello')
def test_get_body(self): req = http.Request('http://foo') req.buffer = BytesIO() req.buffer.write(b'hello') rn = http.Response(req, 200, buffer=None) assert rn.body is None r = http.Response(req, 200, buffer=req.buffer) assert r._body is None assert r.body == b'hello' assert r._body == b'hello' assert r.body == b'hello'