refactor(itim): Update Test Suite for ClusterType model

ref: #824 #826
This commit is contained in:
2025-06-13 12:52:27 +09:30
parent 30c19031eb
commit 8452e678da
8 changed files with 133 additions and 18 deletions

View File

@ -14,11 +14,8 @@ CREATE TABLE IF NOT EXISTS "project_management_project" ("is_global" bool NOT NU
CREATE TABLE IF NOT EXISTS "project_management_projectmilestone" ("is_global" bool NOT NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "modified" datetime NOT NULL, "name" varchar(100) NOT NULL UNIQUE, "slug" varchar(50) NOT NULL, "description" text NULL, "start_date" datetime NULL, "finish_date" datetime NULL, "created" datetime NOT NULL, "project_id" integer NOT NULL REFERENCES "project_management_project" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "project_management_projectstate" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL UNIQUE, "is_completed" bool NOT NULL, "runbook_id" integer NULL REFERENCES "assistance_knowledgebase" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "project_management_projecttype" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL UNIQUE, "runbook_id" integer NULL REFERENCES "assistance_knowledgebase" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_devices" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "cluster_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED, "device_id" integer NOT NULL REFERENCES "itam_device" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_nodes" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "cluster_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED, "device_id" integer NOT NULL REFERENCES "itam_device" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_service_dependent_service" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "from_service_id" integer NOT NULL REFERENCES "itim_service" ("id") DEFERRABLE INITIALLY DEFERRED, "to_service_id" integer NOT NULL REFERENCES "itim_service" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_service_port" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "service_id" integer NOT NULL REFERENCES "itim_service" ("id") DEFERRABLE INITIALLY DEFERRED, "port_id" integer NOT NULL REFERENCES "itim_port" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_clustertype" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "slug" varchar(50) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_port" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "number" integer NOT NULL, "description" varchar(80) NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "protocol" varchar(3) NOT NULL);
CREATE TABLE IF NOT EXISTS "itim_service" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "is_template" bool NOT NULL, "name" varchar(50) NOT NULL, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "config_key_variable" varchar(50) NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "cluster_id" integer NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED, "device_id" integer NULL REFERENCES "itam_device" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "template_id" integer NULL REFERENCES "itim_service" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "core_ticket_assigned_teams" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "ticket_id" integer NOT NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED, "team_id" integer NOT NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED);
@ -202,9 +199,14 @@ CREATE TABLE IF NOT EXISTS "itam_softwarecategory_centurionmodelnote" ("centurio
CREATE TABLE IF NOT EXISTS "itam_softwareversion" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "software_id" integer NOT NULL REFERENCES "itam_software" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
CREATE TABLE IF NOT EXISTS "itam_softwareversion_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itam_softwareversion" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itam_softwareversion_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itam_softwareversion" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "cluster_type_id" integer NULL REFERENCES "itim_clustertype" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL, "parent_cluster_id" integer NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_devices" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "cluster_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED, "device_id" integer NOT NULL REFERENCES "itam_device" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_nodes" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "cluster_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED, "device_id" integer NOT NULL REFERENCES "itam_device" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster" ("model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "cluster_type_id" integer NULL REFERENCES "itim_clustertype" ("id") DEFERRABLE INITIALLY DEFERRED, "parent_cluster_id" integer NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_cluster_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itim_cluster" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_clustertype" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "created" datetime NOT NULL, "modified" datetime NOT NULL, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "model_notes" text NULL);
CREATE TABLE IF NOT EXISTS "itim_clustertype_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itim_clustertype" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "itim_clustertype_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itim_clustertype" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "django_session" ("session_key" varchar(40) NOT NULL PRIMARY KEY, "session_data" text NOT NULL, "expire_date" datetime NOT NULL);
CREATE TABLE IF NOT EXISTS "social_auth_association" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "server_url" varchar(255) NOT NULL, "handle" varchar(255) NOT NULL, "secret" varchar(255) NOT NULL, "issued" integer NOT NULL, "lifetime" integer NOT NULL, "assoc_type" varchar(64) NOT NULL);
CREATE TABLE IF NOT EXISTS "social_auth_code" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "email" varchar(254) NOT NULL, "code" varchar(32) NOT NULL, "verified" bool NOT NULL, "timestamp" datetime NOT NULL);
@ -212,16 +214,15 @@ 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',207);
INSERT INTO sqlite_sequence VALUES('django_content_type',191);
INSERT INTO sqlite_sequence VALUES('auth_permission',809);
INSERT INTO sqlite_sequence VALUES('django_migrations',208);
INSERT INTO sqlite_sequence VALUES('django_content_type',193);
INSERT INTO sqlite_sequence VALUES('auth_permission',817);
INSERT INTO sqlite_sequence VALUES('auth_group',0);
INSERT INTO sqlite_sequence VALUES('auth_user',0);
INSERT INTO sqlite_sequence VALUES('project_management_project',0);
INSERT INTO sqlite_sequence VALUES('project_management_projectmilestone',0);
INSERT INTO sqlite_sequence VALUES('project_management_projectstate',0);
INSERT INTO sqlite_sequence VALUES('project_management_projecttype',0);
INSERT INTO sqlite_sequence VALUES('itim_clustertype',0);
INSERT INTO sqlite_sequence VALUES('itim_port',0);
INSERT INTO sqlite_sequence VALUES('itim_service',0);
INSERT INTO sqlite_sequence VALUES('core_notes',0);
@ -265,7 +266,10 @@ INSERT INTO sqlite_sequence VALUES('itam_operatingsystemversion',0);
INSERT INTO sqlite_sequence VALUES('itam_software',0);
INSERT INTO sqlite_sequence VALUES('itam_softwarecategory',0);
INSERT INTO sqlite_sequence VALUES('itam_softwareversion',0);
INSERT INTO sqlite_sequence VALUES('itim_cluster_devices',0);
INSERT INTO sqlite_sequence VALUES('itim_cluster_nodes',0);
INSERT INTO sqlite_sequence VALUES('itim_cluster',0);
INSERT INTO sqlite_sequence VALUES('itim_clustertype',0);
INSERT INTO sqlite_sequence VALUES('social_auth_association',0);
INSERT INTO sqlite_sequence VALUES('social_auth_code',0);
INSERT INTO sqlite_sequence VALUES('social_auth_nonce',0);

