[Fix] Authentication token missing

Forgot to add the token to the NordigenClient.
Made a test failing, and fixed it.
This commit is contained in:
Luís Murta 2023-04-15 15:54:31 +01:00
parent eb5c1781f0
commit a3d2d8215e
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94
2 changed files with 16 additions and 11 deletions

View File

@ -11,7 +11,7 @@ import pfbudget.db.model as t
from pfbudget.utils.converters import convert
from .credentials import Credentials
from .exceptions import BankError, CredentialsError
from .exceptions import BankError, CredentialsError, ExtractError
from .extract import Extract
@ -29,7 +29,7 @@ class PSD2Client(Extract):
)
if credentials.token:
self._token = credentials.token
self._client.token = credentials.token
self._start = dt.date.min
self._end = dt.date.max
@ -46,7 +46,7 @@ class PSD2Client(Extract):
downloaded = self.download(bank.nordigen.requisition_id)
except requests.HTTPError as e:
print(f"There was an issue downloading from {bank.name} -> {e}")
continue
raise ExtractError(e)
if downloaded:
self.dump(bank, downloaded)

View File

@ -12,21 +12,24 @@ from pfbudget.extract.psd2 import PSD2Client
class MockGet:
def __init__(self, status_code: int = 200, exception=None):
self._ok = True if status_code == 200 else False
self._status_code = status_code
self._exception = exception
def __init__(self, mock_exception=None):
self._status_code = 200
self._mock_exception = mock_exception
def __call__(self, *args, **kwargs):
if self._exception:
raise self._exception
if self._mock_exception:
raise self._mock_exception
self._headers = kwargs["headers"]
if "Authorization" not in self._headers or not self._headers["Authorization"]:
self._status_code = 401
self.url = kwargs["url"]
return self
@property
def ok(self):
return self._ok
return True if self._status_code < 400 else False
@property
def status_code(self):
@ -79,7 +82,9 @@ class TestExtractPSD2:
client.extract([Bank("", "", "")])
def test_timeout(self, monkeypatch, client, banks):
monkeypatch.setattr("requests.get", MockGet(exception=requests.ReadTimeout))
monkeypatch.setattr(
"requests.get", MockGet(mock_exception=requests.ReadTimeout)
)
with pytest.raises(requests.Timeout):
client.extract(banks)