diff --git a/src/HttpLibrary/__init__.py b/src/HttpLibrary/__init__.py index ae11328..c081a59 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. @@ -551,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):