1
0

Fixed tests

This commit is contained in:
Jon Michael Aanes 2024-06-20 23:00:22 +02:00
parent d2cdef2bfa
commit 0cc223f0f4
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
2 changed files with 28 additions and 4 deletions

18
test/secrets.py Normal file
View File

@ -0,0 +1,18 @@
import logging
logger = logging.getLogger(__name__)
def load_secret(env_key: str) -> str:
filepath = f'./secrets/{env_key.lower()}'
try:
with open(filepath) as f:
return f.read().strip()
logger.info('Loaded secret: %s', env_key)
except Exception:
logger.exception("Could not load %s file '%s'", env_key, filepath)
return None
NORDNET_USERNAME = load_secret('NORDNET_USERNAME')
NORDNET_PASSWORD = load_secret('NORDNET_PASSWORD')

View File

@ -1,17 +1,23 @@
import requests import requests
import pytest
from fin_depo import investbank_nordnet from fin_depo import investbank_nordnet
SECRET_USERNAME = None from . import secrets
SECRET_PASSWORD = None
needs_secrets = pytest.mark.skipif(
not secrets.NORDNET_USERNAME,
reason='Secret NORDNET_USERNAME required',
)
@needs_secrets
def test_get_depo(): def test_get_depo():
session = requests.Session() session = requests.Session()
nordnet = investbank_nordnet.NordnetDepoFetcher( nordnet = investbank_nordnet.NordnetDepoFetcher(
session, session,
SECRET_USERNAME, secrets.NORDNET_USERNAME,
SECRET_PASSWORD, secrets.NORDNET_PASSWORD,
) )
depo = nordnet.get_depo() depo = nordnet.get_depo()