-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathchecks.py
More file actions
134 lines (95 loc) · 3.14 KB
/
checks.py
File metadata and controls
134 lines (95 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
"""
Quick sanity checks - run before deploying.
No frameworks, no mocking, just real code paths.
Usage:
uv run python checks.py
uv run python checks.py -v # verbose
"""
import sys
import warnings
# Suppress passlib pkg_resources deprecation warning
warnings.filterwarnings("ignore", message="pkg_resources is deprecated")
VERBOSE = "-v" in sys.argv
PASSED = 0
FAILED = 0
def check(name):
"""Decorator to register a check"""
def decorator(f):
def wrapper(app):
global PASSED, FAILED
try:
f(app)
PASSED += 1
print(f" \033[32m✓\033[0m {name}")
return True
except Exception as e:
FAILED += 1
print(f" \033[31m✗\033[0m {name}")
if VERBOSE:
print(f" → {e}")
return False
wrapper._check_name = name
return wrapper
return decorator
# =============================================================================
# CHECKS
# =============================================================================
@check("App boots without errors")
def check_app_boots(app):
assert app is not None
assert app.config["SECRET_KEY"]
@check("Database connection works")
def check_database(app):
from enferno.extensions import db
with app.app_context():
db.session.execute(db.text("SELECT 1"))
@check("User model loads")
def check_user_model(app):
from enferno.user.models import User
with app.app_context():
User.query.limit(1).all()
@check("Role model loads")
def check_role_model(app):
from enferno.user.models import Role
with app.app_context():
Role.query.limit(1).all()
@check("All blueprints register")
def check_blueprints(app):
blueprints = list(app.blueprints.keys())
required = ["users", "public", "portal"]
for bp in required:
assert bp in blueprints, f"Missing blueprint: {bp}"
@check("Critical routes exist")
def check_routes(app):
rules = [r.rule for r in app.url_map.iter_rules()]
critical_routes = [
"/",
"/login",
"/dashboard/",
]
for route in critical_routes:
assert route in rules, f"Missing route: {route}"
@check("Security config is sane")
def check_security_config(app):
assert app.config["SECURITY_PASSWORD_LENGTH_MIN"] >= 8
assert app.config["SESSION_USE_SIGNER"] is True
# =============================================================================
# RUNNER
# =============================================================================
def run_checks():
from enferno.app import create_app
print("\n\033[1mRunning checks...\033[0m\n")
app = create_app()
checks = [v for v in globals().values() if hasattr(v, "_check_name")]
for check_fn in checks:
check_fn(app)
print()
if FAILED == 0:
print(f"\033[32m\033[1m✓ All {PASSED} checks passed\033[0m\n")
return 0
else:
print(f"\033[31m\033[1m✗ {FAILED}/{PASSED + FAILED} checks failed\033[0m\n")
return 1
if __name__ == "__main__":
sys.exit(run_checks())