ploughshares/tests/test_app.py

65 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Test script for core app functionality.
"""
import os
import unittest
import sys
import importlib.util
class AppFunctionalityTests(unittest.TestCase):
"""Tests to verify core functionality of the Ploughshares app."""
def setUp(self):
"""Set up the test environment."""
self.project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
self.app_path = os.path.join(self.project_root, 'docker', 'ploughshares', 'app.py')
def test_app_imports(self):
"""Test that app.py imports all required modules."""
with open(self.app_path, 'r') as f:
content = f.read()
# Check for direct imports
direct_imports = [
'import os',
'import psycopg2',
'import locale'
]
# Check for from imports
from_imports = [
'from flask import',
'from datetime import'
]
for module in direct_imports:
self.assertIn(module, content,
f"app.py should have {module}")
for module in from_imports:
self.assertIn(module, content,
f"app.py should have {module}")
def test_app_routes(self):
"""Test that app.py defines all required routes."""
with open(self.app_path, 'r') as f:
content = f.read()
required_routes = [
"@app.route('/')",
"@app.route('/api-docs')",
"@app.route('/transaction/<int:id>')",
"@app.route('/transaction/add'",
"@app.route('/transaction/<int:id>/edit'"
]
for route in required_routes:
self.assertIn(route, content,
f"app.py should define route {route}")
if __name__ == '__main__':
unittest.main()