|
9 | 9 | """ |
10 | 10 |
|
11 | 11 | import pytest |
| 12 | +from pydantic import ValidationError |
12 | 13 |
|
13 | 14 | from src.domain.base.exceptions import DomainException |
14 | 15 | from src.domain.base.value_objects import InstanceId, ResourceId, ResourceQuota |
@@ -64,20 +65,20 @@ def test_value_object_immutability(self): |
64 | 65 | # Test InstanceId immutability with correct constructor |
65 | 66 | instance_id = InstanceId(value="i-1234567890abcdef0") |
66 | 67 |
|
67 | | - # Should not be able to modify value objects |
68 | | - with pytest.raises(AttributeError): # Pydantic ValidationError for frozen instances |
| 68 | + # Should not be able to modify value objects (Pydantic frozen instances) |
| 69 | + with pytest.raises(ValidationError): # Pydantic ValidationError for frozen instances |
69 | 70 | instance_id.value = "i-new-value" |
70 | 71 |
|
71 | 72 | # Test ResourceId immutability |
72 | 73 | resource_id = ResourceId(value="r-1234567890abcdef0") |
73 | 74 |
|
74 | | - with pytest.raises(AttributeError): |
| 75 | + with pytest.raises(ValidationError): |
75 | 76 | resource_id.value = "r-new-value" |
76 | 77 |
|
77 | 78 | # Test ResourceQuota immutability |
78 | 79 | quota = ResourceQuota(resource_type="instances", limit=10, used=5, available=5) |
79 | 80 |
|
80 | | - with pytest.raises(AttributeError): |
| 81 | + with pytest.raises(ValidationError): |
81 | 82 | quota.limit = 20 |
82 | 83 |
|
83 | 84 | def test_entity_identity_rules(self): |
@@ -145,14 +146,21 @@ def test_value_object_equality_and_hashing(self): |
145 | 146 | def test_domain_invariants_enforcement(self): |
146 | 147 | """Test that domain invariants are properly enforced.""" |
147 | 148 | # Test template invariants based on actual validation |
148 | | - with pytest.raises(ValueError, match="image_id is required"): |
| 149 | + with pytest.raises(ValidationError, match="Field required"): |
149 | 150 | Template( |
150 | | - template_id="test-template", |
151 | 151 | name="Test Template", |
152 | | - # Missing image_id - should fail validation |
| 152 | + # Missing template_id - should fail validation |
153 | 153 | subnet_ids=["subnet-12345"], |
154 | 154 | ) |
155 | 155 |
|
| 156 | + # Test max_instances validation |
| 157 | + with pytest.raises(ValueError, match="max_instances must be greater than 0"): |
| 158 | + Template( |
| 159 | + template_id="test-template", |
| 160 | + name="Test Template", |
| 161 | + max_instances=0, # Invalid value |
| 162 | + ) |
| 163 | + |
156 | 164 | # Test that max_instances must be positive - validation happens during construction |
157 | 165 | with pytest.raises(ValueError, match="max_instances must be greater than 0"): |
158 | 166 | Template( |
|
0 commit comments