Files
gurix f1d8bae6a1 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
2025-12-27 22:36:05 +01:00

96 lines
3.7 KiB
Python

"""
Tests for configuration settings and helper functions.
"""
import pytest
import os
from config import Config
from app.models import get_application_path, get_data_file_path, get_attachments_path
class TestConfiguration:
"""Tests for Config class."""
def test_config_has_required_settings(self):
"""Test that all required configuration values exist."""
assert hasattr(Config, 'SECRET_KEY')
assert hasattr(Config, 'MAIL_SERVER')
assert hasattr(Config, 'MAIL_PORT')
assert hasattr(Config, 'MAIL_USE_TLS')
assert hasattr(Config, 'APPLICATIONS_FOLDER')
assert hasattr(Config, 'MAX_FILE_SIZE')
assert hasattr(Config, 'MAX_FILES')
assert hasattr(Config, 'ALLOWED_EXTENSIONS')
assert hasattr(Config, 'MAX_STRING_LENGTH')
assert hasattr(Config, 'MAX_TEXT_AREA_LENGTH')
assert hasattr(Config, 'MAX_ZIP_DIGITS')
assert hasattr(Config, 'MIN_BIRTH_YEAR')
assert hasattr(Config, 'MAX_BIRTH_YEAR')
def test_file_size_limit(self):
"""Test that file size limit is set correctly."""
assert Config.MAX_FILE_SIZE == 4 * 1024 * 1024 # 4 MB
def test_max_files_limit(self):
"""Test that maximum number of files is set correctly."""
assert Config.MAX_FILES == 3
def test_allowed_extensions(self):
"""Test that allowed file extensions are configured."""
assert isinstance(Config.ALLOWED_EXTENSIONS, set)
assert 'pdf' in Config.ALLOWED_EXTENSIONS
assert 'doc' in Config.ALLOWED_EXTENSIONS
assert 'docx' in Config.ALLOWED_EXTENSIONS
def test_string_length_limits(self):
"""Test that string length limits are set."""
assert Config.MAX_STRING_LENGTH == 255
assert Config.MAX_TEXT_AREA_LENGTH == 3000
assert Config.MAX_ZIP_DIGITS == 10
def test_birth_year_range(self):
"""Test that birth year range is configured correctly."""
assert Config.MIN_BIRTH_YEAR == 1940
assert Config.MAX_BIRTH_YEAR == 2010
assert Config.MIN_BIRTH_YEAR < Config.MAX_BIRTH_YEAR
class TestPathHelpers:
"""Tests for path helper functions."""
def test_get_application_path(self, app):
"""Test get_application_path returns correct 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."""
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."""
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."""
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('.')