refactor(access): Update Test Suite for Contact model

ref: #839 #842
This commit is contained in:
2025-06-19 22:17:55 +09:30
parent e15bb11a76
commit 43490b7407
5 changed files with 58 additions and 63 deletions

View File

@ -1,14 +1,18 @@
import pytest
from access.models.contact import Contact
@pytest.fixture( scope = 'class')
def model(request):
def model(model_contact):
request.cls.model = Contact
yield model_contact
yield request.cls.model
@pytest.fixture( scope = 'class')
def model_kwargs(request, kwargs_contact):
del request.cls.model
request.cls.kwargs_create_item = kwargs_contact.copy()
yield kwargs_contact.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.person.test_unit_person_api_fields import (
PersonAPIInheritedCases
)
@pytest.mark.model_contact
class ContactAPITestCases(
PersonAPIInheritedCases,
):
@ -33,6 +36,7 @@ class ContactAPIInheritedCases(
@pytest.mark.module_access
class ContactAPIPyTest(
ContactAPITestCases,
):

View File

@ -9,14 +9,11 @@ from access.tests.unit.person.test_unit_person_model import (
@pytest.mark.model_contact
class ContactModelTestCases(
PersonModelInheritedCases,
):
kwargs_create_item: dict = {
'email': 'ipweird@unit.test',
}
sub_model_type = 'contact'
"""Sub Model Type
@ -24,55 +21,49 @@ class ContactModelTestCases(
"""
parameterized_fields: dict = {
"email": {
'field_type': models.fields.CharField,
'field_parameter_default_exists': False,
'field_parameter_verbose_name_type': str,
},
"directory": {
'field_type': models.fields.BooleanField,
'field_parameter_default_exists': True,
'field_parameter_default_value': True,
'field_parameter_verbose_name_type': str,
@property
def parameterized_class_attributes(self):
return {
'_is_submodel': {
'value': True
},
'url_model_name': {
'type': str,
'value': 'entity'
}
}
@property
def parameterized_fields(self):
return {
'directory': {
'blank': True,
'default': True,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'email': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.EmailField,
'null': False,
'unique': True,
},
}
}
def test_class_inherits_contact(self):
def test_class_inherits_contact(self, model):
""" Class inheritence
TenancyObject must inherit SaveHistory
"""
assert issubclass(self.model, Contact)
# 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 == 'access'
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 == 'contact'
def test_function_value_get_url(self):
assert self.item.get_url() == '/api/v2/access/entity/contact/' + str(self.item.id)
assert issubclass(model, Contact)
@ -83,28 +74,19 @@ class ContactModelInheritedCases(
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_access
class ContactModelPyTest(
ContactModelTestCases,
):
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,3 +1,5 @@
import pytest
from django.test import TestCase
from access.models.contact import Contact
@ -7,6 +9,7 @@ from access.tests.unit.person.test_unit_person_viewset import (
@pytest.mark.model_contact
class ViewsetTestCases(
PersonViewsetInheritedCases,
):
@ -28,6 +31,7 @@ class ContactViewsetInheritedCases(
@pytest.mark.module_access
class ContactViewsetTest(
ViewsetTestCases,
TestCase,

View File

@ -1107,6 +1107,7 @@ markers = [
"model_configgroups: Selects Config Group tests.",
"model_configgrouphosts: Selects Config Group Hosts tests.",
"model_configgroupsoftware: Selects Config Group Software tests.",
"model_contact: Selects test for model Contact.",
"model_cluster: Selects Cluster tests.",
"model_clustertype: Selects Cluster Type tests.",
"model_device: Select all Device tests",