Skip to content

Commit

Permalink
Moved is_json to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
lucagiove committed Feb 12, 2020
1 parent bd9e015 commit 54b85e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/RequestsLibrary/RequestsKeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ def request_should_be_successful(self, response):
"""
self._check_status(None, response, msg=None)


def _common_request(
self,
method,
Expand Down Expand Up @@ -1026,7 +1025,7 @@ def _format_data_according_to_header(self, session, data, headers):
# Merged headers are already case insensitive
headers = utils.merge_headers(session, headers)

if data is not None and headers is not None and 'Content-Type' in headers and not self._is_json(data):
if data is not None and headers is not None and 'Content-Type' in headers and not utils.is_json(data):
if headers['Content-Type'].find("application/json") != -1:
if not isinstance(data, types.GeneratorType):
if str(data).strip():
Expand Down Expand Up @@ -1096,14 +1095,6 @@ def _log_response(method, response):
response.text)


@staticmethod
def _is_json(data):
try:
json.loads(data)
except (TypeError, ValueError):
return False
return True

@staticmethod
def _is_string_type(data):
if PY3 and isinstance(data, str):
Expand Down
8 changes: 8 additions & 0 deletions src/RequestsLibrary/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def merge_headers(session, headers):
return merged_headers


def is_json(data):
try:
json.loads(data)
except (TypeError, ValueError):
return False
return True


def json_pretty_print(content):
"""
Pretty print a JSON object
Expand Down

0 comments on commit 54b85e5

Please sign in to comment.