From 4857fd423d2344b9e5684f9e733f269cdff45da7 Mon Sep 17 00:00:00 2001 From: Jan Verhoeven Date: Mon, 9 Jun 2014 20:31:05 +0200 Subject: [PATCH 1/3] Added PATCH as main keyword Added a simply echo server to the mock server (copied from POST statement). Added a test in simple.txt test framework. Moved the old 'Custom HTTP' verb test to use OPTIONS instead of PATCH. --- src/HttpLibrary/__init__.py | 19 +++++++++++++++++++ tests/http/mockserver.py | 27 +++++++++++++++++++++++++-- tests/http/simple.txt | 10 ++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index ae11328..1b970af 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -267,6 +267,25 @@ def PUT(self, url): self.context.request_headers, **kwargs) ) + def PATCH(self, url): + """ + Issues an HTTP PATCH request. + + `url` is the URL relative to the server root, e.g. '/_utils/config.html' + """ + path = self._path_from_url_or_path(url) + kwargs = {} + if 'Content-Type' in self.context.request_headers: + kwargs[ + 'content_type'] = self.context.request_headers['Content-Type'] + self.context.pre_process_request() + logger.debug("Performing PATCH request on %s://%s%s" % ( + self.context._scheme, self.app.host, url)) + self.context.post_process_request( + self.app.patch(path, self.context.request_body or {}, + self.context.request_headers, **kwargs) + ) + def DELETE(self, url): """ Issues a HTTP DELETE request. diff --git a/tests/http/mockserver.py b/tests/http/mockserver.py index fe2bb8e..bff6ca7 100755 --- a/tests/http/mockserver.py +++ b/tests/http/mockserver.py @@ -22,9 +22,32 @@ def do_DELETE(self): self.finish() def do_PATCH(self): - self.send_response(200, "Patch request ok") + if self.path == '/echo': + data = self.rfile.read(int(self.headers['Content-Length'])) + self.rfile.close() + self.send_response(200, "OK") + self.send_header('Content-Type', 'text/plain; charset=utf-8') + self.end_headers() + self.wfile.write(data) + self.finish() + elif self.path == '/content_type': + self.send_response(200, "OK") + self.wfile.write(self.rfile.read) + self.end_headers() + self.wfile.write(self.headers['Content-Type']) + self.finish() + elif self.path == '/kill': + global server + self.send_response(201, "Killing myself") + server.socket.close() + sys.exit(0) + else: + self.send_error(500) + + def do_OPTIONS(self): + self.send_response(200, "Options request ok") self.end_headers() - self.wfile.write("Got a patch request") + self.wfile.write("Got an OPTIONS request") self.finish() def do_GET(self): diff --git a/tests/http/simple.txt b/tests/http/simple.txt index 827950a..66571d5 100644 --- a/tests/http/simple.txt +++ b/tests/http/simple.txt @@ -102,8 +102,8 @@ Next Request Should Have Status Code w/ Status Line FAIL ... GET /418 HTTP Request with custom HTTP verb should work - HTTP Request PATCH /patch - Response Body Should Contain Got a patch request + HTTP Request OPTIONS /options + Response Body Should Contain Got an OPTIONS request Response Should Have Header OK GET /302 @@ -174,6 +174,12 @@ PUT with two word request body PUT /echo Response Body Should Contain Tooot Tooooot +PATCH with two word request body + Set Request Body Tooot Tooooot + Set Request Header Content-Type text/plain + PATCH /echo + Response Body Should Contain Tooot Tooooot + Get Response Status GET /200 ${status}= Get Response Status From 6a89575e2c5f39b0bebcb9c59e70a2615c80aa29 Mon Sep 17 00:00:00 2001 From: Jan Verhoeven Date: Mon, 13 Oct 2014 11:25:09 +0200 Subject: [PATCH 2/3] GET command takes a string from a string, effectively not allowing to take use a variable as a parameter for the GET command. Remove the quotes if needed. --- src/HttpLibrary/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 1b970af..994fba7 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -138,6 +138,9 @@ def response(self): def _path_from_url_or_path(self, url_or_path): + if url_or_path.startswith("\"") and url_or_path.endswith("\""): + url_or_path = url_or_path[1:-1] + if url_or_path.startswith("/"): return url_or_path From 5046879536ffc48b49b0c59508cbb68e3e0d8b02 Mon Sep 17 00:00:00 2001 From: Yan Bilik Date: Wed, 22 Oct 2014 11:02:17 +0200 Subject: [PATCH 3/3] Added OPTIONS as main keyword --- src/HttpLibrary/__init__.py | 14 ++++++++++++++ tests/http/simple.txt | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 994fba7..82d7f84 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -303,6 +303,20 @@ def DELETE(self, url): self.app.delete(path, {}, self.context.request_headers) ) + def OPTIONS(self, url): + """ + Issues a HTTP OPTIONS request. + + `url` is the URL relative to the server root, e.g. '/_utils/config.html' + """ + path = self._path_from_url_or_path(url) + self.context.pre_process_request() + logger.debug("Performing OPTIONS request on %s://%s%s" % ( + self.context._scheme, self.app.host, path,)) + self.context.post_process_request( + self.app.options(path, self.context.request_headers) + ) + def follow_response(self): """ Follows a HTTP redirect if the previous response status code was a 301 or 302. diff --git a/tests/http/simple.txt b/tests/http/simple.txt index 66571d5..3c97e6b 100644 --- a/tests/http/simple.txt +++ b/tests/http/simple.txt @@ -180,6 +180,10 @@ PATCH with two word request body PATCH /echo Response Body Should Contain Tooot Tooooot +Simple OPTIONS request + OPTIONS /options + Response Body Should Contain Got an OPTIONS request + Get Response Status GET /200 ${status}= Get Response Status