def format_analysis_status(resp: AnalysisStatusResponse) -> str: """Format an analysis status response as compressed JSON.""" return resp.to_json()
def test_analysis_list_from_valid_json(): resp = AnalysisStatusResponse.from_json(JSON_DATA) assert_analysis_data(resp.analysis)
def test_analysis_list_from_valid_dict(): resp = AnalysisStatusResponse.from_dict(DICT_DATA) assert_analysis_data(resp.analysis)
client_tool_name=CLIENT_TOOL_NAME_1, ) ) # ANALYSIS STATUS ANALYSIS_STATUS_REQUEST_DICT = {"uuid": UUID_1} ANALYSIS_STATUS_REQUEST_OBJECT = AnalysisStatusRequest(uuid=UUID_1) ANALYSIS_STATUS_RESPONSE_DICT = ANALYSIS_SUBMISSION_RESPONSE_DICT ANALYSIS_STATUS_RESPONSE_OBJECT = AnalysisStatusResponse( analysis=Analysis( uuid=UUID_1, api_version=API_VERSION_1, maru_version=MARU_VERSION_1, mythril_version=MYTHRIL_VERSION_1, harvey_version=HARVEY_VERSION_1, queue_time=QUEUE_TIME_1, run_time=RUN_TIME_1, status=STATUS_1, submitted_at=SUBMITTED_AT_1, submitted_by=SUBMITTED_BY_1, client_tool_name=CLIENT_TOOL_NAME_1, ) ) # ANALYSIS LIST ANALYSIS_LIST_REQUEST_DICT = { "offset": OFFSET, "dateFrom": DATE_FROM, "dateTo": DATE_TO, } ANALYSIS_LIST_REQUEST_OBJECT = AnalysisListRequest(
import json from copy import deepcopy import pytest from mythx_models.response import Analysis, AnalysisStatusResponse from mythx_models.util import serialize_api_timestamp from .common import get_test_case JSON_DATA, DICT_DATA = get_test_case("testdata/analysis-status-response.json") OBJ_DATA = AnalysisStatusResponse.from_json(JSON_DATA) def assert_analysis_data(analysis: Analysis): assert DICT_DATA["apiVersion"] == analysis.api_version assert DICT_DATA["maruVersion"] == analysis.maru_version assert DICT_DATA["mythrilVersion"] == analysis.mythril_version assert DICT_DATA["harveyVersion"] == analysis.harvey_version assert DICT_DATA["queueTime"] == analysis.queue_time assert DICT_DATA["runTime"] == analysis.run_time assert DICT_DATA["status"] == analysis.status assert DICT_DATA["submittedAt"] == serialize_api_timestamp( analysis.submitted_at) assert DICT_DATA["submittedBy"] == analysis.submitted_by assert DICT_DATA["uuid"] == analysis.uuid def test_analysis_list_from_valid_json(): resp = AnalysisStatusResponse.from_json(JSON_DATA) assert_analysis_data(resp.analysis)
def test_analysis_list_from_empty_dict(): with pytest.raises(ValidationError): AnalysisStatusResponse.from_dict({})
def test_analysis_list_from_valid_dict(): resp = AnalysisStatusResponse.from_dict( testdata.ANALYSIS_STATUS_RESPONSE_DICT) assert_analysis_data(testdata.ANALYSIS_STATUS_RESPONSE_DICT, resp.analysis)
def test_analysis_list_from_empty_json(): with pytest.raises(ValidationError): AnalysisStatusResponse.from_json("{}")
def test_analysis_list_from_valid_json(): resp = AnalysisStatusResponse.from_json( json.dumps(testdata.ANALYSIS_STATUS_RESPONSE_DICT)) assert_analysis_data(testdata.ANALYSIS_STATUS_RESPONSE_DICT, resp.analysis)
def test_serde(response): resp = AnalysisStatusResponse(**response) assert resp.dict(by_alias=True) == response