refactor(human_resources): Update Model Employee to use PyTest for Model Test Suite

ref: #761 #730
This commit is contained in:
2025-05-15 22:15:43 +09:30
parent 3c19e9d4cf
commit c2a367bd28

View File

@ -1,8 +1,8 @@
from django.db.models.fields import NOT_PROVIDED import pytest
from django.test import TestCase
from django.db import models
from access.tests.unit.contact.test_unit_contact_model import ( from access.tests.unit.contact.test_unit_contact_model import (
Contact,
ContactModelInheritedCases ContactModelInheritedCases
) )
@ -10,72 +10,96 @@ from human_resources.models.employee import Employee
class ModelTestCases( class EmployeeModelTestCases(
ContactModelInheritedCases, ContactModelInheritedCases,
): ):
model = Employee kwargs_create_item: dict = {
'employee_number': 12345,
}
kwargs_item_create: dict = { sub_model_type = 'employee'
'email': 'ipweird@unit.test', """Sub Model Type
'employee_number': 123456,
sub-models must have this attribute defined in `ModelName.Meta.sub_model_type`
"""
parameterized_fields: dict = {
"employee_number": {
'field_type': models.fields.IntegerField,
'field_parameter_default_exists': False,
'field_parameter_verbose_name_type': str,
}
} }
def test_model_field_employee_number_mandatory(self): def test_class_inherits_employee(self):
"""Test Field """ Class inheritence
Field `employee_number` must be a mandatory field TenancyObject must inherit SaveHistory
""" """
assert( assert issubclass(self.model, Employee)
not (
self.model._meta.get_field('employee_number').blank
and self.model._meta.get_field('employee_number').null
)
and self.model._meta.get_field('employee_number').default is NOT_PROVIDED
)
def test_model_inherits_contact(self): def test_attribute_value_history_app_label(self):
"""Test model inheritence """Attribute Type
model must inherit from Entity sub-model `Contact` history_app_label has been set, override this test case with the value
of attribute `history_app_label`
""" """
assert issubclass(self.model, Contact) assert self.model.history_app_label == 'human_resources'
def test_attribute_value_history_model_name(self):
"""Attribute Type
history_model_name has been set, override this test case with the value
of attribute `history_model_name`
"""
assert self.model.history_model_name == 'employee'
def test_function_value_get_url(self):
assert self.item.get_url() == '/api/v2/access/entity/employee/' + str(self.item.id)
class EmployeeModelInheritedCases( class EmployeeModelInheritedCases(
ModelTestCases, EmployeeModelTestCases,
): ):
"""Sub-Entity Test Cases """Sub-Ticket Test Cases
Test Cases for Entity models that inherit from model Employee Test Cases for Ticket models that inherit from model Entity
""" """
kwargs_item_create: dict = None kwargs_create_item: dict = {}
model = None model = None
sub_model_type = None
"""Ticket Sub Model Type
@classmethod Ticket sub-models must have this attribute defined in `ModelNam.Meta.sub_model_type`
def setUpTestData(self): """
self.kwargs_item_create.update(
super().kwargs_item_create
)
super().setUpTestData()
class EmployeeModelTest( class EmployeeModelPyTest(
ModelTestCases, EmployeeModelTestCases,
TestCase,
): ):
pass
def test_function_value_get_related_model(self):
"""Function test
Confirm function `get_related_model` is None for base model
"""
assert self.item.get_related_model() is None