refactor: split monolithic app.py into modular Flask application with factory pattern

- Created app/ package with 6 modules:
  - __init__.py: Application factory (create_app function)
  - routes.py: All route handlers (473 lines)
  - models.py: Data persistence layer (41 lines)
  - validators.py: Input validation functions (48 lines)
  - email_service.py: Email sending functions (85 lines)
  - utils.py: Utility functions (30 lines)

- Implemented Flask application factory pattern
- Created run.py as minimal entry point
- Updated all test imports to use new module structure
- Fixed template/static folder paths for package structure

- All 102 tests passing
- Improved maintainability with clear separation of concerns
- Follows Flask best practices for scalable applications
This commit is contained in:
2025-12-27 22:36:05 +01:00
parent 733ee756c7
commit f1d8bae6a1
18 changed files with 1254 additions and 229 deletions
+26 -22
View File
@@ -4,7 +4,7 @@ Tests for configuration settings and helper functions.
import pytest
import os
from config import Config
from app import get_application_path, get_data_file_path, get_attachments_path
from app.models import get_application_path, get_data_file_path, get_attachments_path
class TestConfiguration:
@@ -59,33 +59,37 @@ class TestPathHelpers:
def test_get_application_path(self, app):
"""Test get_application_path returns correct path."""
session_id = 'test-123'
expected_path = os.path.join(app.config['APPLICATIONS_FOLDER'], session_id)
assert get_application_path(session_id) == expected_path
with app.app_context():
session_id = 'test-123'
expected_path = os.path.join(app.config['APPLICATIONS_FOLDER'], session_id)
assert get_application_path(session_id) == expected_path
def test_get_data_file_path(self, app):
"""Test get_data_file_path returns correct YAML file path."""
session_id = 'test-456'
expected_path = os.path.join(
app.config['APPLICATIONS_FOLDER'],
session_id,
'data.yaml'
)
assert get_data_file_path(session_id) == expected_path
with app.app_context():
session_id = 'test-456'
expected_path = os.path.join(
app.config['APPLICATIONS_FOLDER'],
session_id,
'data.yaml'
)
assert get_data_file_path(session_id) == expected_path
def test_get_attachments_path(self, app):
"""Test get_attachments_path returns correct attachments directory path."""
session_id = 'test-789'
expected_path = os.path.join(
app.config['APPLICATIONS_FOLDER'],
session_id,
'attachments'
)
assert get_attachments_path(session_id) == expected_path
with app.app_context():
session_id = 'test-789'
expected_path = os.path.join(
app.config['APPLICATIONS_FOLDER'],
session_id,
'attachments'
)
assert get_attachments_path(session_id) == expected_path
def test_path_helpers_with_special_characters(self, app):
"""Test path helpers handle session IDs with special characters."""
session_id = 'test-abc-123-def'
app_path = get_application_path(session_id)
assert session_id in app_path
assert os.path.isabs(app_path) or app_path.startswith('.')
with app.app_context():
session_id = 'test-abc-123-def'
app_path = get_application_path(session_id)
assert session_id in app_path
assert os.path.isabs(app_path) or app_path.startswith('.')