def format_version(resp: VersionResponse) -> str: """Format a version response as compressed JSON.""" return resp.to_json()
def format_version(resp: VersionResponse) -> str: """Format a version response to a tabular representation.""" data = ((k.title(), v) for k, v in resp.to_dict().items()) return tabulate(data, tablefmt="fancy_grid")
def test_version_response_from_valid_dict(): resp = VersionResponse.from_dict(DICT_DATA) assert_version_response(resp)
OPENAPI_RESPONSE = "openapi stuff" OPENAPI_RESPONSE_OBJECT = OASResponse(data=OPENAPI_RESPONSE) # VERSION VERSION_REQUEST_OBJECT = VersionRequest() VERSION_RESPONSE_DICT = { "api": API_VERSION_1, "maru": MARU_VERSION_1, "mythril": MYTHRIL_VERSION_1, "harvey": HARVEY_VERSION_1, "hash": HASHED_VERSION_1, } VERSION_RESPONSE_OBJECT = VersionResponse( api_version=API_VERSION_1, maru_version=MARU_VERSION_1, mythril_version=MYTHRIL_VERSION_1, harvey_version=HARVEY_VERSION_1, hashed_version=HASHED_VERSION_1, ) # ANALYSIS SUBMISSION ANALYSIS_SUBMISSION_REQUEST_DICT = { "contractName": CONTRACT_NAME, "bytecode": BYTECODE, "sourceMap": SOURCE_MAP, "deployedBytecode": DEPLOYED_BYTECODE, "deployedSourceMap": DEPLOYED_SOURCE_MAP, "mainSource": MAIN_SOURCE, "sources": SOURCES, "sourceList": SOURCE_LIST, "version": SOLC_VERSION,
import json from mythx_models.response import VersionResponse from .common import get_test_case JSON_DATA, DICT_DATA = get_test_case("testdata/version-response.json") OBJ_DATA = VersionResponse.from_json(JSON_DATA) def assert_version_response(resp: VersionResponse): assert resp.api_version == DICT_DATA["api"] assert resp.maru_version == DICT_DATA["maru"] assert resp.mythril_version == DICT_DATA["mythril"] assert resp.harvey_version == DICT_DATA["harvey"] assert resp.hashed_version == DICT_DATA["hash"] def test_version_response_from_valid_json(): resp = VersionResponse.from_json(JSON_DATA) assert_version_response(resp) def test_version_response_from_valid_dict(): resp = VersionResponse.from_dict(DICT_DATA) assert_version_response(resp) # def test_version_response_from_invalid_dict(): # with pytest.raises(ValidationError): # VersionResponse.from_dict({})
def test_version_response_from_valid_json(): resp = VersionResponse.from_json(JSON_DATA) assert_version_response(resp)
def test_auth_logout_request_from_invalid_json(): with pytest.raises(ValidationError): VersionResponse.from_json("{}")
def test_auth_logout_request_from_invalid_dict(): with pytest.raises(ValidationError): VersionResponse.from_dict({})
def test_auth_logout_request_from_valid_dict(): resp = VersionResponse.from_dict(testdata.VERSION_RESPONSE_DICT) assert_version_response(resp)
def test_auth_logout_request_from_valid_json(): resp = VersionResponse.from_json(json.dumps( testdata.VERSION_RESPONSE_DICT)) assert_version_response(resp)
def test_serde(response): resp = VersionResponse(**response) assert resp.dict(by_alias=True) == response