added unittests for repositories DTO base class
Code Quality Pipeline / Check Code (pull_request) Successful in 2m44s
Code Quality Pipeline / Check Code (pull_request) Successful in 2m44s
This commit is contained in:
@@ -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__])
|
||||||
Reference in New Issue
Block a user