Files
roa2web-service-auto/shared/database
Marius Mutu a7a1bef375 Add missing test files and update .gitignore to allow test files
This commit addresses the overly restrictive .gitignore pattern that
was excluding all test files (test_*.py), including legitimate pytest
and unittest test suites essential for code quality and CI/CD.

Changes to .gitignore:
- Added negation patterns !**/tests/test_*.py and !**/test_*.py
  to allow proper test files while still blocking temporary scripts
- This enables pytest test suites to be tracked by git

Added test files (17 files):

Telegram Bot Tests (15 files):
- reports-app/telegram-bot/tests/test_auth.py
  Tests for authentication and account linking flow
- reports-app/telegram-bot/tests/test_callbacks.py
  Tests for callback query handlers
- reports-app/telegram-bot/tests/test_formatters.py
  Tests for message formatting utilities
- reports-app/telegram-bot/tests/test_formatters_extended.py
  Extended formatter tests
- reports-app/telegram-bot/tests/test_handlers_menu.py
  Tests for menu handlers
- reports-app/telegram-bot/tests/test_helpers.py
  Tests for helper functions
- reports-app/telegram-bot/tests/test_helpers_extended.py
  Extended helper tests
- reports-app/telegram-bot/tests/test_helpers_real.py
  Real integration tests for helpers
- reports-app/telegram-bot/tests/test_helpers_real_simple.py
  Simplified integration tests
- reports-app/telegram-bot/tests/test_login_flow.py
  Complete login flow integration tests
- reports-app/telegram-bot/tests/test_menus.py
  Menu system tests
- reports-app/telegram-bot/tests/test_session_company.py
  Session and company management tests
- reports-app/telegram-bot/test_claude_integration.py
  Manual integration test (Claude AI)
- reports-app/telegram-bot/test_claude_response.py
  Response formatting test
- reports-app/telegram-bot/test_db.py
  Database operations manual test

Shared Module Tests (2 files):
- shared/auth/test_auth.py
  Authentication system tests
- shared/database/test_pool.py
  Oracle connection pool tests

Security verification:
 All test files use mock objects, fixtures, and environment variables
 No hardcoded credentials or secrets found
 Safe for version control

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 15:09:43 +03:00
..

ROA2WEB Shared Database Pool

Sistem de pool de conexiuni Oracle partajat între toate microserviciile ROA2WEB.

Componente

📦 oracle_pool.py

Clasa singleton OraclePool pentru gestionarea pool-ului de conexiuni Oracle.

📋 models.py

Modele Pydantic comune:

  • User - Model pentru utilizatori
  • Company - Model pentru firme/scheme Oracle
  • DatabaseConfig - Configurare conexiune database

⚙️ config.py (în utils/)

Configurări partajate prin environment variables.

exceptions.py (în utils/)

Exception handlers personalizate pentru ROA2WEB.

Utilizare

Inițializare în aplicații FastAPI

from contextlib import asynccontextmanager
from fastapi import FastAPI
import sys
import os

# Import shared pool
sys.path.append(os.path.join(os.path.dirname(__file__), '../../../shared'))
from database.oracle_pool import oracle_pool

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup - inițializare pool
    await oracle_pool.initialize()
    print("📊 Oracle pool initialized")
    
    yield
    
    # Shutdown - închidere pool
    await oracle_pool.close_pool()
    print("📊 Oracle pool closed")

app = FastAPI(lifespan=lifespan)

Utilizare conexiune în endpoint-uri

from fastapi import APIRouter, HTTPException
from database.oracle_pool import oracle_pool

router = APIRouter()

@router.get("/companies")
async def get_companies():
    try:
        async with oracle_pool.get_connection() as conn:
            with conn.cursor() as cursor:
                cursor.execute("SELECT schema, firma FROM vdef_util_grup WHERE id_firma <> 0")
                results = cursor.fetchall()
                
                companies = []
                for row in results:
                    companies.append({
                        "code": row[0],
                        "name": row[1]
                    })
                
                return companies
                
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Database error: {str(e)}")

Configurare Environment Variables

# Oracle Database
ORACLE_USER=your_oracle_username
ORACLE_PASSWORD=your_oracle_password
ORACLE_DSN=your_oracle_dsn

# Pool Settings
DB_MIN_CONNECTIONS=2
DB_MAX_CONNECTIONS=10
DB_CONNECTION_INCREMENT=1

# JWT (pentru autentificare)
JWT_SECRET_KEY=your-super-secret-key
ACCESS_TOKEN_EXPIRE_MINUTES=30

Testare

Pentru a testa pool-ul de conexiuni:

cd roa2web/shared/database
python test_pool.py

Notă: Testul necesită configurarea variabilelor de environment pentru Oracle.

Caracteristici

Singleton Pattern - O singură instanță de pool pentru toată aplicația
Async Context Manager - Gestionare automată a conexiunilor
Connection Pooling - Performanță optimizată prin reutilizarea conexiunilor
Configurabil - Setări flexibile prin environment variables
Logging - Urmărirea operațiilor de pool
Error Handling - Excepții personalizate pentru debugging

Următorii Pași

👉 ZIUA 3: Implementarea sistemului JWT partajat (shared/auth/)


Documentație generată pentru ROA2WEB Shared Database Pool - ZIUA 2 🚀