""" Pure unit tests for ticket model constants and enums. No database or HTTP client needed — these guard the core business rules encoded directly in models/ticket.py so regressions are caught immediately. """ import pytest from models.ticket import TicketStatus, TicketPriority, ALLOWED_TRANSITIONS class TestTicketStatusEnum: def test_all_five_statuses_exist(self): values = {s.value for s in TicketStatus} assert values == {"OPEN", "ACKNOWLEDGED", "IN_PROGRESS", "RESOLVED", "CLOSED"} def test_status_string_coercion(self): assert TicketStatus("OPEN") is TicketStatus.OPEN assert TicketStatus("CLOSED") is TicketStatus.CLOSED class TestTicketPriorityEnum: def test_all_four_priorities_exist(self): values = {p.value for p in TicketPriority} assert values == {"P0", "P1", "P2", "P3"} def test_p0_is_highest(self): # Enum order is definitional; P0 comes before P3 priorities = [p.value for p in TicketPriority] assert priorities.index("P0") < priorities.index("P3") class TestAllowedTransitions: """ ALLOWED_TRANSITIONS defines the valid next-state set for each status. These rules are enforced in TicketService.update_ticket for non-admin users. """ def test_every_status_has_an_entry(self): for status in TicketStatus: assert status in ALLOWED_TRANSITIONS, f"{status} missing from ALLOWED_TRANSITIONS" def test_open_can_only_go_to_acknowledged(self): assert ALLOWED_TRANSITIONS[TicketStatus.OPEN] == [TicketStatus.ACKNOWLEDGED] def test_acknowledged_can_go_to_in_progress_or_revert_to_open(self): allowed = ALLOWED_TRANSITIONS[TicketStatus.ACKNOWLEDGED] assert TicketStatus.IN_PROGRESS in allowed assert TicketStatus.OPEN in allowed def test_in_progress_can_resolve_or_revert(self): allowed = ALLOWED_TRANSITIONS[TicketStatus.IN_PROGRESS] assert TicketStatus.RESOLVED in allowed assert TicketStatus.ACKNOWLEDGED in allowed def test_resolved_can_close_or_revert(self): allowed = ALLOWED_TRANSITIONS[TicketStatus.RESOLVED] assert TicketStatus.CLOSED in allowed assert TicketStatus.IN_PROGRESS in allowed def test_closed_is_terminal(self): assert ALLOWED_TRANSITIONS[TicketStatus.CLOSED] == [] def test_open_cannot_skip_to_resolved(self): assert TicketStatus.RESOLVED not in ALLOWED_TRANSITIONS[TicketStatus.OPEN] def test_open_cannot_skip_to_closed(self): assert TicketStatus.CLOSED not in ALLOWED_TRANSITIONS[TicketStatus.OPEN] def test_in_progress_cannot_go_directly_to_closed(self): assert TicketStatus.CLOSED not in ALLOWED_TRANSITIONS[TicketStatus.IN_PROGRESS] def test_all_transition_targets_are_valid_statuses(self): valid = set(TicketStatus) for src, targets in ALLOWED_TRANSITIONS.items(): for tgt in targets: assert tgt in valid, f"Invalid transition target {tgt} from {src}"