refactor(itim): Update Test Suite for Cluster model

ref: #824 #825
This commit is contained in:
2025-06-13 12:17:41 +09:30
parent 1611537d86
commit 93eb65316e
9 changed files with 169 additions and 18 deletions

View File

@ -18,7 +18,6 @@ CREATE TABLE IF NOT EXISTS "itim_cluster_devices" ("id" integer NOT NULL PRIMARY
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_cluster" ("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, "config" text NULL CHECK ((JSON_VALID("config") OR "config" IS NULL)), "created" datetime NOT NULL, "modified" datetime NOT NULL, "cluster_type_id" integer NULL REFERENCES "itim_clustertype" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "parent_cluster_id" integer NULL REFERENCES "itim_cluster" ("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);
@ -112,8 +111,8 @@ CREATE TABLE IF NOT EXISTS "devops_git_group_history" ("modelhistory_ptr_id" int
CREATE TABLE IF NOT EXISTS "devops_github_repository_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_githubrepository" ("gitrepository_ptr_id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "devops_gitlab_repository_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_gitlabrepository" ("gitrepository_ptr_id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "devops_git_group_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_gitgroup" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "access_organization_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "access_organization_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "access_organization_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_usersettings" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "default_organization_id" integer NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "timezone" varchar(32) NOT NULL, "browser_mode" integer NOT NULL);
CREATE TABLE IF NOT EXISTS "settings_appsettings" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "device_model_is_global" bool NOT NULL, "device_type_is_global" bool NOT NULL, "manufacturer_is_global" bool NOT NULL, "software_is_global" bool NOT NULL, "software_categories_is_global" bool NOT NULL, "global_organization_id" integer NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "owner_organization_id" integer NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "access_company" ("entity_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED, "name" varchar(80) NOT NULL);
@ -203,6 +202,9 @@ 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_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 "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);
@ -210,16 +212,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',206);
INSERT INTO sqlite_sequence VALUES('django_content_type',189);
INSERT INTO sqlite_sequence VALUES('auth_permission',801);
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('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_cluster',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);
@ -264,6 +265,7 @@ 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',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_cluster):
yield model_cluster
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_cluster):
request.cls.kwargs_create_item = kwargs_cluster.copy()
yield kwargs_cluster.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
@ -20,6 +19,8 @@ from itim.models.clusters import Cluster, ClusterType
@pytest.mark.model_cluster
@pytest.mark.module_itim
class ClusterAPI(
TestCase,
APITenancyObject

View File

@ -1,3 +1,4 @@
import pytest
from django.shortcuts import reverse
from django.test import Client, TestCase
@ -10,6 +11,8 @@ from itim.models.clusters import Cluster
@pytest.mark.model_cluster
@pytest.mark.module_itim
class ClusterItemTicketAPI(
ItemTicketAPI,
TestCase,

View File

@ -1,16 +1,107 @@
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 Cluster
class ClusterModel(
TenancyObjectInheritedCases,
TestCase,
@pytest.mark.model_cluster
class ClusterModelTestCases(
CenturionAbstractModelInheritedCases
):
model = Cluster
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': str,
'value': 'cluster'
},
}
@property
def parameterized_model_fields(self):
return {
'parent_cluster': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': True,
'unique': False,
},
'cluster_type': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': True,
'unique': False,
},
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.IntegerField,
'length': 50,
'null': False,
'unique': False,
},
'config': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.JSONField,
'null': True,
'unique': False,
},
'nodes': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ManyToManyField,
'null': False,
'unique': False,
},
'devices': {
'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,
},
}
@pytest.mark.skip(reason="to be written")
def test_cluster_move_organization(user):
"""Move Organization test
When a cluster moves organization, clustersoftware and clustersoftware table data
must also move organizations
"""
pass
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 import ViewSet
@pytest.mark.model_cluster
@pytest.mark.module_itim
class ClusterViewsetList(
ModelViewSetInheritedCases,
TestCase,
@ -29,7 +33,7 @@ class ClusterViewsetList(
client = Client()
url = reverse(
self.route_name + '-list',
kwargs = self.kwargs

View File

@ -26,7 +26,7 @@ class Index(IndexViewset):
return Response(
{
"change": reverse('v2:_api_v2_ticket_change-list', request=request),
"cluster": reverse('v2:_api_v2_cluster-list', request=request),
"cluster": reverse('v2:_api_cluster-list', request=request),
"incident": reverse('v2:_api_v2_ticket_incident-list', request=request),
"problem": reverse('v2:_api_v2_ticket_problem-list', request=request),
"service": reverse('v2:_api_v2_service-list', request=request),

View File

@ -43,6 +43,11 @@ from .model_checkin import (
model_checkin,
)
from .model_cluster import (
kwargs_cluster,
model_cluster,
)
from .model_configgroup import (
kwargs_configgroups,
model_configgroups,

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

@ -0,0 +1,26 @@
import datetime
import pytest
from itim.models.clusters import Cluster
@pytest.fixture( scope = 'class')
def model_cluster():
yield Cluster
@pytest.fixture( scope = 'class')
def kwargs_cluster(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': 'cluster_' + random_str,
}
yield kwargs.copy()