Example #1
0
async def test_authentication_exception(hass: HomeAssistantType):
    """Test hub class, authentication raises exception."""

    station = ("12345", )
    username = ("test-username", )
    password = "******"

    hub = wallbox.WallboxHub(station, username, password, hass)

    with requests_mock.Mocker() as m, raises(wallbox.InvalidAuth):
        m.get("https://api.wall-box.com/auth/token/user",
              text="data",
              status_code=403)

        assert await hub.async_authenticate()

    with requests_mock.Mocker() as m, raises(ConnectionError):
        m.get("https://api.wall-box.com/auth/token/user",
              text="data",
              status_code=404)

        assert await hub.async_authenticate()

    with requests_mock.Mocker() as m, raises(wallbox.InvalidAuth):
        m.get("https://api.wall-box.com/auth/token/user",
              text="data",
              status_code=403)
        m.get(
            "https://api.wall-box.com/chargers/status/test",
            json=test_response,
            status_code=403,
        )
        assert await hub.async_get_data()
Example #2
0
async def test_get_data_rounding_error(hass: HomeAssistantType):
    """Test hub class, get_data with rounding error."""

    station = ("12345", )
    username = ("test-username", )
    password = "******"

    hub = wallbox.WallboxHub(station, username, password, hass)

    with requests_mock.Mocker() as m:
        m.get(
            "https://api.wall-box.com/auth/token/user",
            text=
            '{"jwt":"fakekeyhere","user_id":12345,"ttl":145656758,"error":false,"status":200}',
            status_code=200,
        )
        m.get(
            "https://api.wall-box.com/chargers/status/('12345',)",
            json=test_response_rounding_error,
            status_code=200,
        )
        assert await hub.async_get_data()
Example #3
0
async def test_get_data_exception(hass: HomeAssistantType):
    """Test hub class, authentication raises exception."""

    station = ("12345", )
    username = ("test-username", )
    password = "******"

    hub = wallbox.WallboxHub(station, username, password, hass)

    with requests_mock.Mocker() as m, raises(ConnectionError):
        m.get(
            "https://api.wall-box.com/auth/token/user",
            text=
            '{"jwt":"fakekeyhere","user_id":12345,"ttl":145656758,"error":false,"status":200}',
            status_code=200,
        )
        m.get(
            "https://api.wall-box.com/chargers/status/('12345',)",
            text="data",
            status_code=404,
        )
        assert await hub.async_get_data()