Files
dtf-system/tests/test_schema.py
Cauê Faleiros 69997f4598 fix: the database starts again after an e-mail change notice exists
schema.sql defined the e-mail kinds constraint twice: the signup commit's
copy without "notice", and the e-mail change commit's with it. The schema
runs on every start, so once a "notice" e-mail existed the first copy was
refused and db-init restarted for ever. It is defined once now, and
tests/test_schema fails on any constraint added twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 13:18:21 -03:00

21 lines
774 B
Python

"""The schema runs on every start (app/bootstrap.py), so each constraint it
re-adds must be defined once: an earlier, narrower copy would refuse rows
written under a later one, and the database would never finish starting.
Run from the repository root: python3 -m unittest tests.test_schema
"""
import re
import unittest
from collections import Counter
from pathlib import Path
class SchemaTest(unittest.TestCase):
def test_each_constraint_is_added_once(self):
schema = Path(__file__).resolve().parent.parent.joinpath('app', 'schema.sql').read_text()
added = Counter(re.findall(r'ADD CONSTRAINT\s+(\w+)', schema, re.I))
self.assertEqual([name for name, count in added.items() if count > 1], [])
if __name__ == '__main__':
unittest.main()