def test_serde(response):
    obj = AuthLoginResponse(**response)
    assert obj.dict(by_alias=True) == {
        "access": response["access"],
        "refresh": response["refresh"],
    }
Esempio n. 2
0
    harvey_version=HARVEY_VERSION_1,
    queue_time=QUEUE_TIME_1,
    status=STATUS_1,
    client_tool_name=CLIENT_TOOL_NAME_1,
    submitted_at=SUBMITTED_AT_1,
    submitted_by=SUBMITTED_BY_1,
)

# LOGIN
LOGIN_REQUEST_DICT = {"ethAddress": ETH_ADDRESS, "password": PASSWORD}
LOGIN_REQUEST_OBJECT = AuthLoginRequest(eth_address=ETH_ADDRESS, password=PASSWORD)
LOGIN_RESPONSE_DICT = {
    "jwtTokens": {"access": ACCESS_TOKEN_1, "refresh": REFRESH_TOKEN_1}
}
LOGIN_RESPONSE_OBJECT = AuthLoginResponse(
    access_token=ACCESS_TOKEN_1, refresh_token=REFRESH_TOKEN_1
)

# LOGOUT
LOGOUT_REQUEST_DICT = LOGOUT = {"global": GLOBAL_LOGOUT}
LOGOUT_REQUEST_OBJECT = AuthLogoutRequest()
LOGOUT_RESPONSE_DICT = {}
LOGOUT_RESPONSE_OBJECT = AuthLogoutResponse()

# REFRESH
REFRESH_REQUEST_PAYLOAD_DICT = {
    "jwtTokens": {"access": ACCESS_TOKEN_1, "refresh": REFRESH_TOKEN_1}
}
REFRESH_REQUEST_DICT = LOGIN_RESPONSE_DICT
REFRESH_REQUEST_OBJECT = AuthRefreshRequest(
    access_token=ACCESS_TOKEN_1, refresh_token=REFRESH_TOKEN_1
def test_auth_login_response_from_valid_dict():
    resp = AuthLoginResponse.from_dict(testdata.LOGIN_RESPONSE_DICT)
    assert_auth_login_response(resp)
def test_auth_login_response_from_invalid_dict():
    with pytest.raises(ValidationError):
        AuthLoginResponse.from_dict({})
def test_auth_login_response_from_invalid_json():
    with pytest.raises(ValidationError):
        AuthLoginResponse.from_json("{}")
def test_auth_login_response_from_valid_json():
    resp = AuthLoginResponse.from_json(json.dumps(
        testdata.LOGIN_RESPONSE_DICT))
    assert_auth_login_response(resp)
Esempio n. 7
0
def test_auth_login_response_from_valid_dict():
    resp = AuthLoginResponse.from_dict(DICT_DATA)
    assert_auth_login_response(resp)
Esempio n. 8
0
def test_auth_login_response_from_valid_json():
    resp = AuthLoginResponse.from_json(JSON_DATA)
    assert_auth_login_response(resp)
Esempio n. 9
0
import json

import pytest

from mythx_models.response import AuthLoginResponse

from .common import get_test_case

JSON_DATA, DICT_DATA = get_test_case("testdata/auth-login-response.json")
OBJ_DATA = AuthLoginResponse.from_json(JSON_DATA)


def assert_auth_login_response(resp: AuthLoginResponse):
    assert resp.api_key == DICT_DATA["jwtTokens"]["access"]
    assert resp.refresh_token == DICT_DATA["jwtTokens"]["refresh"]


def test_auth_login_response_from_valid_json():
    resp = AuthLoginResponse.from_json(JSON_DATA)
    assert_auth_login_response(resp)


# def test_auth_login_response_from_invalid_json():
#     with pytest.raises(ValidationError):
#         AuthLoginResponse.from_json("{}")


def test_auth_login_response_from_valid_dict():
    resp = AuthLoginResponse.from_dict(DICT_DATA)
    assert_auth_login_response(resp)