39 lines
1.1 KiB
Python
39 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
|