mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-13 12:32:18 +00:00
fix: Resolve all CI failures - linting, typing, and test issues
Co-authored-by: elisiariocouto <818914+elisiariocouto@users.noreply.github.com>
This commit is contained in:
committed by
Elisiário Couto
parent
5987a759b8
commit
c8f0a103c6
@@ -2,7 +2,7 @@
|
||||
|
||||
import pytest
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import Mock, AsyncMock
|
||||
from unittest.mock import Mock, AsyncMock, patch
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from leggend.main import create_app
|
||||
@@ -22,7 +22,7 @@ class TestAnalyticsFix:
|
||||
return Mock(spec=DatabaseService)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_transaction_stats_uses_all_transactions(self, client, mock_database_service):
|
||||
async def test_transaction_stats_uses_all_transactions(self, mock_database_service):
|
||||
"""Test that transaction stats endpoint uses all transactions (not limited to 100)"""
|
||||
# Mock data for 600 transactions (simulating the issue)
|
||||
mock_transactions = []
|
||||
@@ -40,41 +40,34 @@ class TestAnalyticsFix:
|
||||
mock_database_service.get_transactions_from_db = AsyncMock(return_value=mock_transactions)
|
||||
|
||||
# Test that the endpoint calls get_transactions_from_db with limit=None
|
||||
with client as test_client:
|
||||
# Replace the database service in the route handler
|
||||
from leggend.api.routes import transactions
|
||||
original_service = transactions.database_service
|
||||
transactions.database_service = mock_database_service
|
||||
|
||||
try:
|
||||
response = test_client.get("/api/v1/transactions/stats?days=365")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Verify that limit=None was passed to get all transactions
|
||||
mock_database_service.get_transactions_from_db.assert_called_once()
|
||||
call_args = mock_database_service.get_transactions_from_db.call_args
|
||||
assert call_args.kwargs.get("limit") is None, "Stats endpoint should pass limit=None to get all transactions"
|
||||
|
||||
# Verify that the response contains stats for all 600 transactions
|
||||
assert data["success"] is True
|
||||
stats = data["data"]
|
||||
assert stats["total_transactions"] == 600, "Should process all 600 transactions, not just 100"
|
||||
|
||||
# Verify calculations are correct for all transactions
|
||||
expected_income = sum(txn["transactionValue"] for txn in mock_transactions if txn["transactionValue"] > 0)
|
||||
expected_expenses = sum(abs(txn["transactionValue"]) for txn in mock_transactions if txn["transactionValue"] < 0)
|
||||
|
||||
assert stats["total_income"] == expected_income
|
||||
assert stats["total_expenses"] == expected_expenses
|
||||
|
||||
finally:
|
||||
# Restore original service
|
||||
transactions.database_service = original_service
|
||||
with patch('leggend.api.routes.transactions.database_service', mock_database_service):
|
||||
app = create_app()
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/api/v1/transactions/stats?days=365")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Verify that limit=None was passed to get all transactions
|
||||
mock_database_service.get_transactions_from_db.assert_called_once()
|
||||
call_args = mock_database_service.get_transactions_from_db.call_args
|
||||
assert call_args.kwargs.get("limit") is None, "Stats endpoint should pass limit=None to get all transactions"
|
||||
|
||||
# Verify that the response contains stats for all 600 transactions
|
||||
assert data["success"] is True
|
||||
stats = data["data"]
|
||||
assert stats["total_transactions"] == 600, "Should process all 600 transactions, not just 100"
|
||||
|
||||
# Verify calculations are correct for all transactions
|
||||
expected_income = sum(txn["transactionValue"] for txn in mock_transactions if txn["transactionValue"] > 0)
|
||||
expected_expenses = sum(abs(txn["transactionValue"]) for txn in mock_transactions if txn["transactionValue"] < 0)
|
||||
|
||||
assert stats["total_income"] == expected_income
|
||||
assert stats["total_expenses"] == expected_expenses
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_analytics_endpoint_returns_all_transactions(self, client, mock_database_service):
|
||||
async def test_analytics_endpoint_returns_all_transactions(self, mock_database_service):
|
||||
"""Test that the new analytics endpoint returns all transactions without pagination"""
|
||||
# Mock data for 600 transactions
|
||||
mock_transactions = []
|
||||
@@ -91,28 +84,21 @@ class TestAnalyticsFix:
|
||||
|
||||
mock_database_service.get_transactions_from_db = AsyncMock(return_value=mock_transactions)
|
||||
|
||||
with client as test_client:
|
||||
# Replace the database service in the route handler
|
||||
from leggend.api.routes import transactions
|
||||
original_service = transactions.database_service
|
||||
transactions.database_service = mock_database_service
|
||||
|
||||
try:
|
||||
response = test_client.get("/api/v1/transactions/analytics?days=365")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Verify that limit=None was passed to get all transactions
|
||||
mock_database_service.get_transactions_from_db.assert_called_once()
|
||||
call_args = mock_database_service.get_transactions_from_db.call_args
|
||||
assert call_args.kwargs.get("limit") is None, "Analytics endpoint should pass limit=None"
|
||||
|
||||
# Verify that all 600 transactions are returned
|
||||
assert data["success"] is True
|
||||
transactions_data = data["data"]
|
||||
assert len(transactions_data) == 600, "Analytics endpoint should return all 600 transactions"
|
||||
|
||||
finally:
|
||||
# Restore original service
|
||||
transactions.database_service = original_service
|
||||
with patch('leggend.api.routes.transactions.database_service', mock_database_service):
|
||||
app = create_app()
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/api/v1/transactions/analytics?days=365")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
|
||||
# Verify that limit=None was passed to get all transactions
|
||||
mock_database_service.get_transactions_from_db.assert_called_once()
|
||||
call_args = mock_database_service.get_transactions_from_db.call_args
|
||||
assert call_args.kwargs.get("limit") is None, "Analytics endpoint should pass limit=None"
|
||||
|
||||
# Verify that all 600 transactions are returned
|
||||
assert data["success"] is True
|
||||
transactions_data = data["data"]
|
||||
assert len(transactions_data) == 600, "Analytics endpoint should return all 600 transactions"
|
||||
Reference in New Issue
Block a user