mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 04:02:49 +05:30
refactor: Add JobSummary and Transaction models, client to get currency exchange rate
This commit is contained in:
@@ -5,23 +5,30 @@ from app.utils.csv_parser import parse_and_validate_csv
|
||||
|
||||
def test_parse_valid_csv():
|
||||
valid_csv = (
|
||||
"transaction_id,date,amount,category,description\n"
|
||||
"TX1001,2026-06-25,120.50,Groceries,Weekly grocery shop\n"
|
||||
"TX1002,06/26/2026,15.00,Coffee,Morning latte\n"
|
||||
"transaction_id,date,amount,category,description,currency,account\n"
|
||||
"TX1001,2026-06-25,120.50,Groceries,Weekly grocery shop,INR,ACC01\n"
|
||||
"TX1002,06/26/2026,15.00,Coffee,Morning latte,USD,ACC02\n"
|
||||
)
|
||||
result = parse_and_validate_csv(valid_csv.encode("utf-8"))
|
||||
assert len(result) == 2
|
||||
assert result[0]["transaction_id"] == "TX1001"
|
||||
assert result[0]["txn_id"] == "TX1001"
|
||||
assert result[0]["amount"] == 120.50
|
||||
assert result[0]["date"] == "2026-06-25"
|
||||
assert result[1]["transaction_id"] == "TX1002"
|
||||
assert result[0]["merchant"] == "Weekly grocery shop"
|
||||
assert result[0]["currency"] == "INR"
|
||||
assert result[0]["account_id"] == "ACC01"
|
||||
|
||||
assert result[1]["txn_id"] == "TX1002"
|
||||
assert result[1]["amount"] == 15.00
|
||||
assert result[1]["date"] == "2026-06-26"
|
||||
assert result[1]["merchant"] == "Morning latte"
|
||||
assert result[1]["currency"] == "USD"
|
||||
assert result[1]["account_id"] == "ACC02"
|
||||
|
||||
|
||||
def test_parse_missing_headers():
|
||||
invalid_csv = (
|
||||
"transaction_id,amount,category,description\n"
|
||||
"txn_id,amount,category,description\n"
|
||||
"TX1001,120.50,Groceries,Weekly grocery shop\n"
|
||||
)
|
||||
with pytest.raises(InvalidCSVException) as exc_info:
|
||||
@@ -31,8 +38,7 @@ def test_parse_missing_headers():
|
||||
|
||||
def test_parse_invalid_amount():
|
||||
invalid_csv = (
|
||||
"transaction_id,date,amount,category,description\n"
|
||||
"TX1001,2026-06-25,abc,Groceries,Weekly grocery shop\n"
|
||||
"txn_id,date,amount,merchant\nTX1001,2026-06-25,abc,Weekly grocery shop\n"
|
||||
)
|
||||
with pytest.raises(InvalidCSVException) as exc_info:
|
||||
parse_and_validate_csv(invalid_csv.encode("utf-8"))
|
||||
@@ -41,8 +47,7 @@ def test_parse_invalid_amount():
|
||||
|
||||
def test_parse_invalid_date():
|
||||
invalid_csv = (
|
||||
"transaction_id,date,amount,category,description\n"
|
||||
"TX1001,invalid-date,120.50,Groceries,Weekly grocery shop\n"
|
||||
"txn_id,date,amount,merchant\nTX1001,invalid-date,120.50,Weekly grocery shop\n"
|
||||
)
|
||||
with pytest.raises(InvalidCSVException) as exc_info:
|
||||
parse_and_validate_csv(invalid_csv.encode("utf-8"))
|
||||
|
||||
12
tests/services/test_exchange_rate.py
Normal file
12
tests/services/test_exchange_rate.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import pytest
|
||||
from app.clients.exchange_rate_client import ExchangeRateClient
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
async def test_get_usd_to_inr_rate():
|
||||
client = ExchangeRateClient()
|
||||
rate = await client.get_usd_to_inr_rate()
|
||||
assert isinstance(rate, float)
|
||||
# The rate should be positive (either the fetched rate or the default fallback of 83.0)
|
||||
assert rate > 0.0
|
||||
Reference in New Issue
Block a user