Skip to content

Commit

Permalink
Merge branch 'master' into feat/pipeline-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Joewizy authored Nov 29, 2024
2 parents ea5c06e + 8764daf commit b0498d9
Show file tree
Hide file tree
Showing 17 changed files with 4,632 additions and 363 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/dashboard_app_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: DashBoard App CI Workflow

on: [push]

jobs:
run_tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: data_handler
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install dependencies for Dashboard App
working-directory: ./apps/dashboard_app
run: |
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
poetry lock --no-update
poetry install
- name: Prepare Environment File
working-directory: ./apps/dashboard_app
run: |
cp .env.dev .env
- name: Run Tests for Dashboard_App
working-directory: ./apps/dashboard_app
run: poetry run pytest
6 changes: 6 additions & 0 deletions apps/dashboard_app/.env.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# PostgreSQL
DB_USER=postgres
DB_PASSWORD=password
DB_NAME=data_handler
DB_HOST=db
DB_PORT=5432
266 changes: 265 additions & 1 deletion apps/dashboard_app/poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions apps/dashboard_app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ psycopg2-binary = "^2.9.9"
matplotlib = { version = "3.8.0", optional = true }
tqdm = { version = "4.65.0", optional = true }
yfinance = { version = "0.2.38", optional = true }
sqlalchemy = "^2.0.30"
sqlalchemy-utils = "^0.41.2"
aiogram = "^3.12.0"
dill = "^0.3.8"
gcsfs = "^2024.6.1"
pre-commit = "^3.8.0"
Expand Down
35 changes: 30 additions & 5 deletions apps/dashboard_app/tests/test_dashboard_data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@
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()
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
def handler(mock_data_connector):
"""Fixture to initialize DashboardDataHandler."""
return DashboardDataHandler()
with patch("dashboard_app.helpers.load_data.DataConnector", return_value=mock_data_connector):
handler = DashboardDataHandler()
yield handler

# Positive Scenario: Test Initialization
def test_init_dashboard_data_handler(handler):
Expand Down Expand Up @@ -42,8 +66,9 @@ 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
Expand Down
8 changes: 8 additions & 0 deletions apps/data_handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Go to bash
docker-compose exec backend bash
```


## Running Migration Command:
1. Go to root folder `derisk-research`

Expand All @@ -118,4 +119,11 @@ cd ..
5. Run migration command:
```
alembic -c data_handler/alembic.ini revision --autogenerate -m "your migration message here"
=======
## How to run migration command:
1. Set up `.env.dev` into `derisk-research/apps/data_handler`
2. Go back to `derisk-research/apps` directory
3. Then run bash script to migrate:
```bash
bash data_handler/migrate.sh
```
Loading

0 comments on commit b0498d9

Please sign in to comment.