From 08dbe1e35b31f4a52b9a220e6145f20677b47f1b Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 15 May 2025 20:02:50 +0930 Subject: [PATCH] refactor(access): Update Model Contact to use PyTest API Fields Render ref: #761 #730 --- app/access/tests/unit/contact/conftest.py | 14 +++ .../contact/test_unit_contact_api_fields.py | 40 +++++++++ .../unit/contact/test_unit_contact_api_v2.py | 90 ------------------- 3 files changed, 54 insertions(+), 90 deletions(-) create mode 100644 app/access/tests/unit/contact/conftest.py create mode 100644 app/access/tests/unit/contact/test_unit_contact_api_fields.py delete mode 100644 app/access/tests/unit/contact/test_unit_contact_api_v2.py diff --git a/app/access/tests/unit/contact/conftest.py b/app/access/tests/unit/contact/conftest.py new file mode 100644 index 00000000..ed285d51 --- /dev/null +++ b/app/access/tests/unit/contact/conftest.py @@ -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 diff --git a/app/access/tests/unit/contact/test_unit_contact_api_fields.py b/app/access/tests/unit/contact/test_unit_contact_api_fields.py new file mode 100644 index 00000000..5558f4e2 --- /dev/null +++ b/app/access/tests/unit/contact/test_unit_contact_api_fields.py @@ -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 diff --git a/app/access/tests/unit/contact/test_unit_contact_api_v2.py b/app/access/tests/unit/contact/test_unit_contact_api_v2.py deleted file mode 100644 index 18a706c4..00000000 --- a/app/access/tests/unit/contact/test_unit_contact_api_v2.py +++ /dev/null @@ -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