tests passing

This commit is contained in:
Pablo Martin 2024-06-13 15:56:57 +02:00
parent de8828a9cb
commit 515a4527af
4 changed files with 79 additions and 69 deletions

View file

@ -78,50 +78,50 @@ def test_get_rates_dry_run_always_returns_42_as_rates():
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"),
"--currencies",
",".join(some_random_currencies),
"--output",
"test_output.csv",
],
)
# 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"),
"--currencies",
",".join(some_random_currencies),
"--output",
"test_output.csv",
],
)
assert run_result.exit_code == 0
assert run_result.exit_code == 0
with open("test_output.csv", newline="") as csv_file:
reader = csv.DictReader(csv_file)
rows = list(reader)
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",
"0.024",
"0.02",
"0",
"1",
), 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']}"
# 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",
"0.024",
"0.02",
"0",
"1",
), 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']}"
assert (
row["from_currency"] in some_random_currencies
), f"Unexpected from_currency {row['from_currency']}"
assert (
row["to_currency"] in some_random_currencies
), f"Unexpected to_currency {row['to_currency']}"
row["from_currency"] in some_random_currencies
), f"Unexpected from_currency {row['from_currency']}"
assert (
row["to_currency"] in some_random_currencies
), f"Unexpected to_currency {row['to_currency']}"