intent/tests/test_core.py
Alec Perkins 950a4030ee Scaffold Phase 0: Django project, deploy config, base layout
Django 5.2 with dev/test/prod settings, SQLite tuned for Litestream
(WAL, IMMEDIATE transactions), ULID primary keys via a shared base
model, and a custom User model ahead of the first migration.

Minimal accessible base template with dark mode via color-scheme and
an optional theme picker. /healthz answers before host validation so
Fly checks pass.

Dockerfile (dev and prod targets), compose for local dev, fly.toml
with placeholder app/region, Litestream backups to B2, and a Forgejo
Actions workflow. Migrations run in bin/start because Fly release
machines don't mount volumes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 06:59:34 -04:00

38 lines
1.1 KiB
Python

import pytest
from django.contrib.auth import get_user_model
from ulid import ULID
from intent.core.models import new_ulid
def test_new_ulid_is_parseable_and_unique():
values = {new_ulid() for _ in range(1000)}
assert len(values) == 1000
for value in values:
assert len(value) == 26
assert str(ULID.from_str(value)) == value
@pytest.mark.django_db
def test_user_primary_key_is_ulid():
user = get_user_model().objects.create_user(username="ada")
assert len(user.pk) == 26
ULID.from_str(user.pk)
@pytest.mark.django_db
def test_healthz_ignores_host_validation(client, settings):
settings.ALLOWED_HOSTS = ["intent.example"]
response = client.get("/healthz", HTTP_HOST="172.19.0.2:8000")
assert response.status_code == 200
assert response.content == b"ok"
def test_home_has_accessible_shell(client):
response = client.get("/")
assert response.status_code == 200
html = response.content.decode()
assert '<html lang="en">' in html
assert '<meta name="color-scheme" content="light dark">' in html
assert 'href="#main"' in html
assert '<main id="main"' in html