refactor(itim): Update Test Suite for Service model

ref: #824 #828
This commit is contained in:
2025-06-13 15:11:42 +09:30
parent fa7c70f2ce
commit f377ad102e
9 changed files with 176 additions and 14 deletions

View File

@ -105,10 +105,10 @@ 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 "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 "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_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 "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 "access_company" ("entity_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED, "name" varchar(80) NOT NULL);
CREATE TABLE IF NOT EXISTS "access_entity" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "entity_type" varchar(30) NOT NULL);
CREATE TABLE IF NOT EXISTS "access_person" ("entity_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED, "f_name" varchar(64) NOT NULL, "l_name" varchar(64) NOT NULL, "dob" date NULL, "m_name" varchar(100) NULL);
@ -233,8 +233,8 @@ INSERT INTO sqlite_sequence VALUES('core_ticket',0);
INSERT INTO sqlite_sequence VALUES('core_ticketcomment',0);
INSERT INTO sqlite_sequence VALUES('core_ticketlinkeditem',0);
INSERT INTO sqlite_sequence VALUES('settings_externallink',0);
INSERT INTO sqlite_sequence VALUES('settings_usersettings',0);
INSERT INTO sqlite_sequence VALUES('settings_appsettings',1);
INSERT INTO sqlite_sequence VALUES('settings_usersettings',0);
INSERT INTO sqlite_sequence VALUES('access_entity',0);
INSERT INTO sqlite_sequence VALUES('core_ticketbase',0);
INSERT INTO sqlite_sequence VALUES('core_ticketcommentbase',0);

View File

@ -47,7 +47,7 @@ class ClusterModelTestCases(
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.IntegerField,
'field_type': models.CharField,
'length': 50,
'null': False,
'unique': False,

View File

@ -0,0 +1,19 @@
import pytest
@pytest.fixture( scope = 'class')
def model(model_service):
yield model_service
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_service):
request.cls.kwargs_create_item = kwargs_service.copy()
yield kwargs_service.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
@ -21,6 +20,8 @@ from itim.models.services import Service, Port
@pytest.mark.model_service
@pytest.mark.module_itim
class ServiceAPI(
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.services import Service
@pytest.mark.model_service
@pytest.mark.module_itim
class ServiceItemTicketAPI(
ItemTicketAPI,
TestCase,

View File

@ -1,16 +1,120 @@
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.services import Service
class ServiceModel(
TenancyObjectInheritedCases,
TestCase,
@pytest.mark.model_service
class ServiceModelTestCases(
CenturionAbstractModelInheritedCases
):
model = Service
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': str,
'value': 'service'
},
}
@property
def parameterized_model_fields(self):
return {
'is_template': {
'blank': False,
'default': False,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'template': {
'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.CharField,
'length': 50,
'null': False,
'unique': False,
},
'device': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': True,
'unique': False,
},
'cluster': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': True,
'unique': False,
},
'config': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.JSONField,
'null': True,
'unique': False,
},
'config_key_variable': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'null': True,
'unique': False,
},
'port': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ManyToManyField,
'null': False,
'unique': False,
},
'dependent_service': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ManyToManyField,
'null': False,
'symmetrical': False,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class ServiceModelInheritedCases(
ServiceModelTestCases,
):
pass
@pytest.mark.module_itim
class ServiceModelPyTest(
ServiceModelTestCases,
):
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.service import ViewSet
@pytest.mark.model_service
@pytest.mark.module_itim
class ServiceViewsetList(
ModelViewSetInheritedCases,
TestCase,

View File

@ -168,6 +168,11 @@ from .model_port import (
model_port,
)
from .model_service import (
kwargs_service,
model_service,
)
from .model_software import (
kwargs_software,
model_software,

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

@ -0,0 +1,26 @@
import datetime
import pytest
from itim.models.services import Service
@pytest.fixture( scope = 'class')
def model_service():
yield Service
@pytest.fixture( scope = 'class')
def kwargs_service(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': 'service_' + random_str,
}
yield kwargs.copy()