From 0cc223f0f4f5a111b8fa6834647f0bc9047b7ed0 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 20 Jun 2024 23:00:22 +0200 Subject: [PATCH] Fixed tests --- test/secrets.py | 18 ++++++++++++++++++ test/test_nordnet.py | 14 ++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/secrets.py diff --git a/test/secrets.py b/test/secrets.py new file mode 100644 index 0000000..db07318 --- /dev/null +++ b/test/secrets.py @@ -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') diff --git a/test/test_nordnet.py b/test/test_nordnet.py index b42881d..8b15578 100644 --- a/test/test_nordnet.py +++ b/test/test_nordnet.py @@ -1,17 +1,23 @@ import requests +import pytest from fin_depo import investbank_nordnet -SECRET_USERNAME = None -SECRET_PASSWORD = None +from . import secrets +needs_secrets = pytest.mark.skipif( + not secrets.NORDNET_USERNAME, + reason='Secret NORDNET_USERNAME required', +) + +@needs_secrets def test_get_depo(): session = requests.Session() nordnet = investbank_nordnet.NordnetDepoFetcher( session, - SECRET_USERNAME, - SECRET_PASSWORD, + secrets.NORDNET_USERNAME, + secrets.NORDNET_PASSWORD, ) depo = nordnet.get_depo()