42 lines
1002 B
Python
42 lines
1002 B
Python
"""Tests for Organization / Project invariants."""
|
|
|
|
from datetime import datetime, timezone
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from asf_domain import (
|
|
Organization,
|
|
OrganizationCreate,
|
|
Project,
|
|
ProjectCreate,
|
|
)
|
|
|
|
|
|
NOW = datetime(2026, 9, 7, 12, 0, 0, tzinfo=timezone.utc)
|
|
|
|
|
|
def test_organization_create_validates_slug() -> None:
|
|
OrganizationCreate(name="Contoso", slug="contoso-retail")
|
|
with pytest.raises(ValidationError):
|
|
OrganizationCreate(name="Bad", slug="UPPERCASE no!")
|
|
|
|
|
|
def test_project_create_validates_key_uppercase() -> None:
|
|
ProjectCreate(name="ASF Core", key="ASF")
|
|
with pytest.raises(ValidationError):
|
|
ProjectCreate(name="Bad", key="lowercase")
|
|
|
|
|
|
def test_project_scoped_under_tenant() -> None:
|
|
tenant_id = uuid4()
|
|
p = Project(
|
|
tenant_id=tenant_id,
|
|
name="ASF Web",
|
|
key="WEB",
|
|
created_at=NOW,
|
|
updated_at=NOW,
|
|
)
|
|
assert p.tenant_id == tenant_id
|