Ejemplo n.º 1
0
def test_account(country: str):
    """Test account functionalities."""
    account = DysonAccount()

    # Login failure
    with pytest.raises(DysonLoginFailure):
        account.login_email_password(EMAIL, "wrong_pass", country)
    assert account.auth_info is None
    with pytest.raises(DysonAuthRequired):
        account.devices()

    # Login succeed
    account.login_email_password(EMAIL, PASSWORD, country)
    assert account.auth_info == AUTH_INFO

    # Devices
    devices = account.devices()
    assert devices[0].active is True
    assert devices[0].serial == DEVICE1_SERIAL
    assert devices[0].name == DEVICE1_NAME
    assert devices[0].version == DEVICE1_VERSION
    assert devices[0].credential == DEVICE1_CREDENTIAL
    assert devices[0].product_type == DEVICE1_PRODUCT_TYPE
    assert devices[0].auto_update is True
    assert devices[0].new_version_available is False
    assert devices[1].active is None
    assert devices[1].serial == DEVICE2_SERIAL
    assert devices[1].name == DEVICE2_NAME
    assert devices[1].version == DEVICE2_VERSION
    assert devices[1].credential == DEVICE2_CREDENTIAL
    assert devices[1].product_type == DEVICE2_PRODUCT_TYPE
    assert devices[1].auto_update is False
    assert devices[1].new_version_available is True
Ejemplo n.º 2
0
def test_server_error(mocked_requests: MockedRequests):
    """Test cloud server error handling."""
    def _handler_network_error(**kwargs):
        return (500, None)

    mocked_requests.register_handler("POST", API_PATH_EMAIL_REQUEST,
                                     _handler_network_error)
    mocked_requests.register_handler("GET", API_PATH_DEVICES,
                                     _handler_network_error)

    account = DysonAccount()
    with pytest.raises(DysonServerError):
        account.login_email_otp(EMAIL, REGION)
    account = DysonAccount(AUTH_INFO)
    with pytest.raises(DysonServerError):
        account.devices()
Ejemplo n.º 3
0
def test_network_error(mocked_requests: MockedRequests):
    """Test network error handling."""
    def _handler_network_error(**kwargs):
        raise requests.RequestException

    mocked_requests.register_handler("POST", API_PATH_EMAIL_REQUEST,
                                     _handler_network_error)
    mocked_requests.register_handler("GET", API_PATH_DEVICES,
                                     _handler_network_error)

    account = DysonAccount()
    with pytest.raises(DysonNetworkError):
        account.login_email_otp(EMAIL, REGION)
    account = DysonAccount(AUTH_INFO)
    with pytest.raises(DysonNetworkError):
        account.devices()
Ejemplo n.º 4
0
def test_server_error(mocked_requests: MockedRequests, country: str):
    """Test cloud server error handling."""
    def _handler_network_error(**kwargs):
        return (500, None)

    mocked_requests.register_handler("POST", API_PATH_LOGIN,
                                     _handler_network_error)
    mocked_requests.register_handler("GET", API_PATH_DEVICES,
                                     _handler_network_error)

    account = DysonAccount()
    with pytest.raises(DysonServerError):
        account.login_email_password(EMAIL, PASSWORD, country)
    account = DysonAccount(AUTH_INFO)
    with pytest.raises(DysonServerError):
        account.devices()
Ejemplo n.º 5
0
def test_account():
    """Test account functionalities."""
    account = DysonAccount()

    # Incorrect email
    with pytest.raises(DysonInvalidAccountStatus):
        account.login_email_otp("*****@*****.**", REGION)
    assert account.auth_info is None
    with pytest.raises(DysonAuthRequired):
        account.devices()

    # Incorrect password
    with pytest.raises(DysonLoginFailure):
        verify = account.login_email_otp(EMAIL, REGION)
        verify(OTP, "wrong_pass")
    assert account.auth_info is None

    # Incorrect OTP
    with pytest.raises(DysonLoginFailure):
        verify = account.login_email_otp(EMAIL, REGION)
        verify("999999", PASSWORD)
    assert account.auth_info is None

    # Login succeed
    verify = account.login_email_otp(EMAIL, REGION)
    verify(OTP, PASSWORD)
    assert account.auth_info == AUTH_INFO_BEARER

    # Devices
    devices = account.devices()
    assert devices[0].active is True
    assert devices[0].serial == DEVICE1_SERIAL
    assert devices[0].name == DEVICE1_NAME
    assert devices[0].version == DEVICE1_VERSION
    assert devices[0].credential == DEVICE1_CREDENTIAL
    assert devices[0].product_type == DEVICE1_PRODUCT_TYPE
    assert devices[0].auto_update is True
    assert devices[0].new_version_available is False
    assert devices[1].active is None
    assert devices[1].serial == DEVICE2_SERIAL
    assert devices[1].name == DEVICE2_NAME
    assert devices[1].version == DEVICE2_VERSION
    assert devices[1].credential == DEVICE2_CREDENTIAL
    assert devices[1].product_type == DEVICE2_PRODUCT_TYPE
    assert devices[1].auto_update is False
    assert devices[1].new_version_available is True
Ejemplo n.º 6
0
def test_account_auth_info():
    """Test initialize account with auth info."""
    account = DysonAccount(AUTH_INFO)
    devices = account.devices()
    assert len(devices) == 2

    # Invalid auth
    account = DysonAccount({
        "Account": "invalid",
        "Password": "******",
    }, )
    with pytest.raises(DysonInvalidAuth):
        account.devices()

    # No auth
    account = DysonAccount()
    with pytest.raises(DysonAuthRequired):
        account.devices()