extract_response when initialize ResponseObject

This commit is contained in:
debugtalk
2017-06-28 23:35:56 +08:00
parent 207998a2f5
commit 997e9d642b
3 changed files with 9 additions and 11 deletions

View File

@@ -3,11 +3,14 @@ from ate import utils, exception
class ResponseObject(object):
def __init__(self, resp_obj):
def __init__(self, resp_obj, context=None):
""" initialize with a requests.Response object
@param (requests.Response instance) resp_obj
@param (ate.context.Context instance) context
"""
self.resp_obj = resp_obj
if context:
self.extract_response(context)
def parsed_body(self):
try:

View File

@@ -105,8 +105,7 @@ class TestRunner(object):
resp = self.client.request(url=url, method=method, **req_kwargs)
resp_obj = response.ResponseObject(resp)
resp_obj.extract_response(self.context)
resp_obj = response.ResponseObject(resp, self.context)
return resp_obj.validate(testcase['response'])
def run_testset(self, testset):

View File

@@ -255,8 +255,7 @@ class TestResponse(ApiServerUnittest):
test_context = context.Context()
test_context.bind_extractors(extract_binds)
resp_obj = response.ResponseObject(resp)
resp_obj.extract_response(test_context)
response.ResponseObject(resp, test_context)
extract_binds_dict = test_context.extractors
self.assertEqual(
@@ -312,10 +311,9 @@ class TestResponse(ApiServerUnittest):
test_context = context.Context()
test_context.bind_extractors(extract_binds)
resp_obj = response.ResponseObject(resp)
with self.assertRaises(exception.ParamsError):
resp_obj.extract_response(test_context)
response.ResponseObject(resp, test_context)
extract_binds = {
"resp_content_list_index_error": "content.person.cities.3"
@@ -323,10 +321,9 @@ class TestResponse(ApiServerUnittest):
test_context = context.Context()
test_context.bind_extractors(extract_binds)
resp_obj = response.ResponseObject(resp)
with self.assertRaises(exception.ParamsError):
resp_obj.extract_response(test_context)
response.ResponseObject(resp, test_context)
def test_extract_response_json_string(self):
resp = requests.post(
@@ -345,8 +342,7 @@ class TestResponse(ApiServerUnittest):
test_context = context.Context()
test_context.bind_extractors(extract_binds)
resp_obj = response.ResponseObject(resp)
resp_obj.extract_response(test_context)
resp_obj = response.ResponseObject(resp, test_context)
extract_binds_dict = test_context.extractors
self.assertEqual(