View File

@ -0,0 +1,19 @@
import pytest
@pytest.fixture( scope = 'class')
def model(model_clustertype):
yield model_clustertype
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_clustertype):
request.cls.kwargs_create_item = kwargs_clustertype.copy()
yield kwargs_clustertype.copy()
if hasattr(request.cls, 'kwargs_create_item'):
del request.cls.kwargs_create_item

View File

@ -1,5 +1,4 @@
import pytest
import unittest
from django.contrib.auth.models import Permission, User
from django.contrib.contenttypes.models import ContentType
@ -18,6 +17,8 @@ from itim.models.clusters import ClusterType
@pytest.mark.model_clustertype
@pytest.mark.module_itim
class ClusterTypeAPI(
TestCase,
APITenancyObject

View File

@ -1,16 +1,70 @@
from django.test import TestCase
import pytest
from centurion.tests.unit.test_unit_models import (
TenancyObjectInheritedCases
from django.db import models
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
CenturionAbstractModelInheritedCases
)
from itim.models.clusters import ClusterType
class ClusterTypeModel(
TenancyObjectInheritedCases,
TestCase,
@pytest.mark.model_clustertype
class ClusterModelTestCases(
CenturionAbstractModelInheritedCases
):
model = ClusterType
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': str,
'value': 'cluster'
},
}
@property
def parameterized_model_fields(self):
return {
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'length': 50,
'null': False,
'unique': False,
},
'config': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.JSONField,
'null': True,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class ClusterModelInheritedCases(
ClusterModelTestCases,
):
pass
@pytest.mark.module_itim
class ClusterModelPyTest(
ClusterModelTestCases,
):
pass

View File

@ -1,3 +1,5 @@
import pytest
from django.test import Client, TestCase
from rest_framework.reverse import reverse
@ -8,6 +10,8 @@ from itim.viewsets.cluster_type import ViewSet
@pytest.mark.model_clustertype
@pytest.mark.module_itim
class ClusterTypesViewsetList(
ModelViewSetInheritedCases,
TestCase,

View File

@ -48,6 +48,11 @@ from .model_cluster import (
model_cluster,
)
from .model_clustertype import (
kwargs_clustertype,
model_clustertype,
)
from .model_configgroup import (
kwargs_configgroups,
model_configgroups,

26
app/tests/fixtures/model_clustertype.py vendored Normal file
View File

@ -0,0 +1,26 @@
import datetime
import pytest
from itim.models.clusters import ClusterType
@pytest.fixture( scope = 'class')
def model_clustertype():
yield ClusterType
@pytest.fixture( scope = 'class')
def kwargs_clustertype(kwargs_centurionmodel):
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
random_str = str(random_str).replace(
' ', '').replace(':', '').replace('+', '').replace('.', '')
kwargs = {
**kwargs_centurionmodel.copy(),
'name': 'clustertype_' + random_str,
}
yield kwargs.copy()

View File

@ -1076,6 +1076,8 @@ markers = [
"model_configgroups: Selects Config Group tests.",
"model_configgrouphosts: Selects Config Group Hosts tests.",
"model_configgroupsoftware: Selects Config Group Software tests.",
"model_cluster: Selects Cluster tests.",
"model_clustertype: Selects Cluster Type tests.",
"model_device: Select all Device tests",
"model_devicemodel: Select all device model tests.",
"model_deviceoperatingsystem: Select tests for model Device Operating System",