mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 04:00:11 +08:00
extract_response when initialize ResponseObject
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user