bank-statement-api / scripts /check_rules_feature.py
Coeinterns's picture
Feat : Add Classification Rules Page
37c76c3
Raw History Blame Contribute Delete
3.03 kB
"""Quick verification script for the Rules feature implementation."""
import ast, os, sys
all_ok = True
def chk(label, passed):
global all_ok
if not passed:
all_ok = False
print(('OK ' if passed else 'FAIL') + ' ' + label)
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def read(rel):
return open(os.path.join(root, rel.replace('/', os.sep)), encoding='utf-8').read()
# Python parses
for f in ['routers/rule_requests.py', 'auth/rule_models.py', 'api_server.py']:
try:
ast.parse(read(f))
chk('parse: ' + f, True)
except SyntaxError as e:
chk('parse FAIL: ' + f + ' ' + str(e), False)
# Backend content
r = read('routers/rule_requests.py')
for t in [
'add_keyword', 'move_rule', 'move_category', 'delete_rule', 'delete_category',
'dest_category_id is required', 'dest_group_name is required',
'target.category_id = req.dest_category_id', 'cat.sheet_name = req.dest_group_name',
'An identical request is already pending',
]:
chk('rule_requests: ' + t[:50], t in r)
m = read('auth/rule_models.py')
for t in ['RuleChangeRequest', 'dest_category_id', 'dest_category_name', 'dest_group_name', 'to_dict']:
chk('rule_models: ' + t, t in m)
a = read('api_server.py')
for t in ['rule_requests_router', 'auth.rule_models']:
chk('api_server: ' + t, t in a)
# Frontend files exist
for f in [
'befree-frontend/features/rules/RulesFeature.tsx',
'befree-frontend/app/rules/page.tsx',
]:
chk('exists: ' + f.split('/')[-1], os.path.exists(os.path.join(root, f)))
# Frontend content
fe = read('befree-frontend/features/rules/RulesFeature.tsx')
for t in [
'RulesFeature', 'AdminRequestsPanel', 'MyRequestsPanel', 'RequestRuleForm',
'move_rule', 'move_category', 'delete_rule', 'delete_category',
'fixed inset-0 z-50', 'backdrop-blur-sm', 'selectedGroup', 'handleTypeChange',
'conflictMessage', 'Destination group', 'Destination category', 'Move to',
'dest_category_name', 'dest_group_name',
]:
chk('RulesFeature: ' + t[:40], t in fe)
# Sidebar
sb = read('befree-frontend/components/layout/Sidebar.tsx')
chk('Sidebar: BookOpen', 'BookOpen' in sb)
chk('Sidebar: /rules', '/rules' in sb)
# DB columns (optional — requires DB connection)
try:
from dotenv import load_dotenv
load_dotenv(os.path.join(root, '.env'))
sys.path.insert(0, root)
from auth.database import engine
from sqlalchemy import text
with engine.connect() as conn:
rows = conn.execute(text(
"SELECT column_name FROM information_schema.columns "
"WHERE table_name = 'rule_change_requests' ORDER BY ordinal_position"
)).fetchall()
cols = [r[0] for r in rows]
for col in ['dest_category_id', 'dest_category_name', 'dest_group_name']:
chk('DB column: ' + col, col in cols)
except Exception as e:
print('SKIP DB check: ' + str(e))
print()
print('ALL IMPLEMENTED' if all_ok else 'GAPS FOUND — see FAIL lines above')
sys.exit(0 if all_ok else 1)