refactor(settings): Update Test Suite for ExternalLink model

ref: #833 #835
This commit is contained in:
2025-06-16 13:39:47 +09:30
parent fdbf9f81db
commit 4a3f2ae6db
7 changed files with 179 additions and 17 deletions

View File

@ -37,7 +37,6 @@ CREATE TABLE IF NOT EXISTS "project_management_project_history" ("modelhistory_p
CREATE TABLE IF NOT EXISTS "project_management_projectmilestone_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projectmilestone" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "project_management_projectstate_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projectstate" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "project_management_projecttype_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projecttype" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_externallink" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL UNIQUE, "template" varchar(180) NOT NULL, "colour" varchar(80) NULL, "devices" bool NOT NULL, "software" bool NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "cluster" bool NOT NULL, "service" bool NOT NULL, "button_text" varchar(30) NULL UNIQUE);
CREATE TABLE IF NOT EXISTS "settings_external_link_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_externallink" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_appsettings_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_appsettings" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_externallink_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_externallink" ("id") DEFERRABLE INITIALLY DEFERRED);
@ -101,8 +100,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_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 "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_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);
@ -221,15 +220,18 @@ CREATE TABLE IF NOT EXISTS "project_management_projecttype_centurionmodelnote" (
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 "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_appsettings_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_appsettings" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_externallink" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(30) NOT NULL UNIQUE, "template" varchar(180) NOT NULL, "colour" varchar(80) NULL, "devices" bool NOT NULL, "software" bool NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "cluster" bool NOT NULL, "service" bool NOT NULL, "button_text" varchar(30) NULL UNIQUE, "model_notes" text NULL);
CREATE TABLE IF NOT EXISTS "settings_externallink_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_externallink" ("id") DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE IF NOT EXISTS "settings_externallink_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "settings_externallink" ("id") DEFERRABLE INITIALLY DEFERRED);
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);
CREATE TABLE IF NOT EXISTS "social_auth_nonce" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "server_url" varchar(255) NOT NULL, "timestamp" integer NOT NULL, "salt" varchar(65) NOT NULL);
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',215);
INSERT INTO sqlite_sequence VALUES('django_content_type',206);
INSERT INTO sqlite_sequence VALUES('auth_permission',869);
INSERT INTO sqlite_sequence VALUES('django_migrations',216);
INSERT INTO sqlite_sequence VALUES('django_content_type',208);
INSERT INTO sqlite_sequence VALUES('auth_permission',877);
INSERT INTO sqlite_sequence VALUES('auth_group',0);
INSERT INTO sqlite_sequence VALUES('auth_user',0);
INSERT INTO sqlite_sequence VALUES('core_notes',0);
@ -237,7 +239,6 @@ INSERT INTO sqlite_sequence VALUES('core_relatedtickets',0);
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('access_entity',0);
INSERT INTO sqlite_sequence VALUES('core_ticketbase',0);
@ -284,6 +285,7 @@ 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('settings_appsettings',1);
INSERT INTO sqlite_sequence VALUES('settings_externallink',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_externallink):
yield model_externallink
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_externallink):
request.cls.kwargs_create_item = kwargs_externallink.copy()
yield kwargs_externallink.copy()
if hasattr(request.cls, 'kwargs_create_item'):
del request.cls.kwargs_create_item

View File

@ -1,13 +1,11 @@
import django
import pytest
import unittest
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import reverse
from django.test import Client, TestCase
from rest_framework.relations import Hyperlink
from access.models.tenant import Tenant as Organization
from access.models.team import Team
@ -22,6 +20,8 @@ User = django.contrib.auth.get_user_model()
@pytest.mark.model_externallink
@pytest.mark.module_settings
class ExternalLinkAPI(
TestCase,
APITenancyObject

View File

@ -1,16 +1,122 @@
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 settings.models.external_link import ExternalLink
class ExternalLinkTests(
TenancyObjectInheritedCases,
TestCase,
@pytest.mark.model_externallink
class AppSettingsModelTestCases(
CenturionAbstractModelInheritedCases
):
model = ExternalLink
@property
def parameterized_class_attributes(self):
return {
'model_tag': {
'type': models.fields.NOT_PROVIDED,
'value': models.fields.NOT_PROVIDED
},
}
@property
def parameterized_model_fields(self):
return {
'name': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'length': 30,
'null': False,
'unique': True,
},
'button_text': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'length': 30,
'null': True,
'unique': True,
},
'template': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'length': 180,
'null': False,
'unique': False,
},
'colour': {
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.CharField,
'length': 180,
'null': True,
'unique': False,
},
'cluster': {
'blank': False,
'default': False,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'devices': {
'blank': False,
'default': False,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'service': {
'blank': False,
'default': False,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'software': {
'blank': False,
'default': False,
'field_type': models.BooleanField,
'null': False,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class AppSettingsModelInheritedCases(
AppSettingsModelTestCases,
):
pass
@pytest.mark.module_settings
class AppSettingsModelPyTest(
AppSettingsModelTestCases,
):
def test_model_tag_defined(self, model):
""" Model Tag
Ensure that the model has a tag defined.
"""
pytest.xfail( reason = 'Model does not require tag' )

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 settings.viewsets.external_link import ViewSet
@pytest.mark.model_externallink
@pytest.mark.module_settings
class ExternalLinksViewsetList(
ModelViewSetInheritedCases,
TestCase,

View File

@ -102,6 +102,11 @@ from .model_devicetype import (
model_devicetype,
)
from .model_externallink import (
kwargs_externallink,
model_externallink,
)
from .model_featureflag import (
kwargs_featureflag,
model_featureflag,

View File

@ -0,0 +1,26 @@
import datetime
import pytest
from settings.models.external_link import ExternalLink
@pytest.fixture( scope = 'class')
def model_externallink():
yield ExternalLink
@pytest.fixture( scope = 'class')
def kwargs_externallink( 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': 'el' + random_str,
'button_text': 'bt' + random_str,
'template': 'boo'
}
yield kwargs.copy()