def test_load_auth_with_no_stored_auth(cloud_hass, mock_read): """Test loading authentication with no stored auth.""" mock_read.return_value = None result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None
def test_load_auth_verification_failed_500(cloud_hass, mock_read, aioclient_mock): """Test loading authentication with verify request getting 500.""" mock_read.return_value = MOCK_AUTH aioclient_mock.get(url('account.json'), status=500) result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None
def test_load_auth_token_refresh_needed_timeout(cloud_hass, mock_read, aioclient_mock): """Test loading authentication with refresh timing out.""" mock_read.return_value = MOCK_AUTH aioclient_mock.get(url('account.json'), status=403) aioclient_mock.post(url('o/token/'), exc=asyncio.TimeoutError) result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None
def test_load_auth_token_refresh_needed_500(cloud_hass, mock_read, aioclient_mock): """Test loading authentication with refresh needed which gets 500.""" mock_read.return_value = MOCK_AUTH aioclient_mock.get(url('account.json'), status=403) aioclient_mock.post(url('o/token/'), status=500) result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None
def test_load_auth_timeout_during_verification(cloud_hass, mock_read): """Test loading authentication with timeout during verification.""" mock_read.return_value = MOCK_AUTH with patch.object(cloud_api.Cloud, 'async_refresh_account_info', side_effect=asyncio.TimeoutError): result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None
def test_load_auth_token_refresh_needed_succeeds(cloud_hass, mock_read, aioclient_mock): """Test loading authentication with refresh timing out.""" mock_read.return_value = MOCK_AUTH aioclient_mock.get(url('account.json'), status=403) with patch.object(cloud_api.Cloud, 'async_refresh_access_token', return_value=mock_coro(True)) as mock_refresh: result = yield from cloud_api.async_load_auth(cloud_hass) assert result is None assert len(mock_refresh.mock_calls) == 1
def test_load_auth_token(cloud_hass, mock_read, aioclient_mock): """Test loading authentication with refresh timing out.""" mock_read.return_value = MOCK_AUTH aioclient_mock.get(url('account.json'), json={ 'first_name': 'Paulus', 'last_name': 'Schoutsen' }) result = yield from cloud_api.async_load_auth(cloud_hass) assert result is not None assert result.account == {'first_name': 'Paulus', 'last_name': 'Schoutsen'} assert result.auth == MOCK_AUTH