@ -10,6 +10,8 @@ from access.serializers.role import Role, ModelSerializer
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
@pytest.mark.module_role
|
||||
class ValidationSerializer(
|
||||
TestCase,
|
||||
):
|
||||
|
@ -1,4 +1,6 @@
|
||||
import django
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import Client, TestCase
|
||||
@ -20,6 +22,8 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
@pytest.mark.module_role
|
||||
class ViewSetBase:
|
||||
|
||||
add_data: dict = None
|
||||
|
19
app/access/tests/unit/role/conftest.py
Normal file
19
app/access/tests/unit/role/conftest.py
Normal file
@ -0,0 +1,19 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_role):
|
||||
|
||||
yield model_role
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_role):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_role.copy()
|
||||
|
||||
yield kwargs_role.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
import django
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
@ -18,6 +19,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
class APITestCases(
|
||||
APITenancyObject,
|
||||
):
|
||||
@ -48,7 +50,7 @@ class APITestCases(
|
||||
**self.kwargs_item_create
|
||||
)
|
||||
|
||||
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'pk': self.item.id
|
||||
}
|
||||
@ -154,6 +156,7 @@ class APITestCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_role
|
||||
class RoleAPITest(
|
||||
APITestCases,
|
||||
TestCase,
|
||||
|
@ -1,30 +1,70 @@
|
||||
from django.test import TestCase
|
||||
import pytest
|
||||
|
||||
from access.models.role import Role
|
||||
from django.db import models
|
||||
|
||||
from centurion.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
|
||||
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
class RoleModelTestCases(
|
||||
TenancyObjectInheritedCases,
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
|
||||
model = None
|
||||
|
||||
kwargs_item_create: dict = None
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'model_tag': {
|
||||
'type': str,
|
||||
'value': 'role'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_model_fields(self):
|
||||
|
||||
class RoleModelTest(
|
||||
RoleModelTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = Role
|
||||
|
||||
kwargs_item_create: dict = {
|
||||
'name': 'a role'
|
||||
return {
|
||||
'name': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.CharField,
|
||||
'max_length': 30,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'permissions': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ManyToManyField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'modified': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.DateTimeField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
class RoleModelInheritedCases(
|
||||
RoleModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_role
|
||||
class RoleModelPyTest(
|
||||
RoleModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
@ -20,6 +20,8 @@ import pytest
|
||||
###############################################################################
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
@pytest.mark.module_role
|
||||
@pytest.mark.skip( reason = 'figure out how to isolate so entirety of unit tests can run without this test failing' )
|
||||
# @pytest.mark.forked
|
||||
# @pytest.mark.django_db
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
@ -9,6 +11,7 @@ from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_role
|
||||
class ViewsetTestCases(
|
||||
ModelViewSetInheritedCases,
|
||||
):
|
||||
@ -44,6 +47,7 @@ class ViewsetTestCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_role
|
||||
class RoleViewsetTest(
|
||||
ViewsetTestCases,
|
||||
TestCase,
|
||||
|
@ -1,7 +1,5 @@
|
||||
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiResponse
|
||||
|
||||
# THis import only exists so that the migrations can be created
|
||||
from access.models.role_history import RoleHistory # pylint: disable=W0611:unused-import
|
||||
from access.serializers.role import (
|
||||
Role,
|
||||
ModelSerializer,
|
||||
|
@ -76,10 +76,7 @@ CREATE TABLE IF NOT EXISTS "assistance_knowledge_base_history" ("modelhistory_pt
|
||||
CREATE TABLE IF NOT EXISTS "access_team_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "core_ticketcategory_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "core_ticketcategory" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "core_ticketcommentcategory_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "core_ticketcommentcategory" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_role" ("model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_role_permissions" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "role_id" integer NOT NULL REFERENCES "access_role" ("id") DEFERRABLE INITIALLY DEFERRED, "permission_id" integer NOT NULL REFERENCES "auth_permission" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_role_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_role" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_role_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_role" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_contact" ("person_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_person" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED, "directory" bool NOT NULL, "email" varchar(254) NOT NULL UNIQUE);
|
||||
CREATE TABLE IF NOT EXISTS "core_ticketbase_assigned_to" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "ticketbase_id" integer NOT NULL REFERENCES "core_ticketbase" ("id") DEFERRABLE INITIALLY DEFERRED, "entity_id" integer NOT NULL REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "core_ticketbase_subscribed_to" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "ticketbase_id" integer NOT NULL REFERENCES "core_ticketbase" ("id") DEFERRABLE INITIALLY DEFERRED, "entity_id" integer NOT NULL REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
@ -139,6 +136,7 @@ CREATE TABLE IF NOT EXISTS "access_person_audithistory" ("centurionaudit_ptr_id"
|
||||
CREATE TABLE IF NOT EXISTS "access_person_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_person" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_company_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_company" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_company_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_company" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "access_role" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
|
||||
CREATE TABLE IF NOT EXISTS "accounting_assetbase" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "asset_number" varchar(30) NULL UNIQUE, "serial_number" varchar(30) NULL UNIQUE, "asset_type" varchar(30) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
|
||||
CREATE TABLE IF NOT EXISTS "accounting_assetbase_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "accounting_assetbase" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
CREATE TABLE IF NOT EXISTS "accounting_assetbase_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "accounting_assetbase" ("id") DEFERRABLE INITIALLY DEFERRED);
|
||||
@ -239,9 +237,9 @@ CREATE TABLE IF NOT EXISTS "social_auth_nonce" ("id" integer NOT NULL PRIMARY KE
|
||||
CREATE TABLE IF NOT EXISTS "social_auth_usersocialauth" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "provider" varchar(32) NOT NULL, "uid" varchar(255) NOT NULL, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "created" datetime NOT NULL, "modified" datetime NOT NULL, "extra_data" text NOT NULL CHECK ((JSON_VALID("extra_data") OR "extra_data" IS NULL)));
|
||||
CREATE TABLE IF NOT EXISTS "social_auth_partial" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "token" varchar(32) NOT NULL, "next_step" smallint unsigned NOT NULL CHECK ("next_step" >= 0), "backend" varchar(32) NOT NULL, "timestamp" datetime NOT NULL, "data" text NOT NULL CHECK ((JSON_VALID("data") OR "data" IS NULL)));
|
||||
DELETE FROM sqlite_sequence;
|
||||
INSERT INTO sqlite_sequence VALUES('django_migrations',225);
|
||||
INSERT INTO sqlite_sequence VALUES('django_content_type',218);
|
||||
INSERT INTO sqlite_sequence VALUES('auth_permission',917);
|
||||
INSERT INTO sqlite_sequence VALUES('django_migrations',226);
|
||||
INSERT INTO sqlite_sequence VALUES('django_content_type',216);
|
||||
INSERT INTO sqlite_sequence VALUES('auth_permission',909);
|
||||
INSERT INTO sqlite_sequence VALUES('auth_group',0);
|
||||
INSERT INTO sqlite_sequence VALUES('auth_user',0);
|
||||
INSERT INTO sqlite_sequence VALUES('core_notes',0);
|
||||
@ -263,6 +261,7 @@ INSERT INTO sqlite_sequence VALUES('assistance_knowledgebasecategory',0);
|
||||
INSERT INTO sqlite_sequence VALUES('assistance_modelknowledgebasearticle',0);
|
||||
INSERT INTO sqlite_sequence VALUES('access_tenant',0);
|
||||
INSERT INTO sqlite_sequence VALUES('access_entity',0);
|
||||
INSERT INTO sqlite_sequence VALUES('access_role',0);
|
||||
INSERT INTO sqlite_sequence VALUES('accounting_assetbase',0);
|
||||
INSERT INTO sqlite_sequence VALUES('django_admin_log',0);
|
||||
INSERT INTO sqlite_sequence VALUES('itam_devicetype',0);
|
||||
|
5
app/tests/fixtures/__init__.py
vendored
5
app/tests/fixtures/__init__.py
vendored
@ -233,6 +233,11 @@ from .model_projecttype import (
|
||||
model_projecttype,
|
||||
)
|
||||
|
||||
from .model_role import (
|
||||
kwargs_role,
|
||||
model_role,
|
||||
)
|
||||
|
||||
from .model_service import (
|
||||
kwargs_service,
|
||||
model_service,
|
||||
|
29
app/tests/fixtures/model_role.py
vendored
Normal file
29
app/tests/fixtures/model_role.py
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
import datetime
|
||||
import pytest
|
||||
|
||||
from access.models.role import Role
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_role():
|
||||
|
||||
yield Role
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_role(
|
||||
kwargs_centurionmodel
|
||||
):
|
||||
|
||||
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||
random_str = str(random_str).replace(
|
||||
' ', '').replace(':', '').replace('-', '').replace('+', '').replace('.', '')
|
||||
|
||||
kwargs = {
|
||||
**kwargs_centurionmodel.copy(),
|
||||
'name': 'r_' + random_str,
|
||||
'modified': '2024-06-03T23:00:00Z',
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
@ -1137,6 +1137,7 @@ markers = [
|
||||
"model_projectmilestone: Selects tests for model Project Milestone.",
|
||||
"model_projectstate: Selects tests for model Project State.",
|
||||
"model_projecttype: Selects tests for model Project Type.",
|
||||
"model_role: Selects tests for model Role.",
|
||||
"model_service: Selects tests for model Service.",
|
||||
"model_software: Selects tests for model Software.",
|
||||
"model_softwarecategory: Selects tests for model Software Category.",
|
||||
|
Reference in New Issue
Block a user