guardia-itsm/tests/unit/test_models.py
2026-06-01 19:59:36 +09:00

95 lines
3.6 KiB
Python

"""GUARDiA ITSM 단위 테스트 — Pydantic 모델 검증"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
import pytest
from models import (
SRCreate, SRStatusUpdate, SRType, SRStatus, Priority,
InstitutionCreate, ScrapingTargetCreate,
)
class TestSRCreate:
def test_valid_sr_create(self):
sr = SRCreate(title="서버 장애 점검", requested_by="admin")
assert sr.title == "서버 장애 점검"
assert sr.requested_by == "admin"
assert sr.priority == Priority.MEDIUM
assert sr.sr_type == SRType.OTHER
def test_sr_create_with_priority(self):
sr = SRCreate(title="긴급 배포", requested_by="admin",
priority=Priority.CRITICAL, sr_type=SRType.DEPLOY)
assert sr.priority == Priority.CRITICAL
assert sr.sr_type == SRType.DEPLOY
def test_sr_create_optional_fields(self):
sr = SRCreate(title="테스트", requested_by="user")
assert sr.description is None
assert sr.assigned_to is None
def test_sr_type_enum_values(self):
assert SRType.DEPLOY == "DEPLOY"
assert SRType.RESTART == "RESTART"
assert SRType.LOG == "LOG"
assert SRType.INQUIRY == "INQUIRY"
assert SRType.OTHER == "OTHER"
def test_priority_enum_values(self):
assert Priority.CRITICAL == "CRITICAL"
assert Priority.HIGH == "HIGH"
assert Priority.MEDIUM == "MEDIUM"
assert Priority.LOW == "LOW"
class TestSRStatusUpdate:
def test_valid_status_update(self):
upd = SRStatusUpdate(status=SRStatus.APPROVED, actor="admin")
assert upd.status == SRStatus.APPROVED
assert upd.actor == "admin"
def test_status_with_comment(self):
upd = SRStatusUpdate(status=SRStatus.REJECTED, actor="admin", comment="요건 미충족")
assert upd.comment == "요건 미충족"
def test_optional_comment_default_none(self):
upd = SRStatusUpdate(status=SRStatus.APPROVED, actor="admin")
assert upd.comment is None
def test_sr_status_transitions(self):
for s in [SRStatus.RECEIVED, SRStatus.APPROVED, SRStatus.IN_PROGRESS,
SRStatus.COMPLETED, SRStatus.REJECTED]:
upd = SRStatusUpdate(status=s, actor="system")
assert upd.status == s
class TestInstitutionCreate:
def test_valid_institution(self):
inst = InstitutionCreate(inst_code="INST001", inst_name="테스트기관")
assert inst.inst_code == "INST001"
assert inst.inst_name == "테스트기관"
def test_institution_optional_fields(self):
inst = InstitutionCreate(inst_code="INST002", inst_name="기관2")
assert inst.org_type is None
assert inst.contact_pm is None
def test_institution_with_fields(self):
inst = InstitutionCreate(inst_code="INST003", inst_name="전체기관",
org_type="공공기관", contact_pm="홍길동")
assert inst.org_type == "공공기관"
class TestScrapingTargetCreate:
def test_valid_scraping_target(self):
target = ScrapingTargetCreate(name="뉴스 수집", url="https://example.com")
assert target.name == "뉴스 수집"
assert target.url == "https://example.com"
assert target.is_active is True
def test_scraping_target_with_selector(self):
target = ScrapingTargetCreate(name="기사", url="https://news.co.kr",
selector=".article-content", schedule="0 9 * * *")
assert target.selector == ".article-content"
assert target.schedule == "0 9 * * *"