async def test_login_login_error(connector: Connector, raw_resp: aioresponses) -> None: raw_resp.post(urls.new_token(), status=401) try: await connector.login() assert False except ApiError as err: assert urls.new_token() in err.message assert not await connector.is_logged()
async def test_login_error_before_request(connector: Connector, raw_resp: aioresponses) -> None: with mock.patch.object(connector, "login", wraps=connector.login) as mock_login: raw_resp.post(urls.new_token(), status=401) raw_resp.get(urls.system(serial="123"), status=401) try: await connector.get(urls.system(serial="123")) assert False except ApiError as err: assert urls.new_token() in err.message mock_login.assert_called_once() assert not await connector.is_logged()
async def test_login_error_before_request(connector: Connector, raw_resp: aioresponses) -> None: with mock.patch.object(connector, 'login', wraps=connector.login)\ as mock_login: raw_resp.post(urls.new_token(), status=401) raw_resp.get(urls.system(serial='123'), status=401) try: await connector.get(urls.system(serial='123')) assert False except ApiError as err: assert str(err.response.url) == urls.new_token() mock_login.assert_called_once() assert not await connector.is_logged()
def mock_auth(resp_mock: aioresponses) -> None: resp_mock.post(urls.new_token(), status=200, payload={"body": { "authToken": "123" }}) resp_mock.post(urls.authenticate(), status=200) resp_mock.post(urls.logout(), status=200)
def mock_auth(resp_mock: aioresponses) -> None: resp_mock.post(urls.new_token(), status=200, payload={'body': { 'authToken': '123' }}) resp_mock.post(urls.authenticate(), status=200) resp_mock.post(urls.logout(), status=200)
async def test_login_auth_error(connector: Connector, raw_resp: aioresponses) -> None: raw_resp.post(urls.new_token(), status=200, payload={"body": { "authToken": "123" }}) raw_resp.post(urls.authenticate(), status=401) try: await connector.login() raise AssertionError("Error expected") except ApiError as err: assert urls.authenticate() in err.message assert not await connector.is_logged()
async def test_login_auth_error(connector: Connector, raw_resp: aioresponses) -> None: raw_resp.post(urls.new_token(), status=200, payload={'body': { 'authToken': '123' }}) raw_resp.post(urls.authenticate(), status=401) try: await connector.login() assert False except ApiError as err: assert str(err.response.url) == urls.authenticate() assert not await connector.is_logged()