quite a bit of development around get rates input handling
This commit is contained in:
parent
46988352ca
commit
4f81ac2e62
8 changed files with 199 additions and 20 deletions
94
tests/tests_unit/test_input_handling.py
Normal file
94
tests/tests_unit/test_input_handling.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import datetime
|
||||
|
||||
import pytest
|
||||
from currencies import Currency
|
||||
from currencies.exceptions import CurrencyDoesNotExist
|
||||
|
||||
from xexe.inputs_handling import handle_get_rates_inputs
|
||||
from xexe.utils import DateRange
|
||||
|
||||
|
||||
def test_handle_input_rates_works_with_full_correct_inputs():
|
||||
handled_inputs = handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now(),
|
||||
end_date=datetime.datetime.now() + datetime.timedelta(days=7),
|
||||
currencies="USD,EUR,GBP",
|
||||
dry_run=False,
|
||||
output="test_output.csv",
|
||||
)
|
||||
expected_result = {
|
||||
"date_range": DateRange(
|
||||
start_date=datetime.datetime.now().date(),
|
||||
end_date=(datetime.datetime.now() + datetime.timedelta(days=7)).date(),
|
||||
),
|
||||
"currencies": {Currency("USD"), Currency("EUR"), Currency("GBP")},
|
||||
"dry_run": False,
|
||||
"output": pathlib.Path("test_output.csv"),
|
||||
}
|
||||
assert handled_inputs == expected_result
|
||||
|
||||
|
||||
def test_handle_input_rates_raises_with_bad_currency_code():
|
||||
|
||||
with pytest.raises(CurrencyDoesNotExist):
|
||||
handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now(),
|
||||
end_date=datetime.datetime.now() + datetime.timedelta(days=7),
|
||||
currencies="not_a_currency,USD,not_this_either",
|
||||
dry_run=False,
|
||||
output="test_output.csv",
|
||||
)
|
||||
|
||||
|
||||
def test_handle_input_rates_raises_with_start_date_after_end_date():
|
||||
with pytest.raises(ValueError):
|
||||
handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now(),
|
||||
end_date=datetime.datetime.now() - datetime.timedelta(days=7),
|
||||
currencies="GBP,USD",
|
||||
dry_run=False,
|
||||
output="test_output.csv",
|
||||
)
|
||||
|
||||
|
||||
def test_handle_input_rates_raises_with_output_different_than_csv():
|
||||
with pytest.raises(ValueError):
|
||||
handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now(),
|
||||
end_date=datetime.datetime.now() + datetime.timedelta(days=7),
|
||||
currencies="GBP,USD",
|
||||
dry_run=False,
|
||||
output="test_output.xlsx",
|
||||
)
|
||||
|
||||
|
||||
def test_handle_input_rates_brings_future_end_date_to_today():
|
||||
handled_inputs = handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now() - datetime.timedelta(days=7),
|
||||
end_date=datetime.datetime.now() + datetime.timedelta(days=7),
|
||||
currencies="USD,EUR,GBP",
|
||||
dry_run=False,
|
||||
output="test_output.csv",
|
||||
)
|
||||
|
||||
assert handled_inputs["date_range"].end_date == datetime.datetime.now().date()
|
||||
|
||||
|
||||
def test_handle_input_rates_start_and_end_date_equal_works_fine():
|
||||
handled_inputs = handle_get_rates_inputs(
|
||||
start_date=datetime.datetime.now(),
|
||||
end_date=datetime.datetime.now(),
|
||||
currencies="USD,EUR,GBP",
|
||||
dry_run=False,
|
||||
output="test_output.csv",
|
||||
)
|
||||
expected_result = {
|
||||
"date_range": DateRange(
|
||||
start_date=datetime.datetime.now().date(),
|
||||
end_date=(datetime.datetime.now() + datetime.timedelta(days=7)).date(),
|
||||
),
|
||||
"currencies": {Currency("USD"), Currency("EUR"), Currency("GBP")},
|
||||
"dry_run": False,
|
||||
"output": "test_output.csv",
|
||||
}
|
||||
assert handled_inputs == expected_result
|
||||
Loading…
Add table
Add a link
Reference in a new issue