data-xexe/tests/tests_integration/test_get_rates.py
2024-06-11 14:15:47 +02:00

79 lines
2.3 KiB
Python

import datetime
import random
from click.testing import CliRunner
from money.currency import Currency
from xexe.cli import get_rates
def test_get_rates_for_hardcoded_case_returns_expected_output():
"""
Calling the CLI get-rates command to get the rates between USD, EUR and GBP
for 2024-01-01 to 2024-01-03 returns the expected records in a CSV.
"""
runner = CliRunner()
with runner.isolated_filesystem():
run_result = runner.invoke(
get_rates,
[
"--start-date",
"2024-01-01",
"--end-date",
"2024-01-03",
"--currencies",
"USD,GBP,EUR",
"--output",
"test_output.csv",
],
)
assert run_result.exit_code == 0
# Write code here to read output file and compare it against expected
# output
assert False
def test_get_rates_dry_run_always_returns_42_as_rates():
"""
Calling the CLI get-rates command with the dry-run flag will apparently
work, but it always returns 42 as the rate no matter what it's being asked
for since it doesn't call xe.com at all and 42 is the Answer to the Ultimate
Question of Life, the Universe, and Everything.
"""
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_random_currencies = random.choices(population=list(Currency), k=3)
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(
[str(some_currency) for some_currency in some_random_currencies]
),
"--output",
"test_output.csv",
"--dry-run",
],
)
assert run_result.exit_code == 0
# Write code here to read output file and compare it against expected
# output
assert False