def test_header(self): res = grole.Response(None, 123, 'foo', {'foo': 'bar'}, 'bar') writer = FakeWriter() a_wait(res._write(writer)) for line in writer.data.split(b'\r\n'): if line.startswith(b'bar'): self.assertEqual(line, b'bar 123 foo') elif line.startswith(b'Content-Type'): self.assertEqual(line, b'Content-Type: text/plain') elif line.startswith(b'Content-Length'): self.assertEqual(line, b'Content-Length: 0') elif line.startswith(b'foo'): self.assertEqual(line, b'foo: bar') elif line.startswith(b'Server'): self.assertEqual(line, b'Server: grole/' + grole.__version__.encode()) else: if line != b'': self.fail('Extra data: ' + line.decode())
def test_file(self): res = grole.Response(grole.ResponseFile('foo')) self.assertIsInstance(res.data, grole.ResponseFile)
def test_string(self): res = grole.Response('foo') self.assertIsInstance(res.data, grole.ResponseString)
def test_json(self): res = grole.Response(['foo']) self.assertIsInstance(res.data, grole.ResponseJSON)
def test_bytes(self): res = grole.Response(b'foo') self.assertIsInstance(res.data, grole.ResponseBody)
def test_json(self): res = grole.Response({'foo': 'bar'}) self.assertTrue(isinstance(res.data, grole.ResponseJSON)) self.assertEqual(res.data._data, b'{"foo": "bar"}') self.assertEqual(res.data._headers['Content-Type'], 'application/json')
def test_str(self): res = grole.Response('foo') self.assertTrue(isinstance(res.data, grole.ResponseString)) self.assertEqual(res.data._data, b'foo') self.assertEqual(res.data._headers['Content-Type'], 'text/html')
def test_bytes(self): res = grole.Response(b'foo') self.assertTrue(isinstance(res.data, grole.ResponseBody)) self.assertEqual(res.data._data, b'foo') self.assertEqual(res.data._headers['Content-Type'], 'text/plain')
def test_empty(self): res = grole.Response() self.assertTrue(isinstance(res.data, grole.ResponseBody))