more tests, splitting input handling and logic

This commit is contained in:
Pablo Martin 2024-06-06 18:02:43 +02:00
parent afe9e18e0d
commit 46988352ca
4 changed files with 34 additions and 31 deletions

View file

@ -55,4 +55,4 @@ The output file will follow this schema:
A few more details:
- Running `get-rates` with an `end-date` beyond the current date will ignore the future dates. The run will behave as if you had specified today as the `end-date`.
- Any run that requires more than 1,000 API calls will prompt the user for confirmation. We do this to avoid accidentally running massive exports against the API due to human errors, since we have a monthly cap on the usage of xe.com's API.
- Trying to place an `end-date` before a `start-date` will cause an exception.

View file

@ -7,33 +7,34 @@ 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",
],
)
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
assert run_result.exit_code == 0
def test_get_rates_works_with_defaults():
runner = CliRunner()
result = runner.invoke(get_rates, ["--start-date"])
result = runner.invoke(get_rates, ["--output", "test_output.csv"])
assert result.exit_code == 0
def test_get_rates_breaks_without_output():
assert False
runner = CliRunner()
result = runner.invoke(get_rates)
assert result.exit_code == 2
def test_get_rates_replaces_future_dates_properly():
@ -44,9 +45,5 @@ 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

View file

@ -66,7 +66,7 @@ def xe_healthcheck():
"--currencies", default=",".join([]), show_default=True, type=click.STRING
)
@click.option("--dry-run", is_flag=True)
@click.option("--output", type=click.STRING)
@click.option("--output", type=click.STRING, required=True)
def get_rates(
start_date: Union[str, datetime.datetime, datetime.date],
end_date: Union[str, datetime.datetime, datetime.date],
@ -74,10 +74,11 @@ def get_rates(
dry_run: bool,
output: pathlib.Path,
):
handle_get_rates_inputs()
handle_get_rates_inputs(
start_date=start_date,
end_date=end_date,
currencies=currencies,
dry_run=dry_run,
output=output,
)
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}")

View file

@ -3,5 +3,10 @@ import logging
logger = logging.getLogger()
def handle_get_rates_inputs():
def handle_get_rates_inputs(start_date, end_date, currencies, dry_run, output):
logger.info("Handling inputs.")
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}")