add parse_response_object

This commit is contained in:
debugtalk
2017-06-20 20:06:36 +08:00
parent 898e0f27fa
commit 278aaff290
2 changed files with 18 additions and 2 deletions

View File

@@ -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
}

View File

@@ -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)