Skip to content

Commit

Permalink
adjust test case
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Nov 28, 2024
1 parent 83d31b3 commit 5f7f6d3
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions apps/dashboard_app/tests/test_dashboard_data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,31 @@
@pytest.fixture
def mock_data_connector():
"""Fixture to mock the DataConnector."""
with patch("dashboard_app.helpers.load_data.DataConnector") as MockConnector:
connector = MockConnector.return_value
connector.fetch_data.return_value = MagicMock()
with patch("dashboard_app.helpers.load_data.data_connector") as MockConnector:
connector = MockConnector
# Mocking fetch_data calls with dummy data
connector.fetch_data.side_effect = [
MagicMock(to_dict=lambda orient: [
{
"user": "user1",
"collateral_enabled": [True, False],
"collateral": [100, 200],
"debt": [50, 150],
"block": 5
},
{
"user": "user2",
"collateral_enabled": [True],
"collateral": [300],
"debt": [100],
"block": 6
}
]),
MagicMock(
collateral=1.5,
debt=2.0
),
]
yield connector

@pytest.fixture
Expand Down Expand Up @@ -42,10 +64,12 @@ def test_load_data_success(mock_get_prices, handler):

# Negative Scenario: Missing or Invalid Data
def test_load_data_missing_data(handler):
handler._get_loan_stats = MagicMock(side_effect=Exception("Data fetch error"))
with pytest.raises(Exception, match="Data fetch error"):
"""Test for handling missing data in load_data method."""
handler._get_loan_stats = MagicMock(side_effect=AttributeError("'list' object has no attribute 'keys'"))
with pytest.raises(AttributeError, match="'list' object has no attribute 'keys'"):
handler.load_data()


# Negative Scenario: Invalid Prices
@patch("dashboard_app.helpers.load_data.get_prices")
def test_load_data_invalid_prices(mock_get_prices, handler):
Expand Down

0 comments on commit 5f7f6d3

Please sign in to comment.