Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better env check for creds #16

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions bcutils/tests/test_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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"
Expand All @@ -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"]
)
13 changes: 7 additions & 6 deletions sample/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
_env,
)
from bcutils.migrate import migrate_to_multi_freq
from bcutils.config import CONTRACT_MAP

logging.basicConfig(level=logging.INFO)

Expand Down Expand Up @@ -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,
)

Expand All @@ -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()