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

Feat/web app pipeline #346

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
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
52 changes: 52 additions & 0 deletions .github/workflows/dashboard_app_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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
1,637 changes: 956 additions & 681 deletions 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 @@ -24,6 +24,9 @@ pre-commit = "^3.8.0"
pydantic = "^2.9.2"
pytest = "^8.3.3"
python-dotenv = "^1.0.1"
aiogram = "^3.15.0"
sqlalchemy = "^2.0.36"
sqlalchemy-utils = "^0.41.2"

[tool.poetry.group.dev.dependencies]
black = "^24.8.0"
Expand Down
36 changes: 31 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,10 +66,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
1 change: 1 addition & 0 deletions apps/data_handler/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ def __init__(self, db_url: str = SQLALCHEMY_DATABASE_URL):
Initialize the database connection and session factory.
:param db_url: Database connection URL.
"""
print(f"Database connection established: {db_url}")
self.engine = create_engine(db_url)
Base.metadata.create_all(self.engine)
self.session_factory = sessionmaker(bind=self.engine)
Expand Down
8 changes: 4 additions & 4 deletions apps/data_handler/db/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

load_dotenv()

DB_USER = os.environ.get("DB_USER", "")
DB_PASSWORD = os.environ.get("DB_PASSWORD", "")
DB_SERVER = os.environ.get("DB_HOST", "")
DB_USER = os.environ.get("DB_USER", "postgres")
DB_PASSWORD = os.environ.get("DB_PASSWORD", "password")
DB_SERVER = os.environ.get("DB_HOST", "127.0.01")
DB_PORT = os.environ.get("DB_PORT", 5432)
DB_NAME = os.environ.get("DB_NAME", "")
DB_NAME = os.environ.get("DB_NAME", "data_handler")

SQLALCHEMY_DATABASE_URL = (f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_SERVER}:{DB_PORT}/{DB_NAME}")

Expand Down