#67_unittests_for_DTOs #69

Merged
brian merged 2 commits from #67_unittests_for_DTOs into main 2025-04-16 00:35:08 +02:00
Showing only changes of commit 06913064c3 - Show all commits
@@ -0,0 +1,46 @@
"""Definition of unittests for TypeCheckingBaseModel class."""
import unittest
import pytest
from pydantic import ValidationError
from shared.repositories.src.dto.type_checking_base_model import TypeCheckingBaseModel
class UUT(TypeCheckingBaseModel):
"""Test class for TypeCheckingBaseModel."""
string_field: str
int_field: int
class TestTypeCheckingBaseModel(unittest.TestCase):
"""Test class for TypeCheckingBaseModel."""
def setUp(self):
"""Set up the test case."""
self.uut = UUT
self.string_field = 'test'
self.int_field = 123
def test_type_checking_on_instantiation(self):
"""Test type checking on instantiation."""
with pytest.raises(ValidationError):
_ = self.uut(
string_field=self.int_field,
int_field=self.string_field,
)
def test_attributes_frozen(self):
"""Test that attributes cannot be updated."""
uut_instance = self.uut(
string_field=self.string_field,
int_field=self.int_field,
)
with pytest.raises(ValidationError):
uut_instance.string_field = self.int_field
if __name__ == '__main__':
pytest.main(['-s', '-v', __file__])