diff --git a/tests/tests_integration/test_xe_get_rates.py b/tests/tests_integration/test_xe_get_rates.py new file mode 100644 index 0000000..4e9e4ba --- /dev/null +++ b/tests/tests_integration/test_xe_get_rates.py @@ -0,0 +1,52 @@ +from click.testing import CliRunner + +from xexe.cli import get_rates + + +def test_get_rates_reads_input_correctly(): + + runner = CliRunner() + + with runner.isolated_filesystem(): + run_result = runner.invoke( + get_rates, + [ + "--start-date", + "2024-01-01", + "--end-date", + "2024-01-02", + "--currencies", + "USD,GBP", + "--output", + "test_output.csv", + "--dry-run", + ], + ) + + assert run_result.exit_code == 0 + + +def test_get_rates_works_with_defaults(): + runner = CliRunner() + result = runner.invoke(get_rates, ["--start-date"]) + assert result.exit_code == 0 + + +def test_get_rates_breaks_without_output(): + assert False + + +def test_get_rates_replaces_future_dates_properly(): + assert False + + +def test_get_rates_rejects_start_date_after_end_date(): + assert False + + +def test_get_rates_requires_prompt_for_large_export(): + assert False + + +def test_get_rates_rejects_invalid_currency_codes(): + assert False diff --git a/xexe/cli.py b/xexe/cli.py index f3fd0a2..168a892 100644 --- a/xexe/cli.py +++ b/xexe/cli.py @@ -1,12 +1,16 @@ +import datetime import importlib.metadata import logging +import pathlib +from typing import Union import click import pyfiglet from dotenv import load_dotenv from xexe.constants import PATHS -from xexe.processes import run_xe_healthcheck +from xexe.inputs_handling import handle_get_rates_inputs +from xexe.processes import run_get_rates, run_xe_healthcheck logging.basicConfig( level=logging.DEBUG, @@ -45,3 +49,35 @@ def xe_healthcheck(): logger.info("Running healthcheck against xe.com API.") run_xe_healthcheck() logger.info("Healthcheck attempt finished.") + + +@cli.command() +@click.option( + "--start-date", + type=click.DateTime(), + default=datetime.datetime.today() - datetime.timedelta(days=7), +) +@click.option( + "--end-date", + type=click.DateTime(), + default=datetime.datetime.today(), +) +@click.option( + "--currencies", default=",".join([]), show_default=True, type=click.STRING +) +@click.option("--dry-run", is_flag=True) +@click.option("--output", type=click.STRING) +def get_rates( + start_date: Union[str, datetime.datetime, datetime.date], + end_date: Union[str, datetime.datetime, datetime.date], + currencies: Union[None, str], + dry_run: bool, + output: pathlib.Path, +): + handle_get_rates_inputs() + run_get_rates() + logger.debug(f"Received start_date: {start_date}") + logger.debug(f"Received end_date: {end_date}") + logger.debug(f"Received currencies: {currencies}") + logger.debug(f"dry_run state: {dry_run}") + logger.debug(f"Received output: {output}") diff --git a/xexe/inputs_handling.py b/xexe/inputs_handling.py new file mode 100644 index 0000000..b802ca9 --- /dev/null +++ b/xexe/inputs_handling.py @@ -0,0 +1,7 @@ +import logging + +logger = logging.getLogger() + + +def handle_get_rates_inputs(): + logger.info("Handling inputs.") diff --git a/xexe/processes.py b/xexe/processes.py index 30a9276..ec7c92b 100644 --- a/xexe/processes.py +++ b/xexe/processes.py @@ -42,3 +42,7 @@ def run_xe_healthcheck() -> None: logger.info("xe.com reached successfully.") logger.info("See response below.") logger.info(account_info_response) + + +def run_get_rates(): + logger.info("Getting rates")