Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Test: test_dashboard #340

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Changes from all 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
61 changes: 25 additions & 36 deletions web_app/tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
from fastapi.responses import JSONResponse
from fastapi.testclient import TestClient
from httpx import ASGITransport, AsyncClient

from web_app.api.dashboard import (
get_dashboard,
position_db_connector,
router,
)
from web_app.api.dashboard import get_dashboard, position_db_connector, router
from web_app.api.serializers.dashboard import DashboardResponse
from web_app.contract_tools.mixins import HealthRatioMixin
from web_app.contract_tools.mixins.dashboard import DashboardMixin
Expand Down Expand Up @@ -87,9 +82,6 @@ async def test_get_dashboard_success():
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_wallet_balances",
new_callable=AsyncMock,
) as mock_get_wallet_balances, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_zklend_position",
new_callable=AsyncMock,
) as mock_get_zklend_position, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_current_position_sum",
new_callable=AsyncMock,
) as mock_get_current_position_sum, patch(
Expand All @@ -112,15 +104,15 @@ async def test_get_dashboard_success():
"ETH": 5.0,
"USDC": 1000.0,
}
mock_get_zklend_position.return_value = {
"products": [
{
"name": "ZkLend",
"groups": {"1": {"healthRatio": "1.2"}},
"positions": [],
}
]
}
# mock_get_zklend_position.return_value = {
# "products": [
# {
# "name": "ZkLend",
# "groups": {"1": {"healthRatio": "1.2"}},
# "positions": [],
# }
# ]
# }
mock_get_current_position_sum.return_value = Decimal("200.0")
mock_get_start_position_sum.return_value = Decimal("200.0")

Expand All @@ -133,11 +125,12 @@ async def test_get_dashboard_success():
data = response.json()

assert data == {
"multipliers": {"ETH": 1},
"multipliers": {"ETH": "1"},
"start_dates": {"ETH": "2024-01-01T00:00:00"},
"current_sum": "200.0",
"start_sum": "200.0",
"borrowed": "200000.00",
"balance": "2.020202020202020202020202020",
"health_ratio": "1.2",
}

Expand All @@ -157,17 +150,14 @@ async def test_get_dashboard_no_positions():
) as mock_get_health_ratio_and_tvl, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_wallet_balances",
new_callable=AsyncMock,
) as mock_get_wallet_balances, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_zklend_position",
new_callable=AsyncMock,
) as mock_get_zklend_position:
) as mock_get_wallet_balances:
mock_get_contract_address_by_wallet_id.return_value = "0xabcdef1234567890"
mock_get_positions_by_wallet_id.return_value = []
mock_get_wallet_balances.return_value = {
"ETH": 5.0,
"USDC": 1000.0,
}
mock_get_zklend_position.return_value = {"products": []}
# mock_get_zklend_position.return_value = {"products": []}
mock_get_health_ratio_and_tvl.return_value = ("1.2", "1000.0")
async with AsyncClient(
transport=ASGITransport(app=app), base_url=BASE_URL
Expand All @@ -176,8 +166,8 @@ async def test_get_dashboard_no_positions():

assert response.is_success
data = response.json()
assert data["multipliers"] == {"ETH": None}
assert data["start_dates"] == {"ETH": None}
assert data["multipliers"] == {}
assert data["start_dates"] == {}


@pytest.mark.asyncio
Expand All @@ -195,18 +185,15 @@ async def test_get_dashboard_no_contract_address():
) as mock_get_health_ratio_and_tvl, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_wallet_balances",
new_callable=AsyncMock,
) as mock_get_wallet_balances, patch(
"web_app.contract_tools.mixins.dashboard.DashboardMixin.get_zklend_position",
new_callable=AsyncMock,
) as mock_get_zklend_position:
) as mock_get_wallet_balances:

mock_get_contract_address_by_wallet_id.return_value = None
mock_get_positions_by_wallet_id.return_value = []
mock_get_wallet_balances.return_value = {
"ETH": 5.0,
"USDC": 1000.0,
}
mock_get_zklend_position.return_value = {"products": []}
# mock_get_zklend_position.return_value = {"products": []}
mock_get_health_ratio_and_tvl.return_value = ("1.2", "1000.0")
async with AsyncClient(
transport=ASGITransport(app=app), base_url=BASE_URL
Expand Down Expand Up @@ -283,19 +270,21 @@ async def test_empty_positions(
)
mock_db_connector.get_positions_by_wallet_id.return_value = []
DashboardMixin.get_wallet_balances = AsyncMock(return_value=MOCK_WALLET_BALANCES)
DashboardMixin.get_zklend_position = AsyncMock(return_value={"products": []})
# DashboardMixin.get_zklend_position = AsyncMock(return_value={"products": []})
HealthRatioMixin.get_health_ratio_and_tvl = AsyncMock(
return_value=("1.2", "1000.0")
)

response = await get_dashboard(VALID_WALLET_ID)
assert isinstance(response, DashboardResponse)
assert response.dict() == {
"multipliers": {"ETH": None},
"start_dates": {"ETH": None},
"multipliers": {},
"start_dates": {},
"current_sum": Decimal("0"),
"start_sum": Decimal("0"),
"borrowed": "0.0",
"health_ratio": "1.2",
"borrowed": "0",
"balance": "0",
"health_ratio": "0",
}


Expand Down
Loading