def test_reqeust(self): def my_request(environ, start_response): assert isinstance(environ, dict) assert hasattr(start_response, "__call__") return ["ok"] req = Request(my_request) self.assertEqual(req.wsgi_callback, my_request) self.assertEqual(req.name, "my_request") self.assertEqual(req.urls, ((None, "/my_request"),)) self.assertEqual(req.doc, None) req.onload(None) # called by application self.assertEqual(req({}, lambda status, headers: None), ["ok"])
def test_request_none(self): try: Request() except AssertionError as exc: self.assertEqual(str(exc), "must specify either wsgi_callback and/or name") else: self.fail() req = Request(name="my_request") self.assertEqual(req.wsgi_callback, None) self.assertEqual(req.name, "my_request") self.assertEqual(req.urls, ((None, "/my_request"),)) self.assertEqual(req.doc, None) req.onload(None) # called by application try: req({}, lambda status, headers: None) except AssertionError as exc: self.assertEqual(str(exc), "must specify wsgi_callback when using Request directly") else: self.fail()