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()