Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/supported-sources/frankfurter.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ ingestr ingest \
### **`--interval-end` (Optional)**
- **Description**: The end date for fetching historical exchange rates.
- **Value**: A date in the format `YYYY-MM-DD` (e.g., `'2025-03-28'`).
- **Purpose**: Defines the ending point for fetching historical data. If not provided, it defaults to the value of `--interval-start`.
- **Purpose**: Defines the ending point for fetching historical data.
- If not provided, it defaults to the value of `--interval-start`.
- If `--interval-end` is provided without `--interval-start`, it will be ignored and the call will retrieve the last published data.
- For `latest` and `currencies` this parameter is ignored.

---
Expand Down
113 changes: 113 additions & 0 deletions ingestr/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2953,6 +2953,119 @@ def test_applovin_source(testcase):
testcase()


def frankfurter_test_cases() -> Iterable[Callable]:
def invalid_source_table(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
result = invoke_ingest_command(
"frankfurter://",
"invalid table",
dest_uri,
dest_table,
)
assert result.exit_code != 0
assert has_exception(result.exception, ValueError)

def interval_start_does_not_exceed_interval_end(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
result = invoke_ingest_command(
"frankfurter://",
"exchange_rates",
dest_uri,
dest_table,
interval_start="2025-04-11",
interval_end="2025-04-10",
)
assert result.exit_code != 0
assert has_exception(result.exception, ValueError)
assert "Interval-end cannot be before interval-start." in str(result.exception)

def interval_start_can_equal_interval_end(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
result = invoke_ingest_command(
"frankfurter://",
"exchange_rates",
dest_uri,
dest_table,
interval_start="2025-04-10",
interval_end="2025-04-10",
)
assert result.exit_code == 0

def interval_start_does_not_exceed_current_date(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
start_date = pendulum.now().add(days=1).format("YYYY-MM-DD")
result = invoke_ingest_command(
"frankfurter://",
"exchange_rates",
dest_uri,
dest_table,
interval_start=start_date,
)
assert result.exit_code != 0
assert has_exception(result.exception, ValueError)
assert "Interval-start cannot be in the future." in str(result.exception)


def interval_end_does_not_exceed_current_date(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
start_date = pendulum.now().subtract(days=1).format("YYYY-MM-DD")
end_date = pendulum.now().add(days=1).format("YYYY-MM-DD")
result = invoke_ingest_command(
"frankfurter://",
"exchange_rates",
dest_uri,
dest_table,
interval_start=start_date,
interval_end=end_date,
)
assert result.exit_code != 0
assert has_exception(result.exception, ValueError)
assert "Interval-end cannot be in the future." in str(result.exception)

def exchange_rate_on_specific_date(dest_uri):
schema = f"testschema_frankfurter_{get_random_string(5)}"
dest_table = f"{schema}.frankfurter_{get_random_string(5)}"
start_date = "2025-01-03"
result = invoke_ingest_command(
"frankfurter://",
"exchange_rates",
dest_uri,
dest_table,
interval_start=start_date,
)
assert result.exit_code == 0, f"Ingestion failed: {result.output}"

dest_engine = sqlalchemy.create_engine(dest_uri)
query = f"SELECT rate FROM {dest_table} WHERE currency_name = 'GBP'"
with dest_engine.connect() as conn:
rows = conn.execute(query).fetchall()

# Assert that the rate for GBP is 0.82993
assert len(rows) > 0, "No data found for GBP"
assert rows[0][0] == 0.82993, f"Expected rate 0.82993, but got {rows[0][0]}"

return [
invalid_source_table,
interval_start_does_not_exceed_interval_end,
interval_start_can_equal_interval_end,
interval_start_does_not_exceed_current_date,
interval_end_does_not_exceed_current_date,
exchange_rate_on_specific_date,
]

@pytest.mark.parametrize(
"dest", list(DESTINATIONS.values()), ids=list(DESTINATIONS.keys())
)
@pytest.mark.parametrize("test_case", frankfurter_test_cases())
def test_frankfurter(dest, test_case):
test_case(dest.start())
dest.stop()

def test_version_cmd():
"""
This should always be 0.0.0-dev.
Expand Down
5 changes: 5 additions & 0 deletions ingestr/src/frankfurter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def get_path_with_retry(path: str) -> StrAny:
def validate_dates(start_date: datetime, end_date: datetime) -> None:
current_date = pendulum.now()

print("START DATE")
print(start_date)
print("END DATE")
print(end_date)

# Check if start_date is in the future
if start_date > current_date:
raise ValueError("Interval-start cannot be in the future.")
Expand Down