Example #1
0
 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())
Example #2
0
 def test_file(self):
     res = grole.Response(grole.ResponseFile('foo'))
     self.assertIsInstance(res.data, grole.ResponseFile)
Example #3
0
 def test_string(self):
     res = grole.Response('foo')
     self.assertIsInstance(res.data, grole.ResponseString)
Example #4
0
 def test_json(self):
     res = grole.Response(['foo'])
     self.assertIsInstance(res.data, grole.ResponseJSON)
Example #5
0
 def test_bytes(self):
     res = grole.Response(b'foo')
     self.assertIsInstance(res.data, grole.ResponseBody)
Example #6
0
 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')
Example #7
0
 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')
Example #8
0
 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')
Example #9
0
 def test_empty(self):
     res = grole.Response()
     self.assertTrue(isinstance(res.data, grole.ResponseBody))