From 9cf47b14782343abedbea90141af169ef2f8d6d4 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Tue, 11 Jun 2024 14:15:47 +0200 Subject: [PATCH] a couple of tests --- tests/tests_integration/test_get_rates.py | 79 +++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/tests_integration/test_get_rates.py diff --git a/tests/tests_integration/test_get_rates.py b/tests/tests_integration/test_get_rates.py new file mode 100644 index 0000000..6566d33 --- /dev/null +++ b/tests/tests_integration/test_get_rates.py @@ -0,0 +1,79 @@ +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