@@ -80,6 +80,36 @@ def create_sitemaps(data: dict[str, dict], parent: Sitemap = None) -> None:
8080 }
8181
8282
83+ @pytest .mark .parametrize (
84+ argnames = ["route_code" , "should_raise" ],
85+ argvalues = [
86+ ("valid_route" , False ),
87+ ("" , False ),
88+ ("/invalid_route" , True ), # 슬래시로 시작
89+ ("valid_route_123" , False ),
90+ ("valid-route" , False ),
91+ ("valid_route_123!" , True ), # 특수문자 포함
92+ ("valid_route_123@" , True ), # 특수문자 포함
93+ ],
94+ )
95+ @pytest .mark .django_db
96+ def test_route_code_validation (route_code : str , should_raise : bool ):
97+ # Given: Sitemap 객체 생성
98+ sitemap = Sitemap (
99+ route_code = route_code ,
100+ name = "Test Sitemap" ,
101+ page = Page .objects .create (title = "Test Page" , subtitle = "Test Subtitle" ),
102+ )
103+
104+ # When: Validation을 수행
105+ if should_raise :
106+ with pytest .raises (ValidationError ) as excinfo :
107+ sitemap .clean ()
108+ assert excinfo .value == "route_code는 알파벳, 숫자, 언더바(_)로만 구성되어야 합니다."
109+ else :
110+ sitemap .clean ()
111+
112+
83113@pytest .mark .django_db
84114def test_clean_should_check_for_self_reference ():
85115 # Given: Sitemap 객체 생성
@@ -95,7 +125,7 @@ def test_clean_should_check_for_self_reference():
95125 # Then: ValidationError가 발생해야 한다.
96126 with pytest .raises (ValidationError ) as excinfo :
97127 sitemap .clean ()
98- assert str ( excinfo .value ) == "자기 자신을 부모로 설정할 수 없습니다."
128+ assert excinfo .value == "자기 자신을 부모로 설정할 수 없습니다."
99129
100130
101131@pytest .mark .django_db
@@ -127,7 +157,7 @@ def test_clean_should_check_for_circular_reference():
127157 # Then: ValidationError가 발생해야 한다.
128158 with pytest .raises (ValidationError ) as excinfo :
129159 root_sitemap .clean ()
130- assert str ( excinfo .value ) == "Parent Sitemap이 자식 Sitemap을 가리킬 수 없습니다."
160+ assert excinfo .value == "Parent Sitemap이 자식 Sitemap을 가리킬 수 없습니다."
131161
132162
133163@pytest .mark .django_db
@@ -149,4 +179,4 @@ def test_clean_should_check_for_existing_route():
149179 # Then: ValidationError가 발생해야 한다.
150180 with pytest .raises (ValidationError ) as excinfo :
151181 new_sitemap .clean ()
152- assert str ( excinfo .value ) == "`existing`라우트는 이미 존재하는 route입니다."
182+ assert excinfo .value == "`existing`라우트는 이미 존재하는 route입니다."
0 commit comments