diff --git a/ate/utils.py b/ate/utils.py index e5ebb75c..e10a2586 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -20,3 +20,10 @@ def load_testcases(testcase_file_path): else: # '' or other suffix raise ParamsError("Bad testcase file name!") + +def parse_response_object(resp_obj): + return { + 'status_code': resp_obj.status_code, + 'headers': resp_obj.headers, + 'content': resp_obj.content + } diff --git a/test/test_utils.py b/test/test_utils.py index e87007e5..0a87197b 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -1,9 +1,10 @@ import os -import unittest +import requests from ate import utils from ate import exception +from .base import ApiServerUnittest -class TestUtils(unittest.TestCase): +class TestUtils(ApiServerUnittest): def test_load_testcases_bad_filepath(self): testcase_file_path = os.path.join(os.getcwd(), 'test/data/demo') @@ -29,3 +30,11 @@ class TestUtils(unittest.TestCase): self.assertIn('response', testcases[0]) self.assertIn('url', testcases[0]['request']) self.assertIn('method', testcases[0]['request']) + + def test_parse_response_object(self): + url = "http://127.0.0.1:5000/api/users" + resp_obj = requests.get(url) + parse_result = utils.parse_response_object(resp_obj) + self.assertIn('status_code', parse_result) + self.assertIn('headers', parse_result) + self.assertIn('content', parse_result)