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()
async def test_wallbox_setup_entry(hass: HomeAssistantType): """Test Wallbox Setup.""" 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", text= '{"Temperature": 100, "Location": "Toronto", "Datetime": "2020-07-23", "Units": "Celsius"}', status_code=200, ) assert await wallbox.async_setup_entry(hass, entry) 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":404}', status_code=404, ) assert await wallbox.async_setup_entry(hass, entry) is False
async def test_configflow_class(): """Test configFlow class.""" configflow = config_flow.ConfigFlow() assert configflow with patch( "homeassistant.components.wallbox.config_flow.validate_input", side_effect=TypeError, ), raises(Exception): assert await configflow.async_step_user(True) with patch( "homeassistant.components.wallbox.config_flow.validate_input", side_effect=CannotConnect, ), raises(Exception): assert await configflow.async_step_user(True) with patch( "homeassistant.components.wallbox.config_flow.validate_input", ), raises(Exception): assert await configflow.async_step_user(True)
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()