From ade400c75897811b2800d53a9d0a5122296e1977 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Wed, 22 Jun 2016 09:51:10 +0300 Subject: [PATCH 01/14] 1. Added explicit OPTIONS method --- setup.py | 9 ++++----- src/HttpLibrary/__init__.py | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 42ef4c1..9d7ee11 100644 --- a/setup.py +++ b/setup.py @@ -12,19 +12,18 @@ setup( name='robotframework-httplibrary', - version="0.4.2", + version="0.4.3", description='Robot Framework keywords for HTTP requests', long_description=long_description, author='Filip Noetzel', author_email='filip+rfhttplibrary@j03.de', - url='https://github.com/peritus/robotframework-httplibrary', + url='https://github.com/vikulin/robotframework-httplibrary', license='Beerware', - keywords='robotframework testing testautomation web http webtest', + keywords='robotframework testing test automation web http webtest', platforms='any', zip_safe=False, classifiers=CLASSIFIERS.splitlines(), package_dir={'': 'src'}, - install_requires=['robotframework', 'webtest>=2.0', 'jsonpatch', - 'jsonpointer'], + install_requires=['robotframework', 'webtest>=2.0', 'jsonpatch', 'jsonpointer'], packages=['HttpLibrary'] ) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index ae11328..3896d9d 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -35,7 +35,7 @@ class HTTP: Pointer, go to http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00. """ - ROBOT_LIBRARY_VERSION = "0.4.2" + ROBOT_LIBRARY_VERSION = "0.4.3" class Context(object): def __init__(self, http, host=None, scheme='http'): @@ -281,6 +281,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. From 1ece59e1488725f87a8306911177054ad278e191 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Wed, 22 Jun 2016 09:54:24 +0300 Subject: [PATCH 02/14] 1. README update --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index 42a10f3..45e07e9 100644 --- a/README.rst +++ b/README.rst @@ -76,6 +76,11 @@ Changelog **v0.4.2** +- Fix: Added explicit OPTIONS method + https://github.com/peritus/robotframework-httplibrary/issues/30 + +**v0.4.2** + - Don't enforce ASCII when converting to JSON (so chinese characters are printed as such and not escaped like \uXXXX). Thanks Terry Yin! From a246781470483f4d34412d997a54093642e86f9a Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Wed, 22 Jun 2016 09:56:02 +0300 Subject: [PATCH 03/14] 1. url rollback --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 9d7ee11..f22dcda 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ long_description=long_description, author='Filip Noetzel', author_email='filip+rfhttplibrary@j03.de', - url='https://github.com/vikulin/robotframework-httplibrary', + url='https://github.com/peritus/robotframework-httplibrary', license='Beerware', keywords='robotframework testing test automation web http webtest', platforms='any', From 6d2aafa5ded06d1975ee2edf020088b602ba2393 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Wed, 22 Jun 2016 10:06:47 +0300 Subject: [PATCH 04/14] 1. Added git ignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c88edd9..9c541d8 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ output.xml parts/ report.html src/robotframework_httplibrary.egg-info/ +/build/ From 5b6537c48e3253b688a958cdbec83cf254a0234c Mon Sep 17 00:00:00 2001 From: Mohammad Asad Mohammad Date: Wed, 20 Jul 2016 10:40:12 -0700 Subject: [PATCH 05/14] fixed load_json (#1) fixed set_json_value method when json_value has a string --- src/HttpLibrary/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 3896d9d..c90eaef 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -621,10 +621,18 @@ def set_json_value(self, json_string, json_pointer, json_value): | ${result}= | Set Json Value | {"foo": {"bar": [1,2,3]}} | /foo | 12 | | Should Be Equal | ${result} | {"foo": 12} | | | """ + try: + loaded_json = load_json(json_value) + except ValueError, e: + if isinstance(json_value, basestring): + loaded_json = json_value + else: + raise ValueError("Could not parse '%s' as JSON: %s" % (json_value, e)) + return jsonpatch.apply_patch(json_string, [{ 'op': 'add', 'path': json_pointer, - 'value': load_json(json_value) + 'value': loaded_json }]) @_with_json From 6a07e94ea5aa01cd485827691f7fa19a67a5a1a4 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Wed, 20 Jul 2016 20:51:16 +0300 Subject: [PATCH 06/14] 1. Fix: Set Json Value keyword. https://github.com/vikulin/robotframework-httplibrary/pull/1 --- README.rst | 6 +++++- setup.py | 2 +- src/HttpLibrary/__init__.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 45e07e9..42e5832 100644 --- a/README.rst +++ b/README.rst @@ -74,7 +74,11 @@ mostly a wrapper supposed to have a nice API)! Changelog --------- -**v0.4.2** +**v0.4.4** +- Fix: Set Json Value keyword. + https://github.com/vikulin/robotframework-httplibrary/pull/1 + +**v0.4.3** - Fix: Added explicit OPTIONS method https://github.com/peritus/robotframework-httplibrary/issues/30 diff --git a/setup.py b/setup.py index f22dcda..907d05f 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='robotframework-httplibrary', - version="0.4.3", + version="0.4.4", description='Robot Framework keywords for HTTP requests', long_description=long_description, author='Filip Noetzel', diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index c90eaef..81a5fb0 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -35,7 +35,7 @@ class HTTP: Pointer, go to http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00. """ - ROBOT_LIBRARY_VERSION = "0.4.3" + ROBOT_LIBRARY_VERSION = "0.4.4" class Context(object): def __init__(self, http, host=None, scheme='http'): From dc7dddd3501d2dd808d8dce0d093041131cffada Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Thu, 15 Sep 2016 09:31:53 +0300 Subject: [PATCH 07/14] 1. Keep orinigan data type returned by 'Get Json Value' keyword --- README.rst | 5 ++++- setup.py | 2 +- src/HttpLibrary/__init__.py | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 42e5832..40386c6 100644 --- a/README.rst +++ b/README.rst @@ -74,8 +74,11 @@ mostly a wrapper supposed to have a nice API)! Changelog --------- +**v0.4.5** +- Fix: Keep original data type returned by 'Get Json Value' keyword + **v0.4.4** -- Fix: Set Json Value keyword. +- Fix: 'Set Json Value' keyword. https://github.com/vikulin/robotframework-httplibrary/pull/1 **v0.4.3** diff --git a/setup.py b/setup.py index 907d05f..bfe10c8 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='robotframework-httplibrary', - version="0.4.4", + version="0.4.5", description='Robot Framework keywords for HTTP requests', long_description=long_description, author='Filip Noetzel', diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 81a5fb0..cd027a9 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -24,6 +24,12 @@ def wrapper(self, json_string, *args, **kwargs): f(self, load_json(json_string), *args, **kwargs), ensure_ascii=False) return wrapper +def _with_native_json(f): + @wraps(f) + def wrapper(self, json_string, *args, **kwargs): + return f(self, load_json(json_string), *args, **kwargs) + return wrapper + class HTTP: """ @@ -566,7 +572,7 @@ def stringify_json(self, data): raise ValueError( "Could not stringify '%r' to JSON: %s" % (data, e)) - @_with_json + @_with_native_json def get_json_value(self, json_string, json_pointer): """ Get the target node of the JSON document `json_string` specified by `json_pointer`. From 17096bfecb122b5ff7aa699a79b2bf9adef9de9c Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Thu, 15 Sep 2016 09:54:05 +0300 Subject: [PATCH 08/14] 1. Split JSON data and string keywords --- src/HttpLibrary/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index cd027a9..efe36dd 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -533,7 +533,16 @@ def log_response_status(self, log_level='INFO'): # json - def should_be_valid_json(self, json_string): + def should_be_valid_json(self, json_data): + """ + Attempts to parse `json_data` as JSON. Fails, if `json_data` is invalid JSON. + + Example: + | Should Be Valid Json | {"foo": "bar"} | + """ + self.parse_json(json.dumps(json_data, ensure_ascii=False)) + + def should_be_valid_json_string(self, json_string): """ Attempts to parse `json_string` as JSON. Fails, if `json_string` is invalid JSON. From 7e4cdd368d6ad6671217f9c8a7428c943714602a Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Thu, 15 Sep 2016 10:22:46 +0300 Subject: [PATCH 09/14] 1. Added stringify parameter --- src/HttpLibrary/__init__.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index efe36dd..0f350a6 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -24,12 +24,6 @@ def wrapper(self, json_string, *args, **kwargs): f(self, load_json(json_string), *args, **kwargs), ensure_ascii=False) return wrapper -def _with_native_json(f): - @wraps(f) - def wrapper(self, json_string, *args, **kwargs): - return f(self, load_json(json_string), *args, **kwargs) - return wrapper - class HTTP: """ @@ -533,16 +527,7 @@ def log_response_status(self, log_level='INFO'): # json - def should_be_valid_json(self, json_data): - """ - Attempts to parse `json_data` as JSON. Fails, if `json_data` is invalid JSON. - - Example: - | Should Be Valid Json | {"foo": "bar"} | - """ - self.parse_json(json.dumps(json_data, ensure_ascii=False)) - - def should_be_valid_json_string(self, json_string): + def should_be_valid_json(self, json_string): """ Attempts to parse `json_string` as JSON. Fails, if `json_string` is invalid JSON. @@ -581,8 +566,7 @@ def stringify_json(self, data): raise ValueError( "Could not stringify '%r' to JSON: %s" % (data, e)) - @_with_native_json - def get_json_value(self, json_string, json_pointer): + def get_json_value(self, json_string, json_pointer, stringify=True): """ Get the target node of the JSON document `json_string` specified by `json_pointer`. @@ -590,7 +574,10 @@ def get_json_value(self, json_string, json_pointer): | ${result}= | Get Json Value | {"foo": {"bar": [1,2,3]}} | /foo/bar | | Should Be Equal | ${result} | [1, 2, 3] | | """ - return jsonpointer.resolve_pointer(json_string, json_pointer) + if stringify: + return json.dumps(jsonpointer.resolve_pointer(load_json(json_string)), ensure_ascii=False) + else: + return jsonpointer.resolve_pointer(load_json(json_string)) def json_value_should_equal(self, json_string, json_pointer, expected_value): """ From 41de769260f44403089434fbbca21d12cf526f44 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Thu, 15 Sep 2016 10:30:17 +0300 Subject: [PATCH 10/14] 1. json_pointer fix --- src/HttpLibrary/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 0f350a6..78b5b17 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -575,9 +575,9 @@ def get_json_value(self, json_string, json_pointer, stringify=True): | Should Be Equal | ${result} | [1, 2, 3] | | """ if stringify: - return json.dumps(jsonpointer.resolve_pointer(load_json(json_string)), ensure_ascii=False) + return json.dumps(jsonpointer.resolve_pointer(load_json(json_string), json_pointer), ensure_ascii=False) else: - return jsonpointer.resolve_pointer(load_json(json_string)) + return jsonpointer.resolve_pointer(load_json(json_string), json_pointer) def json_value_should_equal(self, json_string, json_pointer, expected_value): """ From 337ec7e095ba0992075e257e8ebe2637cbb05f64 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Fri, 16 Sep 2016 16:02:50 +0300 Subject: [PATCH 11/14] 1. bumped up RF version --- src/HttpLibrary/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 78b5b17..87827f6 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -35,7 +35,7 @@ class HTTP: Pointer, go to http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00. """ - ROBOT_LIBRARY_VERSION = "0.4.4" + ROBOT_LIBRARY_VERSION = "0.4.5" class Context(object): def __init__(self, http, host=None, scheme='http'): From d196d524966c293a12fd1971b65b2655bdfd1683 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Tue, 25 Oct 2016 12:57:49 +0300 Subject: [PATCH 12/14] **v0.4.6** - Improvement: Added stringify parameter to json_value_should_equal and json_value_should_not_equal methods --- README.rst | 3 +++ setup.py | 8 ++++---- src/HttpLibrary/__init__.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 40386c6..783d11c 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,9 @@ mostly a wrapper supposed to have a nice API)! Changelog --------- +**v0.4.6** +- Improvement: Added stringify parameter to json_value_should_equal and json_value_should_not_equal methods + **v0.4.5** - Fix: Keep original data type returned by 'Get Json Value' keyword diff --git a/setup.py b/setup.py index bfe10c8..4c161d4 100644 --- a/setup.py +++ b/setup.py @@ -12,12 +12,12 @@ setup( name='robotframework-httplibrary', - version="0.4.5", + version="0.4.6", description='Robot Framework keywords for HTTP requests', long_description=long_description, - author='Filip Noetzel', - author_email='filip+rfhttplibrary@j03.de', - url='https://github.com/peritus/robotframework-httplibrary', + author='Vadym Vikulin', + author_email='vadym.vikulin@gmail.com', + url='https://github.com/vikulin/robotframework-httplibrary', license='Beerware', keywords='robotframework testing test automation web http webtest', platforms='any', diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 87827f6..3721df9 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -35,7 +35,7 @@ class HTTP: Pointer, go to http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00. """ - ROBOT_LIBRARY_VERSION = "0.4.5" + ROBOT_LIBRARY_VERSION = "0.4.6" class Context(object): def __init__(self, http, host=None, scheme='http'): @@ -569,7 +569,7 @@ def stringify_json(self, data): def get_json_value(self, json_string, json_pointer, stringify=True): """ Get the target node of the JSON document `json_string` specified by `json_pointer`. - + `stringify` specifies whether JSON data should be transformed to string before assertion. Example: | ${result}= | Get Json Value | {"foo": {"bar": [1,2,3]}} | /foo/bar | | Should Be Equal | ${result} | [1, 2, 3] | | @@ -579,33 +579,33 @@ def get_json_value(self, json_string, json_pointer, stringify=True): else: return jsonpointer.resolve_pointer(load_json(json_string), json_pointer) - def json_value_should_equal(self, json_string, json_pointer, expected_value): + def json_value_should_equal(self, json_string, json_pointer, expected_value, stringify=True): """ Fails if the value of the target node of the JSON document `json_string` specified by JSON Pointer `json_pointer` is not `expected_value`. + `stringify` specifies whether JSON data should be transformed to string before assertion. Example: | Set Test Variable | ${doc} | {"foo": {"bar": [1,2,3]}} | | | Json Value Should Equal | ${doc} | /foo/bar | "[1, 2, 3]" | """ - - got = self.get_json_value(json_string, json_pointer) + got = self.get_json_value(json_string, json_pointer, stringify) assert got == expected_value, \ 'JSON value "%s" does not equal "%s", but should have.' % ( got, expected_value) - def json_value_should_not_equal(self, json_string, json_pointer, expected_value): + def json_value_should_not_equal(self, json_string, json_pointer, expected_value, stringify=True): """ Fails if the value of the target node of the JSON document `json_string` specified by JSON Pointer `json_pointer` is `expected_value`. + `stringify` specifies whether JSON data should be transformed to string before assertion. Example: | Set Test Variable | ${doc} | {"foo": {"bar": [1,2,3]}} | | | Json Value Should Not Equal | ${doc} | /foo/bar | "[1, 2, 3]" | """ - - got = self.get_json_value(json_string, json_pointer) + got = self.get_json_value(json_string, json_pointer, stringify) message = 'JSON value "%s" does not equal "%s"' % (got, expected_value) From dc1effcb5f6e41eadaf1089a1b6b7fd126a0e8ac Mon Sep 17 00:00:00 2001 From: Vadym Date: Mon, 25 Jun 2018 17:06:28 +0300 Subject: [PATCH 13/14] 1. added PATCH method support --- README.rst | 3 +++ setup.py | 2 +- src/HttpLibrary/__init__.py | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 783d11c..f961b54 100644 --- a/README.rst +++ b/README.rst @@ -74,6 +74,9 @@ mostly a wrapper supposed to have a nice API)! Changelog --------- +**v0.4.7** +- Improvement: Added PATCH HTTP method + **v0.4.6** - Improvement: Added stringify parameter to json_value_should_equal and json_value_should_not_equal methods diff --git a/setup.py b/setup.py index 4c161d4..b688b97 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name='robotframework-httplibrary', - version="0.4.6", + version="0.4.7", description='Robot Framework keywords for HTTP requests', long_description=long_description, author='Vadym Vikulin', diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 3721df9..119ad31 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -35,7 +35,7 @@ class HTTP: Pointer, go to http://tools.ietf.org/html/draft-pbryan-zyp-json-pointer-00. """ - ROBOT_LIBRARY_VERSION = "0.4.6" + ROBOT_LIBRARY_VERSION = "0.4.7" class Context(object): def __init__(self, http, host=None, scheme='http'): @@ -295,6 +295,24 @@ def OPTIONS(self, url): self.app.options(path, self.context.request_headers) ) + def PATCH(self, url): + """ + Issues a 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 follow_response(self): """ Follows a HTTP redirect if the previous response status code was a 301 or 302. From 4bb1f9d48a0bbce53478b555728085f9309509a2 Mon Sep 17 00:00:00 2001 From: Vadym Date: Mon, 25 Jun 2018 17:41:26 +0300 Subject: [PATCH 14/14] 1. bracket fix --- src/HttpLibrary/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 119ad31..abaead8 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -312,6 +312,7 @@ def PATCH(self, url): self.context.post_process_request( self.app.patch(path, self.context.request_body or {}, self.context.request_headers, **kwargs) + ) def follow_response(self): """