diff --git a/app/access/tests/functional/tenancy_abstract/conftest.py b/app/access/tests/functional/tenancy_abstract/conftest.py index 11397277..48a5b1b8 100644 --- a/app/access/tests/functional/tenancy_abstract/conftest.py +++ b/app/access/tests/functional/tenancy_abstract/conftest.py @@ -1,10 +1,18 @@ import pytest -from access.models.tenancy_abstract import TenancyAbstractModel - @pytest.fixture( scope = 'class') -def model(request): +def model(model_tenancyabstract): - yield TenancyAbstractModel + yield model_tenancyabstract + + +@pytest.fixture( scope = 'class') +def model_kwargs(request, kwargs_tenancyabstract): + + request.cls.kwargs_create_item = kwargs_tenancyabstract.copy() + + yield kwargs_tenancyabstract.copy() + + del request.cls.kwargs_create_item diff --git a/app/access/tests/functional/tenancy_abstract/test_functional_tenancy_abstract_model.py b/app/access/tests/functional/tenancy_abstract/test_functional_tenancy_abstract_model.py index aa722d67..0de3d128 100644 --- a/app/access/tests/functional/tenancy_abstract/test_functional_tenancy_abstract_model.py +++ b/app/access/tests/functional/tenancy_abstract/test_functional_tenancy_abstract_model.py @@ -11,13 +11,8 @@ class TenancyAbstractModelTestCases( - kwargs_create_item = { - 'organization': 'set by fixture - setup_organization' - } - - @pytest.fixture( scope = 'class', autouse = True) - def setup_organization(cls, request, model, organization_one): + def setup_organization(cls, request, model, organization_one, model_kwargs): request.cls.organization = organization_one diff --git a/app/access/tests/unit/tenancy_abstract/conftest.py b/app/access/tests/unit/tenancy_abstract/conftest.py index 11397277..48a5b1b8 100644 --- a/app/access/tests/unit/tenancy_abstract/conftest.py +++ b/app/access/tests/unit/tenancy_abstract/conftest.py @@ -1,10 +1,18 @@ import pytest -from access.models.tenancy_abstract import TenancyAbstractModel - @pytest.fixture( scope = 'class') -def model(request): +def model(model_tenancyabstract): - yield TenancyAbstractModel + yield model_tenancyabstract + + +@pytest.fixture( scope = 'class') +def model_kwargs(request, kwargs_tenancyabstract): + + request.cls.kwargs_create_item = kwargs_tenancyabstract.copy() + + yield kwargs_tenancyabstract.copy() + + del request.cls.kwargs_create_item diff --git a/app/access/tests/unit/tenancy_abstract/test_unit_tenancy_abstract_model.py b/app/access/tests/unit/tenancy_abstract/test_unit_tenancy_abstract_model.py index 26c27251..d24eead4 100644 --- a/app/access/tests/unit/tenancy_abstract/test_unit_tenancy_abstract_model.py +++ b/app/access/tests/unit/tenancy_abstract/test_unit_tenancy_abstract_model.py @@ -15,10 +15,6 @@ class TenancyAbstractModelTestCases( ): - - kwargs_create_item = {} - - parameterized_class_attributes = { 'context': { 'type': dict, @@ -42,7 +38,7 @@ class TenancyAbstractModelTestCases( @pytest.fixture( scope = 'class', autouse = True) - def setup_organization(cls, request, model, organization_one): + def setup_organization(cls, request, model, organization_one, model_kwargs): request.cls.organization = organization_one diff --git a/app/centurion/tests/unit_models.py b/app/centurion/tests/unit_models.py index 62fb24f4..791f59dc 100644 --- a/app/centurion/tests/unit_models.py +++ b/app/centurion/tests/unit_models.py @@ -98,7 +98,7 @@ class ModelTestCases( @pytest.fixture( scope = 'class', autouse = True) - def setup_class(cls, request, model): + def setup_class(cls, request, model, model_kwargs): pass diff --git a/app/conftest.py b/app/conftest.py index 12be8130..603314a6 100644 --- a/app/conftest.py +++ b/app/conftest.py @@ -11,9 +11,9 @@ from django.test import ( TestCase ) -from access.models.tenant import Tenant +from tests.fixtures import * -from settings.models.app_settings import AppSettings +from access.models.tenant import Tenant User = django.contrib.auth.get_user_model() @@ -270,15 +270,6 @@ def pytest_generate_tests(metafunc): -@pytest.fixture( scope = 'class') -def content_type(): - - from django.contrib.contenttypes.models import ContentType - - yield ContentType - - - @pytest.fixture( scope = 'class') def create_model(request, django_db_blocker): @@ -591,17 +582,6 @@ def organization_three(django_db_blocker): -@pytest.fixture( scope = 'class') -def permission(): - - from django.contrib.auth.models import ( - Permission, - ) - - yield Permission - - - @pytest.fixture def recursearray() -> dict[dict, str, any]: """Recursive dict lookup @@ -776,15 +756,12 @@ def fake_view(): @pytest.fixture(scope = 'class') -def user(django_db_blocker): +def user(django_db_blocker, model_user, kwargs_user): with django_db_blocker.unblock(): - random_str = str(datetime.datetime.now(tz=datetime.timezone.utc)) - - user = User.objects.create( - username="test_user-" + random_str, - password="password" + user = model_user.objects.create( + **kwargs_user ) yield user @@ -795,176 +772,4 @@ def user(django_db_blocker): -@pytest.fixture( scope = 'class') -def api_user_permissions( django_db_blocker, - content_type, - model, - organization_one, - organization_two, - organization_three, - permission, -): - - with django_db_blocker.unblock(): - - - random_str = datetime.datetime.now(tz=datetime.timezone.utc) - - app_settings = AppSettings.objects.get( - owner_organization = None - ) - - app_settings.global_organization = organization_three - - app_settings.save() - - - - add_permissions = permission.objects.get( - codename = 'add_' + model._meta.model_name, - content_type = content_type.objects.get( - app_label = model._meta.app_label, - model = model._meta.model_name, - ) - ) - - add_team = Team.objects.create( - team_name = 'add_team' + str(random_str), - organization = organization_one, - ) - - add_team.permissions.set([add_permissions]) - - add_user = User.objects.create_user(username="test_user_add" + str(random_str), password="password") - - TeamUsers.objects.create( - team = add_team, - user = add_user - ) - - - - change_permissions = permission.objects.get( - codename = 'change_' + model._meta.model_name, - content_type = content_type.objects.get( - app_label = model._meta.app_label, - model = model._meta.model_name, - ) - ) - - change_team = Team.objects.create( - team_name = 'change_team' + str(random_str), - organization = organization_one, - ) - - change_team.permissions.set([change_permissions]) - - change_user = User.objects.create_user(username="test_user_change" + str(random_str), password="password") - - TeamUsers.objects.create( - team = change_team, - user = change_user - ) - - - - delete_permissions = permission.objects.get( - codename = 'delete_' + model._meta.model_name, - content_type = content_type.objects.get( - app_label = model._meta.app_label, - model = model._meta.model_name, - ) - ) - - delete_team = Team.objects.create( - team_name = 'delete_team' + str(random_str), - organization = organization_one, - ) - - delete_team.permissions.set([delete_permissions]) - - delete_user = User.objects.create_user(username="test_user_delete" + str(random_str), password="password") - TeamUsers.objects.create( - team = delete_team, - user = delete_user - ) - - - - view_permissions = permission.objects.get( - codename = 'view_' + model._meta.model_name, - content_type = content_type.objects.get( - app_label = model._meta.app_label, - model = model._meta.model_name, - ) - ) - - view_team = Team.objects.create( - team_name = 'view_team' + str(random_str), - organization = organization_one, - ) - - view_team.permissions.set([view_permissions]) - - view_user = User.objects.create_user(username="test_user_view" + str(random_str), password="password") - - TeamUsers.objects.create( - team = view_team, - user = view_user - ) - - - - different_organization_user = User.objects.create_user(username="test_diff_org_user" + str(random_str), password="password") - - - different_organization_team = Team.objects.create( - team_name = 'diff_org_team' + str(random_str), - organization = organization_two, - ) - - different_organization_team.permissions.set([ - view_permissions, - add_permissions, - change_permissions, - delete_permissions, - ]) - - TeamUsers.objects.create( - team = different_organization_team, - user = different_organization_user - ) - - yield { - 'app_settings': app_settings, - 'tenancy': { - 'different': organization_two, - 'global': organization_three, - 'user': organization_one - }, - 'user': { - 'add': add_user, - 'change': change_user, - 'delete': delete_user, - 'different_tenancy': different_organization_user, - 'view': view_user, - } - - } - - add_team.delete() - add_user.delete() - - change_team.delete() - change_user.delete() - - delete_team.delete() - delete_user.delete() - - view_team.delete() - view_user.delete() - - different_organization_team.delete() - different_organization_user.delete() - diff --git a/app/core/tests/functional/centurion_abstract/conftest.py b/app/core/tests/functional/centurion_abstract/conftest.py index 1abb48b0..346a2abf 100644 --- a/app/core/tests/functional/centurion_abstract/conftest.py +++ b/app/core/tests/functional/centurion_abstract/conftest.py @@ -1,14 +1,19 @@ import pytest -from core.models.centurion import CenturionModel - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionmodel): - request.cls.model = CenturionModel + yield model_centurionmodel - yield request.cls.model - del request.cls.model +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionmodel): + + request.cls.kwargs_create_item = kwargs_centurionmodel.copy() + + yield kwargs_centurionmodel.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/functional/centurion_abstract/test_functional_centurion_abstract_model.py b/app/core/tests/functional/centurion_abstract/test_functional_centurion_abstract_model.py index 1467eb81..93800602 100644 --- a/app/core/tests/functional/centurion_abstract/test_functional_centurion_abstract_model.py +++ b/app/core/tests/functional/centurion_abstract/test_functional_centurion_abstract_model.py @@ -14,12 +14,6 @@ class CenturionAbstractModelTestCases( ): - kwargs_create_item = { - 'model_notes': 'model notes txt', - 'created': '2025-05-23T00:00', - } - - def test_model_has_history_model(self, model): """Audit History Table check @@ -46,7 +40,7 @@ class CenturionAbstractModelTestCases( - def test_model_create_has_history_entry(self, content_type, created_model, model): + def test_model_create_has_history_entry(self, model_contenttype, created_model, model): """Model Created Ensure that the model when created, added a `create` Audit History @@ -66,7 +60,7 @@ class CenturionAbstractModelTestCases( entry = history_model.objects.get( model = created_model, - content_type = content_type.objects.get( + content_type = model_contenttype.objects.get( app_label = created_model._meta.app_label, model = created_model._meta.model_name ) diff --git a/app/core/tests/functional/centurion_audit/conftest.py b/app/core/tests/functional/centurion_audit/conftest.py index a5879014..004c2628 100644 --- a/app/core/tests/functional/centurion_audit/conftest.py +++ b/app/core/tests/functional/centurion_audit/conftest.py @@ -1,10 +1,19 @@ import pytest -from core.models.audit import CenturionAudit - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionaudit): - yield CenturionAudit + yield model_centurionaudit + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionaudit): + + request.cls.kwargs_create_item = kwargs_centurionaudit.copy() + + yield kwargs_centurionaudit.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py b/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py index 204ce728..300b33f3 100644 --- a/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py +++ b/app/core/tests/functional/centurion_audit/test_functional_centurion_audit_model.py @@ -16,25 +16,15 @@ class CenturionAuditModelTestCases( ): - kwargs_create_item = { - 'before': {}, - 'after': { - 'after_key': 'after_value' - }, - 'action': CenturionAudit.Actions.ADD, - 'user': 'fixture sets value', - 'content_type': 'fixture sets value', - } - @pytest.fixture( scope = 'class', autouse = True ) - def setup_vars(self, content_type, django_db_blocker, user, model): + def setup_vars(self, model_contenttype, django_db_blocker, model): with django_db_blocker.unblock(): try: - content_type = content_type.objects.get( + content_type = model_contenttype.objects.get( app_label = model._meta.app_label, model = model._meta.model_name, ) @@ -42,14 +32,13 @@ class CenturionAuditModelTestCases( except content_type.DoesNotExist: # Enable Abstract models to be tested - content_type = content_type.objects.get( + content_type = model_contenttype.objects.get( pk = 1, ) self.kwargs_create_item.update({ 'content_type': content_type, - 'user': user, }) diff --git a/app/core/tests/functional/centurion_note/conftest.py b/app/core/tests/functional/centurion_note/conftest.py index 6181c537..867f2b92 100644 --- a/app/core/tests/functional/centurion_note/conftest.py +++ b/app/core/tests/functional/centurion_note/conftest.py @@ -1,10 +1,19 @@ import pytest -from core.models.centurion_notes import CenturionModelNote - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionmodelnote): - yield CenturionModelNote + yield model_centurionmodelnote + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionmodelnote): + + request.cls.kwargs_create_item = kwargs_centurionmodelnote.copy() + + yield kwargs_centurionmodelnote.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/functional/centurion_note/test_functional_centurion_note_model.py b/app/core/tests/functional/centurion_note/test_functional_centurion_note_model.py index 5b2db5cc..834c7caa 100644 --- a/app/core/tests/functional/centurion_note/test_functional_centurion_note_model.py +++ b/app/core/tests/functional/centurion_note/test_functional_centurion_note_model.py @@ -14,21 +14,15 @@ class CenturionNoteModelTestCases( ): - kwargs_create_item = { - 'body': 'a random note', - 'created_by': 'fixture sets value', - 'content_type': 'fixture sets value', - } - @pytest.fixture( scope = 'class', autouse = True ) - def setup_vars(self, content_type, django_db_blocker, user, model): + def setup_vars(self, model_contenttype, django_db_blocker, model): with django_db_blocker.unblock(): try: - content_type = content_type.objects.get( + content_type = model_contenttype.objects.get( app_label = model._meta.app_label, model = model._meta.model_name, ) @@ -36,14 +30,13 @@ class CenturionNoteModelTestCases( except content_type.DoesNotExist: # Enable Abstract models to be tested - content_type = content_type.objects.get( + content_type = model_contenttype.objects.get( pk = 1, ) self.kwargs_create_item.update({ 'content_type': content_type, - 'created_by': user, }) diff --git a/app/core/tests/unit/centurion_abstract/conftest.py b/app/core/tests/unit/centurion_abstract/conftest.py index 1abb48b0..346a2abf 100644 --- a/app/core/tests/unit/centurion_abstract/conftest.py +++ b/app/core/tests/unit/centurion_abstract/conftest.py @@ -1,14 +1,19 @@ import pytest -from core.models.centurion import CenturionModel - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionmodel): - request.cls.model = CenturionModel + yield model_centurionmodel - yield request.cls.model - del request.cls.model +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionmodel): + + request.cls.kwargs_create_item = kwargs_centurionmodel.copy() + + yield kwargs_centurionmodel.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/unit/centurion_abstract/test_unit_centurion_abstract_model.py b/app/core/tests/unit/centurion_abstract/test_unit_centurion_abstract_model.py index a0c6cfee..46d3ff3c 100644 --- a/app/core/tests/unit/centurion_abstract/test_unit_centurion_abstract_model.py +++ b/app/core/tests/unit/centurion_abstract/test_unit_centurion_abstract_model.py @@ -22,14 +22,6 @@ class CenturionAbstractModelTestCases( ): - - kwargs_create_item = { - 'model_notes': 'model notes txt', - 'created': '2025-05-23T00:00', - } - - - @property def parameterized_class_attributes(self): diff --git a/app/core/tests/unit/centurion_audit/conftest.py b/app/core/tests/unit/centurion_audit/conftest.py index a5879014..004c2628 100644 --- a/app/core/tests/unit/centurion_audit/conftest.py +++ b/app/core/tests/unit/centurion_audit/conftest.py @@ -1,10 +1,19 @@ import pytest -from core.models.audit import CenturionAudit - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionaudit): - yield CenturionAudit + yield model_centurionaudit + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionaudit): + + request.cls.kwargs_create_item = kwargs_centurionaudit.copy() + + yield kwargs_centurionaudit.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/unit/centurion_audit/test_unit_centurion_audit_model.py b/app/core/tests/unit/centurion_audit/test_unit_centurion_audit_model.py index c2e21ee7..5b240109 100644 --- a/app/core/tests/unit/centurion_audit/test_unit_centurion_audit_model.py +++ b/app/core/tests/unit/centurion_audit/test_unit_centurion_audit_model.py @@ -1,14 +1,14 @@ import inspect import pytest -from django.apps import apps +# from django.apps import apps from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ( ValidationError ) from django.db import models -from core.models.audit import CenturionAudit +# from core.models.audit import CenturionAudit from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import ( CenturionAbstractModelInheritedCases @@ -21,17 +21,6 @@ class CenturionAuditModelTestCases( ): - kwargs_create_item = { - 'before': {}, - 'after': { - 'after_key': 'after_value' - }, - 'action': CenturionAudit.Actions.ADD, - 'user': 'fixture sets value', - 'content_type': 'fixture sets value', - } - - parameterized_class_attributes = { '_audit_enabled': { 'value': False, diff --git a/app/core/tests/unit/centurion_audit_meta/conftest.py b/app/core/tests/unit/centurion_audit_meta/conftest.py index 267edc2f..e723c923 100644 --- a/app/core/tests/unit/centurion_audit_meta/conftest.py +++ b/app/core/tests/unit/centurion_audit_meta/conftest.py @@ -5,6 +5,17 @@ from core.models.audit import AuditMetaModel @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionauditmeta): - yield AuditMetaModel + yield model_centurionauditmeta + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionauditmeta): + + request.cls.kwargs_create_item = kwargs_centurionauditmeta.copy() + + yield kwargs_centurionauditmeta.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/unit/centurion_model_note/conftest.py b/app/core/tests/unit/centurion_model_note/conftest.py index 6181c537..867f2b92 100644 --- a/app/core/tests/unit/centurion_model_note/conftest.py +++ b/app/core/tests/unit/centurion_model_note/conftest.py @@ -1,10 +1,19 @@ import pytest -from core.models.centurion_notes import CenturionModelNote - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionmodelnote): - yield CenturionModelNote + yield model_centurionmodelnote + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionmodelnote): + + request.cls.kwargs_create_item = kwargs_centurionmodelnote.copy() + + yield kwargs_centurionmodelnote.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/unit/centurion_model_note/test_unit_centurion_model_note_model.py b/app/core/tests/unit/centurion_model_note/test_unit_centurion_model_note_model.py index 760c747d..119111fe 100644 --- a/app/core/tests/unit/centurion_model_note/test_unit_centurion_model_note_model.py +++ b/app/core/tests/unit/centurion_model_note/test_unit_centurion_model_note_model.py @@ -15,13 +15,6 @@ class CenturionNoteModelTestCases( ): - kwargs_create_item = { - 'body': 'a random note', - 'created_by': 'fixture sets value', - 'content_type': 'fixture sets value', - } - - parameterized_class_attributes = { '_audit_enabled': { 'value': False, diff --git a/app/core/tests/unit/centurion_model_note_meta/conftest.py b/app/core/tests/unit/centurion_model_note_meta/conftest.py index fe9611f3..03f2ce79 100644 --- a/app/core/tests/unit/centurion_model_note_meta/conftest.py +++ b/app/core/tests/unit/centurion_model_note_meta/conftest.py @@ -1,10 +1,19 @@ import pytest -from core.models.centurion_notes import NoteMetaModel - @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionmodelnotemeta): - yield NoteMetaModel + yield model_centurionmodelnotemeta + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionmodelnotemeta): + + request.cls.kwargs_create_item = kwargs_centurionmodelnotemeta.copy() + + yield kwargs_centurionmodelnotemeta.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/core/tests/unit/centurion_sub_abstract/conftest.py b/app/core/tests/unit/centurion_sub_abstract/conftest.py index cf94733c..209dc52e 100644 --- a/app/core/tests/unit/centurion_sub_abstract/conftest.py +++ b/app/core/tests/unit/centurion_sub_abstract/conftest.py @@ -5,6 +5,17 @@ from core.models.centurion import CenturionSubModel @pytest.fixture( scope = 'class') -def model(request): +def model(model_centurionsubmodel): - yield CenturionSubModel + yield model_centurionsubmodel + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_centurionsubmodel): + + request.cls.kwargs_create_item = kwargs_centurionsubmodel.copy() + + yield kwargs_centurionsubmodel.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/devops/tests/functional/check_ins/test_functional_check_ins_create.py b/app/devops/tests/functional/check_ins/test_functional_check_ins_create.py index ea808e57..e059c7b9 100644 --- a/app/devops/tests/functional/check_ins/test_functional_check_ins_create.py +++ b/app/devops/tests/functional/check_ins/test_functional_check_ins_create.py @@ -1,3 +1,5 @@ +import pytest + from django.test import Client, TestCase from rest_framework.reverse import reverse @@ -13,6 +15,7 @@ from devops.models.check_ins import CheckIn +@pytest.mark.skip( reason = "Audit history requires context['user']") class Checkin( TestCase, ): diff --git a/app/devops/tests/functional/git_group/conftest.py b/app/devops/tests/functional/git_group/conftest.py index b13ab952..4e00ccdb 100644 --- a/app/devops/tests/functional/git_group/conftest.py +++ b/app/devops/tests/functional/git_group/conftest.py @@ -1,10 +1,19 @@ import pytest -from devops.models.git_group import GitGroup - @pytest.fixture( scope = 'class') -def model(request): +def model(model_gitgroup): - yield GitGroup + yield model_gitgroup + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_gitgroup): + + request.cls.kwargs_create_item = kwargs_gitgroup.copy() + + yield kwargs_gitgroup.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_serializer.py b/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_serializer.py index ba9964e9..bd40e31f 100644 --- a/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_serializer.py +++ b/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_serializer.py @@ -12,7 +12,7 @@ from devops.serializers.public_feature_flag import FeatureFlag, ViewSerializer from itam.models.software import Software - +@pytest.mark.skip( reason = "Audit history requires context['user']") class Serializer( TestCase, ): diff --git a/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_viewset.py b/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_viewset.py index 36a38e70..3a94811b 100644 --- a/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_viewset.py +++ b/app/devops/tests/functional/public_feature_flag/test_functional_public_feature_flag_viewset.py @@ -1,3 +1,4 @@ +import pytest from datetime import datetime from dateutil import tz @@ -15,6 +16,7 @@ from itam.models.software import Software +@pytest.mark.skip( reason = "Audit history requires context['user']") class ViewSetBase: model = FeatureFlag diff --git a/app/devops/tests/unit/feature_flag/conftest.py b/app/devops/tests/unit/feature_flag/conftest.py index e8f4ae5a..61413708 100644 --- a/app/devops/tests/unit/feature_flag/conftest.py +++ b/app/devops/tests/unit/feature_flag/conftest.py @@ -1,10 +1,20 @@ import pytest -from devops.models.feature_flag import FeatureFlag @pytest.fixture( scope = 'class') -def model(request): +def model(model_featureflag): - yield FeatureFlag + yield model_featureflag + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_featureflag): + + request.cls.kwargs_create_item = kwargs_featureflag.copy() + + yield kwargs_featureflag.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/devops/tests/unit/git_group/conftest.py b/app/devops/tests/unit/git_group/conftest.py index b13ab952..4e00ccdb 100644 --- a/app/devops/tests/unit/git_group/conftest.py +++ b/app/devops/tests/unit/git_group/conftest.py @@ -1,10 +1,19 @@ import pytest -from devops.models.git_group import GitGroup - @pytest.fixture( scope = 'class') -def model(request): +def model(model_gitgroup): - yield GitGroup + yield model_gitgroup + + +@pytest.fixture( scope = 'class', autouse = True) +def model_kwargs(request, kwargs_gitgroup): + + request.cls.kwargs_create_item = kwargs_gitgroup.copy() + + yield kwargs_gitgroup.copy() + + if hasattr(request.cls, 'kwargs_create_item'): + del request.cls.kwargs_create_item diff --git a/app/devops/tests/unit/git_group/test_unit_git_group_model.py b/app/devops/tests/unit/git_group/test_unit_git_group_model.py index b7d0929e..c25dffb7 100644 --- a/app/devops/tests/unit/git_group/test_unit_git_group_model.py +++ b/app/devops/tests/unit/git_group/test_unit_git_group_model.py @@ -7,8 +7,6 @@ from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model impor CenturionAbstractModelInheritedCases ) -from devops.models.git_group import GitGroup - @pytest.mark.model_gitgroup @@ -17,18 +15,6 @@ class GitGroupModelTestCases( ): - - kwargs_create_item = { - 'parent_group': None, - 'provider': GitGroup.GitProvider.GITHUB, - 'provider_pk': 1, - 'name': 'a name', - 'path': 'a_path', - 'description': 'a random bit of text.' - } - - - @property def parameterized_class_attributes(self): diff --git a/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_api_v2.py b/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_api_v2.py index 2ac4c0b6..4ffb9fc0 100644 --- a/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_api_v2.py +++ b/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_api_v2.py @@ -1,3 +1,4 @@ +import pytest from datetime import datetime from django.shortcuts import reverse @@ -13,7 +14,7 @@ from devops.models.software_enable_feature_flag import SoftwareEnableFeatureFlag from itam.models.software import Software - +@pytest.mark.skip( reason = "Audit history requires context['user']") class API( TestCase, ): diff --git a/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_viewset.py b/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_viewset.py index fca36c41..03760f7a 100644 --- a/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_viewset.py +++ b/app/devops/tests/unit/public_feature_flag/test_unit_public_feature_flag_viewset.py @@ -1,3 +1,4 @@ +import pytest from django.test import Client, TestCase from rest_framework.reverse import reverse @@ -10,7 +11,7 @@ from devops.viewsets.public_feature_flag import ViewSet from itam.models.software import Software - +@pytest.mark.skip( reason = "Audit history requires context['user']") class ViewsetList( PublicReadOnlyViewSetInheritedCases, TestCase, diff --git a/app/tests/__init__.py b/app/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/tests/fixtures/__init__.py b/app/tests/fixtures/__init__.py new file mode 100644 index 00000000..478bd2f0 --- /dev/null +++ b/app/tests/fixtures/__init__.py @@ -0,0 +1,64 @@ +# pylint: disable=W0611:unused-import + +from app.tests.fixtures.model_centurionsubmodel import model_centurionsubmodel +from .api_request_permissions import ( + api_request_permissions, +) + +from .model_centurionaudit import ( + kwargs_centurionaudit, + model_centurionaudit, +) + +from .model_centurionauditmeta import ( + kwargs_centurionauditmeta, + model_centurionauditmeta, +) + +from .model_centurionmodel import ( + kwargs_centurionmodel, + model_centurionmodel, +) + +from .model_centurionmodelnote import ( + kwargs_centurionmodelnote, + model_centurionmodelnote, +) + +from .model_centurionmodelnotemeta import ( + kwargs_centurionmodelnotemeta, + model_centurionmodelnotemeta, +) + +from .model_centurionsubmodel import ( + kwargs_centurionsubmodel, + model_centurionsubmodel, +) + +from .model_contenttype import ( + model_contenttype, +) + +from .model_featureflag import ( + kwargs_featureflag, + model_featureflag, +) + +from .model_gitgroup import ( + kwargs_gitgroup, + model_gitgroup, +) + +from .model_permission import ( + model_permission, +) + +from .model_tenancyabstract import ( + kwargs_tenancyabstract, + model_tenancyabstract, +) + +from .model_user import ( + kwargs_user, + model_user, +) diff --git a/app/tests/fixtures/api_request_permissions.py b/app/tests/fixtures/api_request_permissions.py new file mode 100644 index 00000000..3e4c1ddf --- /dev/null +++ b/app/tests/fixtures/api_request_permissions.py @@ -0,0 +1,192 @@ +import django +import pytest + +from settings.models.app_settings import AppSettings + + +User = django.contrib.auth.get_user_model() + + + +@pytest.fixture( scope = 'class') +def api_request_permissions( django_db_blocker, + model_contenttype, + model_permission, + model, + organization_one, + organization_two, + organization_three, +): + + with django_db_blocker.unblock(): + + + random_str = datetime.datetime.now(tz=datetime.timezone.utc) + + app_settings = AppSettings.objects.get( + owner_organization = None + ) + + app_settings.global_organization = organization_three + + app_settings.save() + + + + add_permissions = model_permission.objects.get( + codename = 'add_' + model._meta.model_name, + content_type = model_contenttype.objects.get( + app_label = model._meta.app_label, + model = model._meta.model_name, + ) + ) + + add_team = Team.objects.create( + team_name = 'add_team' + str(random_str), + organization = organization_one, + ) + + add_team.permissions.set([add_permissions]) + + add_user = User.objects.create_user( + username="test_user_add" + str(random_str), password="password" + ) + + TeamUsers.objects.create( + team = add_team, + user = add_user + ) + + + + change_permissions = model_permission.objects.get( + codename = 'change_' + model._meta.model_name, + content_type = model_contenttype.objects.get( + app_label = model._meta.app_label, + model = model._meta.model_name, + ) + ) + + change_team = Team.objects.create( + team_name = 'change_team' + str(random_str), + organization = organization_one, + ) + + change_team.permissions.set([change_permissions]) + + change_user = User.objects.create_user( + username="test_user_change" + str(random_str), password="password" + ) + + TeamUsers.objects.create( + team = change_team, + user = change_user + ) + + + + delete_permissions = model_permission.objects.get( + codename = 'delete_' + model._meta.model_name, + content_type = model_contenttype.objects.get( + app_label = model._meta.app_label, + model = model._meta.model_name, + ) + ) + + delete_team = Team.objects.create( + team_name = 'delete_team' + str(random_str), + organization = organization_one, + ) + + delete_team.permissions.set([delete_permissions]) + + delete_user = User.objects.create_user( + username="test_user_delete" + str(random_str), password="password" + ) + TeamUsers.objects.create( + team = delete_team, + user = delete_user + ) + + + + view_permissions = model_permission.objects.get( + codename = 'view_' + model._meta.model_name, + content_type = model_contenttype.objects.get( + app_label = model._meta.app_label, + model = model._meta.model_name, + ) + ) + + view_team = Team.objects.create( + team_name = 'view_team' + str(random_str), + organization = organization_one, + ) + + view_team.permissions.set([view_permissions]) + + view_user = User.objects.create_user( + username="test_user_view" + str(random_str), password="password" + ) + + TeamUsers.objects.create( + team = view_team, + user = view_user + ) + + + + different_organization_user = User.objects.create_user( + username="test_diff_org_user" + str(random_str), password="password" + ) + + + different_organization_team = Team.objects.create( + team_name = 'diff_org_team' + str(random_str), + organization = organization_two, + ) + + different_organization_team.permissions.set([ + view_permissions, + add_permissions, + change_permissions, + delete_permissions, + ]) + + TeamUsers.objects.create( + team = different_organization_team, + user = different_organization_user + ) + + yield { + 'app_settings': app_settings, + 'tenancy': { + 'different': organization_two, + 'global': organization_three, + 'user': organization_one + }, + 'user': { + 'add': add_user, + 'change': change_user, + 'delete': delete_user, + 'different_tenancy': different_organization_user, + 'no_permissions': '', + 'view': view_user, + } + + } + + add_team.delete() + add_user.delete() + + change_team.delete() + change_user.delete() + + delete_team.delete() + delete_user.delete() + + view_team.delete() + view_user.delete() + + different_organization_team.delete() + different_organization_user.delete() diff --git a/app/tests/fixtures/model_centurionaudit.py b/app/tests/fixtures/model_centurionaudit.py new file mode 100644 index 00000000..db50d9e2 --- /dev/null +++ b/app/tests/fixtures/model_centurionaudit.py @@ -0,0 +1,49 @@ +import datetime +import pytest + +from core.models.audit import CenturionAudit + + + +@pytest.fixture( scope = 'class') +def model_centurionaudit(): + + yield CenturionAudit + + +@pytest.fixture( scope = 'class') +def kwargs_centurionaudit(django_db_blocker, kwargs_centurionmodel, kwargs_user, model_user): + + kwargs = kwargs_centurionmodel.copy() + del kwargs['model_notes'] + + with django_db_blocker.unblock(): + + + random_str = str(datetime.datetime.now(tz=datetime.timezone.utc)) + + user_kwargs = kwargs_user.copy() + user_kwargs.update({ + 'username': 'audit_user' + str(random_str) + }) + + user = model_user.objects.create( + **user_kwargs, + ) + + kwargs = { + **kwargs, + 'before': {}, + 'after': { + 'after_key': 'after_value' + }, + 'action': CenturionAudit.Actions.ADD, + 'user': user, + 'content_type': 'fixture sets value', + } + + yield kwargs.copy() + + with django_db_blocker.unblock(): + + user.delete() diff --git a/app/tests/fixtures/model_centurionauditmeta.py b/app/tests/fixtures/model_centurionauditmeta.py new file mode 100644 index 00000000..bc127729 --- /dev/null +++ b/app/tests/fixtures/model_centurionauditmeta.py @@ -0,0 +1,20 @@ +import pytest + +from core.models.audit import AuditMetaModel + + + +@pytest.fixture( scope = 'class') +def model_centurionauditmeta(request): + + yield AuditMetaModel + + +@pytest.fixture( scope = 'class') +def kwargs_centurionauditmeta(request, kwargs_centurionaudit): + + kwargs = { + **kwargs_centurionaudit.copy(), + } + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_centurionmodel.py b/app/tests/fixtures/model_centurionmodel.py new file mode 100644 index 00000000..c8ba02ed --- /dev/null +++ b/app/tests/fixtures/model_centurionmodel.py @@ -0,0 +1,22 @@ +import pytest + +from core.models.centurion import CenturionModel + + + +@pytest.fixture( scope = 'class') +def model_centurionmodel(): + + yield CenturionModel + + +@pytest.fixture( scope = 'class') +def kwargs_centurionmodel(kwargs_tenancyabstract): + + kwargs = { + **kwargs_tenancyabstract, + 'model_notes': 'model notes txt', + 'created': '2025-05-23T00:00', + } + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_centurionmodelnote.py b/app/tests/fixtures/model_centurionmodelnote.py new file mode 100644 index 00000000..a7d4df18 --- /dev/null +++ b/app/tests/fixtures/model_centurionmodelnote.py @@ -0,0 +1,43 @@ +import datetime +import pytest + +from core.models.centurion_notes import CenturionModelNote + + + +@pytest.fixture( scope = 'class') +def model_centurionmodelnote(): + + yield CenturionModelNote + + +@pytest.fixture( scope = 'class') +def kwargs_centurionmodelnote(django_db_blocker, kwargs_centurionmodel, kwargs_user, model_user): + + kwargs = kwargs_centurionmodel.copy() + del kwargs['model_notes'] + + with django_db_blocker.unblock(): + + random_str = str(datetime.datetime.now(tz=datetime.timezone.utc)) + + user_kwargs = kwargs_user.copy() + user_kwargs.update({ + 'username': 'note_user' + str(random_str) + }) + + user = model_user.objects.create( + **user_kwargs, + ) + + kwargs = { + **kwargs, + 'body': 'a random note', + 'created_by': user, + 'content_type': 'fixture sets value', + } + + yield kwargs.copy() + + with django_db_blocker.unblock(): + user.delete() \ No newline at end of file diff --git a/app/tests/fixtures/model_centurionmodelnotemeta.py b/app/tests/fixtures/model_centurionmodelnotemeta.py new file mode 100644 index 00000000..0293ffe2 --- /dev/null +++ b/app/tests/fixtures/model_centurionmodelnotemeta.py @@ -0,0 +1,20 @@ +import pytest + +from core.models.centurion_notes import NoteMetaModel + + + +@pytest.fixture( scope = 'class') +def model_centurionmodelnotemeta(request): + + yield NoteMetaModel + + +@pytest.fixture( scope = 'class') +def kwargs_centurionmodelnotemeta(request, kwargs_centurionmodelnote): + + kwargs = { + **kwargs_centurionmodelnote.copy(), + } + + yield kwargs diff --git a/app/tests/fixtures/model_centurionsubmodel.py b/app/tests/fixtures/model_centurionsubmodel.py new file mode 100644 index 00000000..dec9d3bb --- /dev/null +++ b/app/tests/fixtures/model_centurionsubmodel.py @@ -0,0 +1,20 @@ +import pytest + +from core.models.centurion import CenturionSubModel + + + +@pytest.fixture( scope = 'class') +def model_centurionsubmodel(request): + + yield CenturionSubModel + + +@pytest.fixture( scope = 'class') +def kwargs_centurionsubmodel(request, kwargs_centurionmodel): + + kwargs = { + **kwargs_centurionmodel.copy(), + } + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_contenttype.py b/app/tests/fixtures/model_contenttype.py new file mode 100644 index 00000000..46b049ec --- /dev/null +++ b/app/tests/fixtures/model_contenttype.py @@ -0,0 +1,16 @@ +import pytest + +from django.contrib.contenttypes.models import ContentType + + + +@pytest.fixture( scope = 'class') +def model_contenttype(): + + yield ContentType + + +@pytest.fixture( scope = 'class') +def content_type(): + + yield ContentType diff --git a/app/tests/fixtures/model_featureflag.py b/app/tests/fixtures/model_featureflag.py new file mode 100644 index 00000000..cfa6d608 --- /dev/null +++ b/app/tests/fixtures/model_featureflag.py @@ -0,0 +1,27 @@ +import pytest + +from devops.models.feature_flag import FeatureFlag + + + +@pytest.fixture( scope = 'class') +def model_featureflag(request): + + yield FeatureFlag + + +@pytest.fixture( scope = 'class') +def kwargs_featureflag(kwargs_centurionmodel): + + # kwargs = kwargs_centurionmodel.copy() + # del kwargs['model_notes'] + + kwargs = { + **kwargs_centurionmodel.copy(), + 'software': None, + 'name': 'a name', + 'description': ' a description', + 'enabled': True, + } + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_gitgroup.py b/app/tests/fixtures/model_gitgroup.py new file mode 100644 index 00000000..0879b832 --- /dev/null +++ b/app/tests/fixtures/model_gitgroup.py @@ -0,0 +1,29 @@ +import pytest + +from devops.models.git_group import GitGroup + + + +@pytest.fixture( scope = 'class') +def model_gitgroup(request): + + yield GitGroup + + +@pytest.fixture( scope = 'class') +def kwargs_gitgroup(kwargs_centurionmodel): + + # kwargs = kwargs_centurionmodel.copy() + # del kwargs['model_notes'] + + kwargs = { + **kwargs_centurionmodel.copy(), + 'parent_group': None, + 'provider': GitGroup.GitProvider.GITHUB, + 'provider_pk': 1, + 'name': 'a name', + 'path': 'a_path', + 'description': 'a random bit of text.' + } + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_permission.py b/app/tests/fixtures/model_permission.py new file mode 100644 index 00000000..3f00c62f --- /dev/null +++ b/app/tests/fixtures/model_permission.py @@ -0,0 +1,17 @@ +import datetime +import django +import pytest + + +from django.contrib.auth.models import ( + Permission, +) + + +User = django.contrib.auth.get_user_model() + + +@pytest.fixture( scope = 'class') +def model_permission(): + + yield Permission diff --git a/app/tests/fixtures/model_tenancyabstract.py b/app/tests/fixtures/model_tenancyabstract.py new file mode 100644 index 00000000..31654cbe --- /dev/null +++ b/app/tests/fixtures/model_tenancyabstract.py @@ -0,0 +1,18 @@ +import pytest + +from access.models.tenancy_abstract import TenancyAbstractModel + + + +@pytest.fixture( scope = 'class') +def model_tenancyabstract(request): + + yield TenancyAbstractModel + + +@pytest.fixture( scope = 'class') +def kwargs_tenancyabstract(): + + kwargs = {} + + yield kwargs.copy() diff --git a/app/tests/fixtures/model_user.py b/app/tests/fixtures/model_user.py new file mode 100644 index 00000000..73aedf99 --- /dev/null +++ b/app/tests/fixtures/model_user.py @@ -0,0 +1,26 @@ +import datetime +import django +import pytest + +User = django.contrib.auth.get_user_model() + + +@pytest.fixture( scope = 'class') +def model_user(): + + yield User + + +@pytest.fixture( scope = 'class') +def kwargs_user(): + + kwargs = {} + + random_str = str(datetime.datetime.now(tz=datetime.timezone.utc)) + + kwargs = { + 'username': "test_user-" + random_str, + 'password': "password" + } + + yield kwargs.copy() diff --git a/docs/projects/centurion_erp/development/testing.md b/docs/projects/centurion_erp/development/testing.md index 8550f058..0f52868b 100644 --- a/docs/projects/centurion_erp/development/testing.md +++ b/docs/projects/centurion_erp/development/testing.md @@ -10,12 +10,6 @@ Unit and functional tests are written to aid in application stability and to ass We use PyTest as the testing framework. As such, All available features of pytest are available. We have slightly deviated from the standard naming convention wherein test class must be suffixed with `PyTest`. Please [see below](#writing-tests) for more details. -!!! note - As of release v1.3, the UI has moved to it's [own project](https://github.com/nofusscomputing/centurion_erp_ui) with the current Django UI feature locked and depreciated. - -!!! note - These docs are currently undergoing a rewrite as how we write and expect tests to be written has changed. - ## Directory Structure @@ -149,9 +143,43 @@ Fixtures are used to setup the test and to pass objects to test should they requ There may also be a requirement that you add additional fixtures, they are: -- `model` This fixture should be defined in `conftest.py` in the test suite files directory. _Only required if the model is required to be worked with._ +- Global Model Fixtures - ``` py filename="conftest.py" + Locatation for the global fixtures is `app/tests/fixtures/`. Each model is to have a global fixture file added with name `model_` within this file the following fixtures are to be created: + + ``` py title="tests/fixtures/model_centurionmodel.py" + import pytest + + from core.models.centurion import CenturionModel + + + + @pytest.fixture( scope = 'class') + def model_centurionmodel(): + + yield CenturionModel + + + @pytest.fixture( scope = 'class') + def kwargs_centurionmodel(kwargs_tenancyabstract): + + kwargs = { + **kwargs_tenancyabstract, + 'model_notes': 'model notes txt', + 'created': '2025-05-23T00:00', + } + + yield kwargs.copy() + + ``` + + - `model` is to return the model class un-instantiated + + - `kwargs` the Kwargs required to create the model. + +- `model` and `model_kwargs` These fixtures should be defined in `conftest.py` in the test suite files directory. _Only required if the model is required to be worked with._ + + ``` py title="conftest.py" import pytest @@ -162,11 +190,18 @@ There may also be a requirement that you add additional fixtures, they are: @pytest.fixture( scope = 'class') def model(request): - request.cls.model = RequestTicket + yield RequestTicket - yield request.cls.model + + @pytest.fixture( scope = 'class') + def model_kwargs(request, kwargs_): + + request.cls.kwargs_create_item = kwargs_.copy() + + yield kwargs_.copy() + + del request.cls.kwargs_create_item - del request.cls.model # Don't forget to clean-up any objects created. ``` diff --git a/makefile b/makefile index c0d7eda4..7f780aaa 100644 --- a/makefile +++ b/makefile @@ -6,10 +6,12 @@ ACTIVATE_VENV :=. ${PATH_VENV}/bin/activate .PHONY: clean prepare docs ansible-lint lint test - -prepare: +prepare-git-submodule: git submodule update --init; git submodule foreach git submodule update --init; + + +prepare-python: prepare-git-submodule python3 -m venv ${PATH_VENV}; ${ACTIVATE_VENV}; pip install -r website-template/gitlab-ci/mkdocs/requirements.txt; @@ -17,13 +19,15 @@ prepare: pip install -r gitlab-ci/mkdocs/requirements.txt; pip install -r requirements.txt; pip install -r requirements_test.txt; + +prepare-docs: prepare-git-submodule npm install markdownlint-cli2; npm install markdownlint-cli2-formatter-junit; cp -f "website-template/.markdownlint.json" ".markdownlint.json"; cp -f "gitlab-ci/lint/.markdownlint-cli2.jsonc" ".markdownlint-cli2.jsonc"; -markdown-mkdocs-lint: +markdown-mkdocs-lint: prepare-docs PATH=${PATH}:node_modules/.bin markdownlint-cli2 docs/*.md docs/**/*.md docs/**/**/*.md docs/**/**/**/*.md docs/**/**/**/**/**/*.md !docs/pull_request_template.md !CHANGELOG.md !gitlab-ci !website-template || true