From 113fc5b29e9b938f50d6c68a96dfe907b0983739 Mon Sep 17 00:00:00 2001 From: Matt Pistella Date: Mon, 25 Jan 2016 14:36:57 -0600 Subject: [PATCH 1/2] Added keyword response_header_should_contain Created keyword to check if a response header contains a certain value --- src/HttpLibrary/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index ae11328..6bd9f16 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -410,6 +410,20 @@ def response_header_should_not_equal(self, header_name, not_expected): 'Response header "%s" was "%s" but should not have been.' % ( header_name, actual) + def response_header_should_contain(self, header_name, should_contain): + """ + Fails if the value of response header `header_name` does not contain + `should_contain`. Also fails if the last response does not have a + `header_name` header. + """ + self.response_should_have_header(header_name) + actual = self.response.headers[header_name] + logger.debug('Testing whether "%s" contains "%s".' % ( + actual, should_contain)) + assert should_contain in actual, \ + 'Response header "%s" s value of "%s" should have contained "%s", but did not.' % ( + header_name, actual, should_contain) + def log_response_headers(self, log_level='INFO'): """ Logs the response headers, line by line. From 4ad28a6ef3ea215b440b3a78c97373cac5c9ebb9 Mon Sep 17 00:00:00 2001 From: Matt Pistella Date: Thu, 28 Jan 2016 13:05:51 -0600 Subject: [PATCH 2/2] added minify json keyword --- src/HttpLibrary/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index 6bd9f16..c081a59 100644 --- a/src/HttpLibrary/__init__.py +++ b/src/HttpLibrary/__init__.py @@ -565,6 +565,23 @@ def stringify_json(self, data): except ValueError, e: raise ValueError( "Could not stringify '%r' to JSON: %s" % (data, e)) + + def minify_json(self, data): + """ + Converts JSON string to a minified JSON String + + Example: + | ${data} = | Get Response Body| + | ${json_string}= | Minify JSON | ${data} | + + `data` is the json string to convert to json + """ + + try: + return json.dumps(data, separators=(',',':')) + except ValueError, e: + raise ValueError( + "Could not minify '%r' to JSON: %s" % (data, e)) @_with_json def get_json_value(self, json_string, json_pointer):