add test for pair path

This commit is contained in:
Pablo Martin 2025-05-26 16:30:21 +02:00
parent 568e27adbe
commit d74be13372

View file

@ -143,3 +143,60 @@ def test_get_rates_dry_run_always_returns_42_as_rates():
assert ( assert (
row["to_currency"] in some_random_currencies row["to_currency"] in some_random_currencies
), f"Unexpected to_currency {row['to_currency']}" ), f"Unexpected to_currency {row['to_currency']}"
def test_get_rates_dry_run__with_pairs_always_returns_42_as_rates():
"""
Same as the test above, but relying on the pairs argument instead
of the currencies one.
"""
some_random_date = datetime.datetime(
year=random.choice(range(2010, 2020)),
month=random.choice(range(1, 13)),
day=random.choice(range(1, 29)),
).date()
some_pairs = ["USDEUR", "USDGBP", "GBPEUR"]
runner = CliRunner()
with runner.isolated_filesystem():
run_result = runner.invoke(
get_rates,
[
"--start-date",
some_random_date.strftime("%Y-%m-%d"),
"--end-date",
(some_random_date + datetime.timedelta(days=3)).strftime("%Y-%m-%d"),
"--pairs",
",".join(some_pairs),
"--output",
"test_output.csv",
],
)
assert run_result.exit_code == 0
with open("test_output.csv", newline="") as csv_file:
reader = csv.DictReader(csv_file)
rows = list(reader)
# Ensure that the output contains the correct number of rows
expected_num_rows = 36
assert (
len(rows) == expected_num_rows
), f"Expected {expected_num_rows} rows, but got {len(rows)}"
# Check that all rows have the expected rate of 42, 1/42 or 1 and the correct dates
for row in rows:
assert row["rate"] in (
"42.00000000",
"0.02380952",
"0.00000000",
"1.00000000",
), f"Expected rate to be 42, 1/42 or 1, but got {row['rate']}"
assert row["rate_date"] in [
(some_random_date + datetime.timedelta(days=i)).strftime("%Y-%m-%d")
for i in range(4)
], f"Unexpected rate_date {row['rate_date']}"