Skip to content

Commit 12d6e16

Browse files
committed
feat(chapter7): add tests for Order priority setter and validation
1 parent 89114f3 commit 12d6e16

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

chapter07/tests/case03/test_case03.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,23 @@ def test_priority_comparison():
6262
order2 = Order(data2)
6363
# Priority 클래스 리팩토링 후 아래 테스트 활성화
6464
assert order1.priority.higher_than(order2.priority)
65+
66+
67+
def test_order_priority_setter():
68+
# 문자열로 priority 설정 테스트
69+
order = Order({"priority": "normal", "product": "Widget"})
70+
order.priority = "high"
71+
assert order.priority == Priority("high")
72+
73+
# Priority 객체로 priority 설정 테스트
74+
new_priority = Priority("rush")
75+
order.priority = new_priority
76+
assert order.priority == Priority("rush")
77+
assert order.priority == new_priority # 참조 동일성이 아닌 값 동일성 확인
78+
79+
# 잘못된 값에 대한 예외 발생 테스트
80+
try:
81+
order.priority = "invalid"
82+
assert False, "잘못된 우선순위 값이 허용되었습니다"
83+
except ValueError:
84+
pass # 예상대로 예외 발생

0 commit comments

Comments
 (0)