refactor(access): Update Test Suite for Employee model

ref: #839 #843
This commit is contained in:
2025-06-19 22:26:55 +09:30
parent 3ea44aaabe
commit bc3545d53e
7 changed files with 81 additions and 57 deletions

View File

@ -1,14 +1,18 @@
import pytest
from human_resources.models.employee import Employee
@pytest.fixture( scope = 'class')
def model(request):
def model(model_employee):
request.cls.model = Employee
yield model_employee
yield request.cls.model
@pytest.fixture( scope = 'class')
def model_kwargs(request, kwargs_employee):
del request.cls.model
request.cls.kwargs_create_item = kwargs_employee.copy()
yield kwargs_employee.copy()
if hasattr(request.cls, 'kwargs_create_item'):
del request.cls.kwargs_create_item

View File

@ -1,9 +1,12 @@
import pytest
from access.tests.unit.contact.test_unit_contact_api_fields import (
ContactAPIInheritedCases
)
@pytest.mark.model_employee
class EmployeeAPITestCases(
ContactAPIInheritedCases,
):
@ -30,6 +33,7 @@ class EmployeeAPIInheritedCases(
@pytest.mark.module_human_resources
class EmployeeAPIPyTest(
EmployeeAPITestCases,
):

View File

@ -10,64 +10,53 @@ from human_resources.models.employee import Employee
@pytest.mark.model_employee
class EmployeeModelTestCases(
ContactModelInheritedCases,
):
kwargs_create_item: dict = {
'employee_number': 12345,
}
sub_model_type = 'employee'
"""Sub Model Type
sub-models must have this attribute defined in `ModelName.Meta.sub_model_type`
"""
@property
def parameterized_class_attributes(self):
parameterized_fields: dict = {
"employee_number": {
'field_type': models.fields.IntegerField,
'field_parameter_default_exists': False,
'field_parameter_verbose_name_type': str,
return {
'_is_submodel': {
'value': True
},
'url_model_name': {
'type': str,
'value': 'entity'
}
}
@property
def parameterized_fields(self):
return {
'employee_number': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.IntegerField,
'null': False,
'unique': True,
},
}
}
def test_class_inherits_employee(self):
def test_class_inherits_employee(self, model):
""" Class inheritence
TenancyObject must inherit SaveHistory
"""
assert issubclass(self.model, Employee)
def test_attribute_value_history_app_label(self):
"""Attribute Type
history_app_label has been set, override this test case with the value
of attribute `history_app_label`
"""
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)
assert issubclass(model, Employee)
@ -78,28 +67,20 @@ class EmployeeModelInheritedCases(
Test Cases for Ticket models that inherit from model Entity
"""
kwargs_create_item: dict = {}
model = None
sub_model_type = None
"""Ticket Sub Model Type
Ticket sub-models must have this attribute defined in `ModelNam.Meta.sub_model_type`
"""
pass
@pytest.mark.module_human_resources
class EmployeeModelPyTest(
EmployeeModelTestCases,
):
def test_function_value_get_related_model(self):
def test_function_value_get_related_model(self, model_instance):
"""Function test
Confirm function `get_related_model` is None for base model
"""
assert self.item.get_related_model() is None
assert model_instance.get_related_model() is None

View File

@ -1,6 +1,7 @@
import pytest
from django.test import TestCase
# from access.models.contact import Contact
from access.tests.unit.contact.test_unit_contact_viewset import (
ContactViewsetInheritedCases
)
@ -9,6 +10,7 @@ from human_resources.models.employee import Employee
@pytest.mark.model_employee
class ViewsetTestCases(
ContactViewsetInheritedCases,
):
@ -30,6 +32,7 @@ class EmployeeViewsetInheritedCases(
@pytest.mark.module_human_resources
class EmployeeViewsetTest(
ViewsetTestCases,
TestCase,

View File

@ -112,6 +112,11 @@ from .model_devicetype import (
model_devicetype,
)
from .model_employee import (
kwargs_employee,
model_employee,
)
from .model_entity import (
kwargs_entity,
model_entity,

26
app/tests/fixtures/model_employee.py vendored Normal file
View File

@ -0,0 +1,26 @@
import datetime
import pytest
from human_resources.models.employee import Employee
@pytest.fixture( scope = 'class')
def model_employee():
yield Employee
@pytest.fixture( scope = 'class')
def kwargs_employee( kwargs_contact ):
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
random_str = str(random_str).replace(
' ', '').replace(':', '').replace('+', '').replace('.', '').replace('-', '')
kwargs = {
**kwargs_contact.copy(),
'employee_number': random_str
}
yield kwargs.copy()

View File

@ -1115,6 +1115,7 @@ markers = [
"model_deviceoperatingsystem: Select tests for model Device Operating System",
"model_devicesoftware: Select tests for model Device Software.",
"model_devicetype: Select all device type tests.",
"model_employee: Selects test for model Employee.",
"model_externallink: Select tests for model External Link.",
"model_featureflag: Feature Flag Model",
"model_gitgroup: Selects tests for model `git group`",