test: add dev stack integration checks
api-ci-deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-05-27 23:24:28 +01:00
parent 60bd2892d4
commit abe518a003
8 changed files with 384 additions and 4450 deletions
+53
View File
@@ -0,0 +1,53 @@
import os
import requests
def _supabase_headers():
key = os.getenv('SERVICE_ROLE_KEY') or os.getenv('ANON_KEY')
assert key, 'SERVICE_ROLE_KEY or ANON_KEY must be set for Supabase integration tests'
return {
'apikey': key,
'Authorization': f'Bearer {key}',
'Prefer': 'count=exact',
}
def _rest_count(table: str) -> int:
supabase_url = os.getenv('SUPABASE_URL')
assert supabase_url, 'SUPABASE_URL must be set'
response = requests.get(
f'{supabase_url.rstrip("/")}/rest/v1/{table}',
headers=_supabase_headers(),
params={'select': 'id'},
timeout=15,
)
assert response.status_code in (200, 206), response.text[:500]
content_range = response.headers.get('content-range', '')
assert '/' in content_range, f'missing exact content-range count for {table}: {content_range!r}'
return int(content_range.rsplit('/', 1)[1])
def test_dev_environment_points_at_dev_supabase():
assert os.getenv('SUPABASE_URL') == 'http://192.168.0.94:8000'
def test_dev_api_health_endpoint_is_healthy():
health_url = os.getenv('API_HEALTH_URL', 'http://192.168.0.64:18000/health')
response = requests.get(health_url, timeout=15)
assert response.status_code == 200
payload = response.json()
assert payload['status'] == 'healthy'
assert payload['services']['supabase']['status'] == 'healthy'
assert payload['services']['redis']['status'] == 'healthy'
def test_supabase_dev_seed_core_counts():
assert _rest_count('profiles') == 21
assert _rest_count('institute_memberships') == 21
assert _rest_count('institutes') == 2
def test_supabase_dev_seed_timetable_counts():
assert _rest_count('classes') == 17
assert _rest_count('taught_lessons') == 1462
+34
View File
@@ -0,0 +1,34 @@
import os
from neo4j import GraphDatabase
def test_cc_users_database_is_populated_from_seed_profiles():
url = os.getenv('APP_BOLT_URL')
user = os.getenv('USER_NEO4J')
password = os.getenv('PASSWORD_NEO4J')
assert url and user and password
with GraphDatabase.driver(url, auth=(user, password)) as driver:
with driver.session(database='cc.users') as session:
result = session.run('''
CALL { MATCH (u:User) RETURN count(u) AS users }
CALL { MATCH (u:User {user_type: 'teacher'}) RETURN count(u) AS teachers }
CALL { MATCH (u:User {user_type: 'student'}) RETURN count(u) AS students }
CALL { MATCH (:User)-[r:MEMBER_OF]->(:Institute) RETURN count(r) AS memberships }
CALL { MATCH (i:Institute) RETURN count(i) AS institutes }
CALL {
MATCH (bad:User)
WHERE bad.uuid_string IS NULL OR bad.user_email IS NULL OR bad.cc_username IS NULL
OR bad.user_type IS NULL OR bad.user_name IS NULL OR bad.user_db_name IS NULL
RETURN count(bad) AS bad_users
}
RETURN users, teachers, students, memberships, institutes, bad_users
''').single()
assert dict(result) == {
'users': 21,
'teachers': 15,
'students': 6,
'memberships': 21,
'institutes': 2,
'bad_users': 0,
}