refactor(access): Update Model Contact to use PyTest API Fields Render

ref: #761 #730
This commit is contained in:
2025-05-15 20:02:50 +09:30
parent 8e9dca56bc
commit 08dbe1e35b
3 changed files with 54 additions and 90 deletions

View File

@ -0,0 +1,14 @@
import pytest
from access.models.contact import Contact
@pytest.fixture( scope = 'class')
def model(request):
request.cls.model = Contact
yield request.cls.model
del request.cls.model

View File

@ -0,0 +1,40 @@
from access.tests.unit.person.test_unit_person_api_fields import (
PersonAPIInheritedCases
)
class ContactAPITestCases(
PersonAPIInheritedCases,
):
parameterized_test_data = {
'email': {
'expected': str
},
'directory': {
'expected': bool
}
}
kwargs_create_item: dict = {
'email': 'ipfunny@unit.test',
}
class ContactAPIInheritedCases(
ContactAPITestCases,
):
kwargs_create_item: dict = None
model = None
class ContactAPIPyTest(
ContactAPITestCases,
):
pass

View File

@ -1,90 +0,0 @@
from django.test import TestCase
from access.models.contact import Contact
from access.tests.unit.person.test_unit_person_api_v2 import (
PersonAPIInheritedCases,
)
class APITestCases(
PersonAPIInheritedCases,
):
model = Contact
kwargs_item_create: dict = {
'email': 'ipfunny@unit.test',
}
url_ns_name = '_api_v2_entity_sub'
def test_api_field_exists_email(self):
""" Test for existance of API Field
email field must exist
"""
assert 'email' in self.api_data
def test_api_field_type_email(self):
""" Test for type for API Field
email field must be str
"""
assert type(self.api_data['email']) is str
def test_api_field_exists_directory(self):
""" Test for existance of API Field
directory field must exist
"""
assert 'directory' in self.api_data
def test_api_field_type_directory(self):
""" Test for type for API Field
directory field must be bool
"""
assert type(self.api_data['directory']) is bool
class ContactAPIInheritedCases(
APITestCases,
):
"""Sub-Entity Test Cases
Test Cases for Entity models that inherit from model Contact
"""
kwargs_item_create: dict = None
model = None
@classmethod
def setUpTestData(self):
self.kwargs_item_create.update(
super().kwargs_item_create
)
super().setUpTestData()
class ContactAPITest(
APITestCases,
TestCase,
):
pass