class Test_wsgi(unittest.TestCase): """ Test case for wsgi """ def setUp(self): controller_data = {'test_param': 'foo'} self.wsgi_app = WSGIApplication() self.wsgi_app.register(_TestController, controller_data) def tearDown(self): pass def test_wsgi_decorator_ok(self): r = self.wsgi_app( { 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test/0123456789abcdef' }, lambda s, _: eq_(s, '200 OK')) eq_(r[0], (b'0123456789abcdef')) def test_wsgi_decorator_ng_path(self): self.wsgi_app({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/' }, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ng_method(self): # XXX: If response code is "405 Method Not Allowed", it is better. self.wsgi_app( { 'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/test/0123456789abcdef' }, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ng_requirements(self): # XXX: If response code is "400 Bad Request", it is better. self.wsgi_app({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test/hogehoge' }, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ok_any_method(self): self.wsgi_app({ 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test' }, lambda s, _: eq_(s, '200 OK')) self.wsgi_app({ 'REQUEST_METHOD': 'POST', 'PATH_INFO': '/test' }, lambda s, _: eq_(s, '200 OK')) self.wsgi_app({ 'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/test' }, lambda s, _: eq_(s, '200 OK')) r = self.wsgi_app({ 'REQUEST_METHOD': 'DELETE', 'PATH_INFO': '/test' }, lambda s, _: eq_(s, '200 OK')) eq_(r[0], b'root')
class Test_wsgi(unittest.TestCase): """ Test case for wsgi """ def setUp(self): controller_data = { 'test_param': 'foo' } self.wsgi_app = WSGIApplication() self.wsgi_app.register(_TestController, controller_data) def tearDown(self): pass def test_wsgi_decorator_ok(self): r = self.wsgi_app({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test/0123456789abcdef'}, lambda s, _: eq_(s, '200 OK')) eq_(r[0], (b'0123456789abcdef')) def test_wsgi_decorator_ng_path(self): self.wsgi_app({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/'}, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ng_method(self): # XXX: If response code is "405 Method Not Allowed", it is better. self.wsgi_app({'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/test/0123456789abcdef'}, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ng_requirements(self): # XXX: If response code is "400 Bad Request", it is better. self.wsgi_app({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test/hogehoge'}, lambda s, _: eq_(s, '404 Not Found')) def test_wsgi_decorator_ok_any_method(self): self.wsgi_app({'REQUEST_METHOD': 'GET', 'PATH_INFO': '/test'}, lambda s, _: eq_(s, '200 OK')) self.wsgi_app({'REQUEST_METHOD': 'POST', 'PATH_INFO': '/test'}, lambda s, _: eq_(s, '200 OK')) self.wsgi_app({'REQUEST_METHOD': 'PUT', 'PATH_INFO': '/test'}, lambda s, _: eq_(s, '200 OK')) r = self.wsgi_app({'REQUEST_METHOD': 'DELETE', 'PATH_INFO': '/test'}, lambda s, _: eq_(s, '200 OK')) eq_(r[0], b'root')