diff --git a/bcutils/tests/test_downloader.py b/bcutils/tests/test_downloader.py index 224642f..528f802 100644 --- a/bcutils/tests/test_downloader.py +++ b/bcutils/tests/test_downloader.py @@ -63,6 +63,7 @@ def test_bad_credentials(self, download_dir): ) def test_hourly(self, bc_config, download_dir): + print(bc_config.keys()) if len(bc_config) == 0: pytest.skip("Skipping test, no Barchart credentials found in env") else: @@ -81,7 +82,7 @@ def test_hourly(self, bc_config, download_dir): assert not csv.is_dir() def test_daily(self, bc_config, download_dir): - if len(bc_config) == 0: + if not self._have_creds(bc_config): pytest.skip("Skipping test, no Barchart credentials found in env") else: get_barchart_downloads( @@ -100,7 +101,7 @@ def test_daily(self, bc_config, download_dir): assert not csv.is_dir() def test_insufficient(self, bc_config, download_dir): - if len(bc_config) == 0: + if not self._have_creds(bc_config): pytest.skip("Skipping test, no Barchart credentials found in env") else: contract_key = "UPU14" @@ -119,3 +120,12 @@ def test_insufficient(self, bc_config, download_dir): ) assert result == HistoricalDataResult.INSUFFICIENT + + @staticmethod + def _have_creds(config: dict): + return ( + "barchart_username" in config + and config["barchart_username"] + and "barchart_password" in config + and config["barchart_password"] + ) diff --git a/sample/samples.py b/sample/samples.py index bffe668..a658224 100644 --- a/sample/samples.py +++ b/sample/samples.py @@ -15,6 +15,7 @@ _env, ) from bcutils.migrate import migrate_to_multi_freq +from bcutils.config import CONTRACT_MAP logging.basicConfig(level=logging.INFO) @@ -122,14 +123,14 @@ def update_hourly_file(): ) -def update_daily_file(): - # update the daily AUD Mar 2024 price file in the current working directory - contract_map = {"AUD": {"code": "A6", "cycle": "HMUZ", "exchange": "CME"}} +def update_daily_file(contract_key, config=None): + if config is None: + config = CONTRACT_MAP update_barchart_contract_file( create_bc_session(config_obj=_env()), - _build_inverse_map(contract_map), + config, os.getcwd(), - "A6H24", + contract_key, Resolution.Day, ) @@ -153,5 +154,5 @@ def rename_files_with_new_format(): # save_hourly("CHFJPY", "UPU14") # update_downloads() # update_hourly_file() - # update_daily_file() + # update_daily_file("EPM24") # rename_files_with_new_format()