mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
extract_response when initialize ResponseObject
This commit is contained in:
+4
-1
@@ -3,11 +3,14 @@ from ate import utils, exception
|
|||||||
|
|
||||||
class ResponseObject(object):
|
class ResponseObject(object):
|
||||||
|
|
||||||
def __init__(self, resp_obj):
|
def __init__(self, resp_obj, context=None):
|
||||||
""" initialize with a requests.Response object
|
""" initialize with a requests.Response object
|
||||||
@param (requests.Response instance) resp_obj
|
@param (requests.Response instance) resp_obj
|
||||||
|
@param (ate.context.Context instance) context
|
||||||
"""
|
"""
|
||||||
self.resp_obj = resp_obj
|
self.resp_obj = resp_obj
|
||||||
|
if context:
|
||||||
|
self.extract_response(context)
|
||||||
|
|
||||||
def parsed_body(self):
|
def parsed_body(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
+1
-2
@@ -105,8 +105,7 @@ class TestRunner(object):
|
|||||||
|
|
||||||
resp = self.client.request(url=url, method=method, **req_kwargs)
|
resp = self.client.request(url=url, method=method, **req_kwargs)
|
||||||
|
|
||||||
resp_obj = response.ResponseObject(resp)
|
resp_obj = response.ResponseObject(resp, self.context)
|
||||||
resp_obj.extract_response(self.context)
|
|
||||||
return resp_obj.validate(testcase['response'])
|
return resp_obj.validate(testcase['response'])
|
||||||
|
|
||||||
def run_testset(self, testset):
|
def run_testset(self, testset):
|
||||||
|
|||||||
@@ -255,8 +255,7 @@ class TestResponse(ApiServerUnittest):
|
|||||||
|
|
||||||
test_context = context.Context()
|
test_context = context.Context()
|
||||||
test_context.bind_extractors(extract_binds)
|
test_context.bind_extractors(extract_binds)
|
||||||
resp_obj = response.ResponseObject(resp)
|
response.ResponseObject(resp, test_context)
|
||||||
resp_obj.extract_response(test_context)
|
|
||||||
|
|
||||||
extract_binds_dict = test_context.extractors
|
extract_binds_dict = test_context.extractors
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -312,10 +311,9 @@ class TestResponse(ApiServerUnittest):
|
|||||||
|
|
||||||
test_context = context.Context()
|
test_context = context.Context()
|
||||||
test_context.bind_extractors(extract_binds)
|
test_context.bind_extractors(extract_binds)
|
||||||
resp_obj = response.ResponseObject(resp)
|
|
||||||
|
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParamsError):
|
||||||
resp_obj.extract_response(test_context)
|
response.ResponseObject(resp, test_context)
|
||||||
|
|
||||||
extract_binds = {
|
extract_binds = {
|
||||||
"resp_content_list_index_error": "content.person.cities.3"
|
"resp_content_list_index_error": "content.person.cities.3"
|
||||||
@@ -323,10 +321,9 @@ class TestResponse(ApiServerUnittest):
|
|||||||
|
|
||||||
test_context = context.Context()
|
test_context = context.Context()
|
||||||
test_context.bind_extractors(extract_binds)
|
test_context.bind_extractors(extract_binds)
|
||||||
resp_obj = response.ResponseObject(resp)
|
|
||||||
|
|
||||||
with self.assertRaises(exception.ParamsError):
|
with self.assertRaises(exception.ParamsError):
|
||||||
resp_obj.extract_response(test_context)
|
response.ResponseObject(resp, test_context)
|
||||||
|
|
||||||
def test_extract_response_json_string(self):
|
def test_extract_response_json_string(self):
|
||||||
resp = requests.post(
|
resp = requests.post(
|
||||||
@@ -345,8 +342,7 @@ class TestResponse(ApiServerUnittest):
|
|||||||
|
|
||||||
test_context = context.Context()
|
test_context = context.Context()
|
||||||
test_context.bind_extractors(extract_binds)
|
test_context.bind_extractors(extract_binds)
|
||||||
resp_obj = response.ResponseObject(resp)
|
resp_obj = response.ResponseObject(resp, test_context)
|
||||||
resp_obj.extract_response(test_context)
|
|
||||||
|
|
||||||
extract_binds_dict = test_context.extractors
|
extract_binds_dict = test_context.extractors
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user