set inputs for cli
This commit is contained in:
parent
f1eb555c03
commit
afe9e18e0d
4 changed files with 100 additions and 1 deletions
52
tests/tests_integration/test_xe_get_rates.py
Normal file
52
tests/tests_integration/test_xe_get_rates.py
Normal file
|
|
@ -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
|
||||
38
xexe/cli.py
38
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}")
|
||||
|
|
|
|||
7
xexe/inputs_handling.py
Normal file
7
xexe/inputs_handling.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import logging
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
def handle_get_rates_inputs():
|
||||
logger.info("Handling inputs.")
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue