def test_empty_request(self): app = Microdot() mock_socket.clear_requests() fd = mock_socket.FakeStream(b'\n') mock_socket._requests.append(fd) self._add_shutdown(app) app.run() self.assertTrue(fd.response.startswith(b'HTTP/1.0 400 N/A\r\n')) self.assertIn(b'Content-Length: 11\r\n', fd.response) self.assertIn(b'Content-Type: text/plain\r\n', fd.response) self.assertTrue(fd.response.endswith(b'\r\n\r\nBad request'))
def test_400_handler(self): self._mock() app = Microdot() @app.errorhandler(400) def handle_400(req): return '400' mock_socket.clear_requests() fd = mock_socket.FakeStream(b'\n') mock_socket._requests.append(fd) self._add_shutdown(app) app.run() self.assertTrue(fd.response.startswith(b'HTTP/1.0 200 OK\r\n')) self.assertIn(b'Content-Length: 3\r\n', fd.response) self.assertIn(b'Content-Type: text/plain\r\n', fd.response) self.assertTrue(fd.response.endswith(b'\r\n\r\n400')) self._unmock()