forked from ChelseaKR/habitable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_usecases.py
More file actions
73 lines (58 loc) · 2.5 KB
/
Copy pathtest_usecases.py
File metadata and controls
73 lines (58 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright 2026 Chelsea Kelly-Reif
from __future__ import annotations
from dataclasses import replace
from datetime import date
import pytest
from habitable.errors import HabitableError
from habitable.usecases import (
ARTIFACT_TYPES,
RELATIONSHIP_TYPES,
get_profile,
list_profiles,
profile_expired,
)
def test_all_ten_profiles_are_versioned_and_valid() -> None:
profiles = list_profiles()
assert len(profiles) == 10
assert len({profile.profile_id for profile in profiles}) == 10
for profile in profiles:
assert profile.version == 1
assert profile.name_en and profile.name_es
assert set(profile.artifact_types) <= ARTIFACT_TYPES
assert set(profile.relationship_types) <= RELATIONSHIP_TYPES
payload = profile.to_json()
assert payload["profile_id"] == profile.profile_id
assert payload["review_state"] in {"maintainer_reviewed", "external_review_required"}
def test_sensitive_profiles_keep_external_review_gate() -> None:
for profile_id in (
"inspector_handoff",
"accommodation_request",
"public_housing_remediation",
"health_corroboration",
"building_pattern",
"partner_capsule",
):
assert get_profile(profile_id).external_review_required
def test_unknown_profile_fails_closed() -> None:
with pytest.raises(HabitableError, match="unknown use-case profile"):
get_profile("not-real")
def test_no_shipped_profile_expires_today() -> None:
# None of the ten built-in profiles sets expires_at yet; this is
# forward-looking infrastructure for jurisdiction/community profiles, not a
# behavior change for what ships today.
for profile in list_profiles():
assert profile.expires_at == ""
assert not profile_expired(profile)
def test_profile_expired_compares_calendar_dates() -> None:
base = get_profile("repair_delivery")
never_expires = replace(base, expires_at="")
expires_tomorrow = replace(base, expires_at="2026-08-23")
expires_today = replace(base, expires_at="2026-08-22")
expired_yesterday = replace(base, expires_at="2026-08-21")
today = date(2026, 8, 22)
assert not profile_expired(never_expires, today=today)
assert not profile_expired(expires_tomorrow, today=today)
# A profile expires at the start of its named day, not partway through it.
assert profile_expired(expires_today, today=today)
assert profile_expired(expired_yesterday, today=today)