Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: json compare #229

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions flybirds/core/plugin/plugins/default/web/interception.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,34 +207,7 @@ def request_compare(operation, target_data_path):
raise FlybirdsException(message)

log.info(f'[request_compare] actualObj dict:{actual_request_obj}')

# Get the file path
file_path = os.path.join(os.getcwd(), target_data_path)

# If the file path exists, read data from the file and assign it to expect_request_obj
if os.path.exists(file_path):

expect_request_obj = file_helper.read_file_from_path(file_path)
if expect_request_obj.startswith('<?xml') or expect_request_obj.startswith('<'):
try:
# If the format is XML, parse the XML.
expect_request_obj = xmltodict.parse(expect_request_obj)
except ValueError:
message = f'[xml convert] format is wrong, data:' + expect_request_obj
raise FlybirdsException(message)

else:
try:
# If the format is json, parse the json.
expect_request_obj = file_helper.get_json_from_file_path(file_path)
except ValueError:
message = f'[json convert] format is wrong, data:' + expect_request_obj
raise FlybirdsException(message)

else:
message = f'[request_compare] expect_request_obj not get file from [{file_path}]'
raise FlybirdsException(message)

expect_request_obj = get_operate_actual_request_body(target_data_path)
# Output the information of expect_request_obj in the log
log.info(f'[request_compare] expectObj dict:{expect_request_obj}')

Expand Down Expand Up @@ -689,6 +662,37 @@ def open_web_request_mock(service_str, mock_case_id_str, mock_key_list_str, requ
"requestBody": mock_data.get("flybirdsMockRequest")
})

def get_operate_actual_request_body(target_data_path):

expect_request_obj = None
# Get the file path
file_path = os.path.join(os.getcwd(), target_data_path)

# If the file path exists, read data from the file and assign it to expect_request_obj
if os.path.exists(file_path):

expect_request_obj = file_helper.read_file_from_path(file_path)
if expect_request_obj.startswith('<?xml') or expect_request_obj.startswith('<'):
try:
# If the format is XML, parse the XML.
expect_request_obj = xmltodict.parse(expect_request_obj)
except ValueError:
message = f'[xml convert] format is wrong, data:' + expect_request_obj
raise FlybirdsException(message)

else:
try:
# If the format is json, parse the json.
expect_request_obj = file_helper.get_json_from_file_path(file_path)
except ValueError:
message = f'[json convert] format is wrong, data:' + expect_request_obj
raise FlybirdsException(message)

else:
message = f'[request_compare] expect_request_obj not get file from [{file_path}]'
raise FlybirdsException(message)
return expect_request_obj


def get_server_request_body(service):
interception_request = gr.get_value('interceptionRequest')
Expand Down