extractor: add support to extract value from html text with regex string

This commit is contained in:
httprunner
2017-10-31 23:26:38 +08:00
parent a1bc8dd964
commit 577cb01dcf
4 changed files with 110 additions and 15 deletions

View File

@@ -149,6 +149,55 @@ class TestResponse(ApiServerUnittest):
"abc"
)
def test_extract_text_response(self):
resp = requests.post(
url="http://127.0.0.1:5000/customize-response",
json={
'headers': {
'Content-Type': "application/json"
},
'body': "LB123abcRB789"
}
)
extract_binds_list = [
{"resp_content_key1": "LB123(.*)RB789"},
{"resp_content_key2": "LB[\d]*(.*)RB[\d]*"},
{"resp_content_key3": "LB[\d]*(.*)9"}
]
resp_obj = response.ResponseObject(resp)
extract_binds_dict = resp_obj.extract_response(extract_binds_list)
self.assertEqual(
extract_binds_dict["resp_content_key1"],
"abc"
)
self.assertEqual(
extract_binds_dict["resp_content_key2"],
"abc"
)
self.assertEqual(
extract_binds_dict["resp_content_key3"],
"abcRB78"
)
def test_extract_text_response_exception(self):
resp = requests.post(
url="http://127.0.0.1:5000/customize-response",
json={
'headers': {
'Content-Type': "application/json"
},
'body': "LB123abcRB789"
}
)
extract_binds_list = [
{"resp_content_key1": "LB123.*RB789"}
]
resp_obj = response.ResponseObject(resp)
with self.assertRaises(exception.ParamsError):
resp_obj.extract_response(extract_binds_list)
def test_extract_response_empty(self):
resp = requests.post(
url="http://127.0.0.1:5000/customize-response",
@@ -174,7 +223,7 @@ class TestResponse(ApiServerUnittest):
{"resp_content_body": "content.abc"}
]
resp_obj = response.ResponseObject(resp)
with self.assertRaises(exception.ResponseError):
with self.assertRaises(exception.ParamsError):
resp_obj.extract_response(extract_binds_list)
def test_validate(self):