test(human_resources): APIv2, History, Model and ViewSet Unit test suites for employee

ref: #722 #684
This commit is contained in:
2025-04-15 15:22:56 +09:30
parent e71f7a6942
commit 559e65f990
5 changed files with 250 additions and 0 deletions

View File

@ -0,0 +1,73 @@
from django.test import TestCase
from access.tests.unit.contact.test_unit_contact_api_v2 import (
ContactAPIInheritedCases,
)
from human_resources.models.employee import Employee
class APITestCases(
ContactAPIInheritedCases,
):
model = Employee
kwargs_item_create: dict = {
'email': 'ipfunny@unit.test',
'employee_number': 123456,
}
url_ns_name = '_api_v2_entity_sub'
def test_api_field_exists_employee_number(self):
""" Test for existance of API Field
employee_number field must exist
"""
assert 'employee_number' in self.api_data
def test_api_field_type_employee_number(self):
""" Test for type for API Field
employee_number field must be str
"""
assert type(self.api_data['employee_number']) is int
class EmployeeAPIInheritedCases(
APITestCases,
):
"""Sub-Entity Test Cases
Test Cases for Entity models that inherit from model Employee
"""
kwargs_item_create: dict = None
model = None
@classmethod
def setUpTestData(self):
self.kwargs_item_create.update(
super().kwargs_item_create
)
super().setUpTestData()
class EmployeeAPITest(
APITestCases,
TestCase,
):
pass

View File

@ -0,0 +1,58 @@
from django.test import TestCase
from access.tests.unit.contact.test_unit_contact_history_api_v2 import (
ContactHistoryAPIInheritedCases
)
from human_resources.models.employee import Employee
class EmployeeModelHistoryAPITestCases(
ContactHistoryAPIInheritedCases,
):
""" Model Histoy Test Cases
Test must be setup by creating object `kwargs_create_audit_object` with the
attributes required to create the object.
"""
audit_model = Employee
kwargs_create_audit_object: dict = {
'email': 'ipfunny@unit.test',
'employee_number': 123456,
}
class EmployeeHistoryAPIInheritedCases(
EmployeeModelHistoryAPITestCases,
):
"""Sub-Entity Test Cases
Test Cases for Entity models that inherit from model Contact
"""
audit_model = None
kwargs_create_audit_object: dict = None
@classmethod
def setUpTestData(self):
self.kwargs_create_audit_object.update(
super().kwargs_create_audit_object
)
super().setUpTestData()
class EmployeeModelHistoryAPITest(
EmployeeModelHistoryAPITestCases,
TestCase,
):
pass

View File

@ -0,0 +1,81 @@
from django.db.models.fields import NOT_PROVIDED
from django.test import TestCase
from access.tests.unit.contact.test_unit_contact_model import (
Contact,
ContactModelInheritedCases
)
from human_resources.models.employee import Employee
class ModelTestCases(
ContactModelInheritedCases,
):
model = Employee
kwargs_item_create: dict = {
'email': 'ipweird@unit.test',
'employee_number': 123456,
}
def test_model_field_employee_number_mandatory(self):
"""Test Field
Field `employee_number` must be a mandatory field
"""
assert(
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):
"""Test model inheritence
model must inherit from Entity sub-model `Contact`
"""
assert issubclass(self.model, Contact)
class EmployeeModelInheritedCases(
ModelTestCases,
):
"""Sub-Entity Test Cases
Test Cases for Entity models that inherit from model Employee
"""
kwargs_item_create: dict = None
model = None
@classmethod
def setUpTestData(self):
self.kwargs_item_create.update(
super().kwargs_item_create
)
super().setUpTestData()
class EmployeeModelTest(
ModelTestCases,
TestCase,
):
pass

View File

@ -0,0 +1,38 @@
from django.test import TestCase
# from access.models.contact import Contact
from access.tests.unit.contact.test_unit_contact_viewset import (
ContactViewsetInheritedCases
)
from human_resources.models.employee import Employee
class ViewsetTestCases(
ContactViewsetInheritedCases,
):
model: str = Employee
class EmployeeViewsetInheritedCases(
ViewsetTestCases,
):
"""Sub-Entity Test Cases
Test Cases for Entity models that inherit from model Employee
"""
model: str = None
"""name of the model to test"""
class EmployeeViewsetTest(
ViewsetTestCases,
TestCase,
):
pass