[Refactor] Move NordigenCredentials to nordigen
Create manager that for now only has the default values from the .env file.
This commit is contained in:
parent
8710722eb2
commit
d6cbb10c47
@ -1,8 +1,6 @@
|
||||
import csv
|
||||
import dotenv
|
||||
from pathlib import Path
|
||||
import pickle
|
||||
import os
|
||||
import webbrowser
|
||||
|
||||
from pfbudget.common.types import Operation
|
||||
@ -27,13 +25,10 @@ from pfbudget.db.model import (
|
||||
Transaction,
|
||||
TransactionCategory,
|
||||
)
|
||||
from pfbudget.extract.credentials import Credentials
|
||||
from pfbudget.extract.nordigen import NordigenClient
|
||||
from pfbudget.extract.nordigen import NordigenClient, NordigenCredentialsManager
|
||||
from pfbudget.extract.parsers import parse_data
|
||||
from pfbudget.extract.psd2 import PSD2Extractor
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
class Manager:
|
||||
def __init__(self, db: str, verbosity: int = 0):
|
||||
@ -422,9 +417,4 @@ class Manager:
|
||||
|
||||
@staticmethod
|
||||
def nordigen_client() -> NordigenClient:
|
||||
credentials = Credentials(
|
||||
os.environ.get("SECRET_ID"),
|
||||
os.environ.get("SECRET_KEY"),
|
||||
os.environ.get("TOKEN"),
|
||||
)
|
||||
return NordigenClient(credentials)
|
||||
return NordigenClient(NordigenCredentialsManager.default)
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
@dataclass
|
||||
class Credentials:
|
||||
id: str
|
||||
key: str
|
||||
token: str = ""
|
||||
|
||||
def valid(self) -> bool:
|
||||
return self.id and self.key
|
||||
@ -1,17 +1,31 @@
|
||||
from dataclasses import dataclass
|
||||
import dotenv
|
||||
import json
|
||||
import nordigen
|
||||
import os
|
||||
import requests
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from .credentials import Credentials
|
||||
from .exceptions import CredentialsError, DownloadError
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
|
||||
@dataclass
|
||||
class NordigenCredentials:
|
||||
id: str
|
||||
key: str
|
||||
token: str = ""
|
||||
|
||||
def valid(self) -> bool:
|
||||
return self.id and self.key
|
||||
|
||||
|
||||
class NordigenClient:
|
||||
redirect_url = "https://murta.dev"
|
||||
|
||||
def __init__(self, credentials: Credentials):
|
||||
def __init__(self, credentials: NordigenCredentials):
|
||||
super().__init__()
|
||||
|
||||
if not credentials.valid():
|
||||
@ -90,3 +104,11 @@ class NordigenClient:
|
||||
if self._token:
|
||||
print("Replacing existing token with {value}")
|
||||
self._token = value
|
||||
|
||||
|
||||
class NordigenCredentialsManager:
|
||||
default = NordigenCredentials(
|
||||
os.environ.get("SECRET_ID"),
|
||||
os.environ.get("SECRET_KEY"),
|
||||
os.environ.get("TOKEN"),
|
||||
)
|
||||
|
||||
@ -6,9 +6,8 @@ import requests
|
||||
import mocks.nordigen as mock
|
||||
|
||||
from pfbudget.db.model import Bank, BankTransaction, Nordigen
|
||||
from pfbudget.extract.credentials import Credentials
|
||||
from pfbudget.extract.exceptions import BankError, CredentialsError
|
||||
from pfbudget.extract.nordigen import NordigenClient
|
||||
from pfbudget.extract.nordigen import NordigenClient, NordigenCredentials
|
||||
from pfbudget.extract.psd2 import PSD2Extractor
|
||||
|
||||
|
||||
@ -57,7 +56,7 @@ def mock_requests(monkeypatch):
|
||||
|
||||
@pytest.fixture
|
||||
def extractor() -> NordigenClient:
|
||||
credentials = Credentials("ID", "KEY", "TOKEN")
|
||||
credentials = NordigenCredentials("ID", "KEY", "TOKEN")
|
||||
return PSD2Extractor(NordigenClient(credentials))
|
||||
|
||||
|
||||
@ -70,7 +69,7 @@ def bank() -> list[Bank]:
|
||||
|
||||
class TestExtractPSD2:
|
||||
def test_empty_credentials(self):
|
||||
cred = Credentials("", "")
|
||||
cred = NordigenCredentials("", "")
|
||||
with pytest.raises(CredentialsError):
|
||||
NordigenClient(cred)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user