Add more tests

This commit is contained in:
Unrud 2020-09-14 18:46:46 +02:00
parent d3bb19800c
commit 80e8750c8a
4 changed files with 8 additions and 7 deletions

View File

@ -26,5 +26,4 @@ class ApplicationPostMixin:
"""Manage POST request.""" """Manage POST request."""
if path == "/.web" or path.startswith("/.web/"): if path == "/.web" or path.startswith("/.web/"):
return self._web.post(environ, base_prefix, path, user) return self._web.post(environ, base_prefix, path, user)
return httputils.METHOD_NOT_ALLOWED return httputils.METHOD_NOT_ALLOWED

View File

@ -104,8 +104,8 @@ class BaseTest:
self._check_status(status, 200, check) self._check_status(status, 200, check)
return status, answer return status, answer
def post(self, path, check=True, **args): def post(self, path, data=None, check=True, **args):
status, _, answer = self.request("POST", path, **args) status, _, answer = self.request("POST", path, data, **args)
self._check_status(status, 200, check) self._check_status(status, 200, check)
return status, answer return status, answer

View File

@ -29,4 +29,5 @@ class Web(web.BaseWeb):
return client.OK, {"Content-Type": "text/plain"}, "custom" return client.OK, {"Content-Type": "text/plain"}, "custom"
def post(self, environ, base_prefix, path, user): def post(self, environ, base_prefix, path, user):
return client.OK, {"Content-Type": "text/plain"}, "custom post" answer = "echo:" + environ["wsgi.input"].read().decode()
return client.OK, {"Content-Type": "text/plain"}, answer

View File

@ -48,6 +48,7 @@ class TestBaseWebRequests(BaseTest):
assert headers.get("Location") == ".web/" assert headers.get("Location") == ".web/"
_, answer = self.get("/.web/") _, answer = self.get("/.web/")
assert answer assert answer
self.post("/.web", check=405)
def test_none(self): def test_none(self):
self.configuration.update({"web": {"type": "none"}}, "test") self.configuration.update({"web": {"type": "none"}}, "test")
@ -55,6 +56,7 @@ class TestBaseWebRequests(BaseTest):
_, answer = self.get("/.web") _, answer = self.get("/.web")
assert answer assert answer
self.get("/.web/", check=404) self.get("/.web/", check=404)
self.post("/.web", check=405)
def test_custom(self): def test_custom(self):
"""Custom web plugin.""" """Custom web plugin."""
@ -63,6 +65,5 @@ class TestBaseWebRequests(BaseTest):
self.application = Application(self.configuration) self.application = Application(self.configuration)
_, answer = self.get("/.web") _, answer = self.get("/.web")
assert answer == "custom" assert answer == "custom"
_, answer = self.post("/.web", "body content")
_, answer = self.post("/.web") assert answer == "echo:body content"
assert answer == "custom post"