Skip to content

Commit 988b990

Browse files
committed
refactor(itim): Update Test Suite for Cluster model
ref: #824 #825
1 parent 1419234 commit 988b990

9 files changed

Lines changed: 168 additions & 17 deletions

File tree

app/fixtures/fresh_db.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ CREATE TABLE IF NOT EXISTS "itim_cluster_devices" ("id" integer NOT NULL PRIMARY
1818
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);
1919
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);
2020
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);
21-
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);
2221
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);
2322
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);
2423
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
112111
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);
113112
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);
114113
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);
115-
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);
116114
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);
115+
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);
117116
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);
118117
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);
119118
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,23 +202,25 @@ CREATE TABLE IF NOT EXISTS "itam_softwarecategory_centurionmodelnote" ("centurio
203202
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);
204203
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);
205204
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);
205+
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);
206+
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);
207+
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);
206208
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);
207209
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);
208210
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);
209211
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);
210212
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)));
211213
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)));
212214
DELETE FROM sqlite_sequence;
213-
INSERT INTO sqlite_sequence VALUES('django_migrations',206);
214-
INSERT INTO sqlite_sequence VALUES('django_content_type',189);
215-
INSERT INTO sqlite_sequence VALUES('auth_permission',801);
215+
INSERT INTO sqlite_sequence VALUES('django_migrations',207);
216+
INSERT INTO sqlite_sequence VALUES('django_content_type',191);
217+
INSERT INTO sqlite_sequence VALUES('auth_permission',809);
216218
INSERT INTO sqlite_sequence VALUES('auth_group',0);
217219
INSERT INTO sqlite_sequence VALUES('auth_user',0);
218220
INSERT INTO sqlite_sequence VALUES('project_management_project',0);
219221
INSERT INTO sqlite_sequence VALUES('project_management_projectmilestone',0);
220222
INSERT INTO sqlite_sequence VALUES('project_management_projectstate',0);
221223
INSERT INTO sqlite_sequence VALUES('project_management_projecttype',0);
222-
INSERT INTO sqlite_sequence VALUES('itim_cluster',0);
223224
INSERT INTO sqlite_sequence VALUES('itim_clustertype',0);
224225
INSERT INTO sqlite_sequence VALUES('itim_port',0);
225226
INSERT INTO sqlite_sequence VALUES('itim_service',0);
@@ -264,6 +265,7 @@ INSERT INTO sqlite_sequence VALUES('itam_operatingsystemversion',0);
264265
INSERT INTO sqlite_sequence VALUES('itam_software',0);
265266
INSERT INTO sqlite_sequence VALUES('itam_softwarecategory',0);
266267
INSERT INTO sqlite_sequence VALUES('itam_softwareversion',0);
268+
INSERT INTO sqlite_sequence VALUES('itim_cluster',0);
267269
INSERT INTO sqlite_sequence VALUES('social_auth_association',0);
268270
INSERT INTO sqlite_sequence VALUES('social_auth_code',0);
269271
INSERT INTO sqlite_sequence VALUES('social_auth_nonce',0);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pytest
2+
3+
4+
5+
@pytest.fixture( scope = 'class')
6+
def model(model_cluster):
7+
8+
yield model_cluster
9+
10+
11+
@pytest.fixture( scope = 'class', autouse = True)
12+
def model_kwargs(request, kwargs_cluster):
13+
14+
request.cls.kwargs_create_item = kwargs_cluster.copy()
15+
16+
yield kwargs_cluster.copy()
17+
18+
if hasattr(request.cls, 'kwargs_create_item'):
19+
del request.cls.kwargs_create_item

app/itim/tests/unit/cluster/test_cluster_api_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import unittest
32

43
from django.contrib.auth.models import Permission, User
54
from django.contrib.contenttypes.models import ContentType
@@ -20,6 +19,8 @@
2019

2120

2221

22+
@pytest.mark.model_cluster
23+
@pytest.mark.module_itim
2324
class ClusterAPI(
2425
TestCase,
2526
APITenancyObject

app/itim/tests/unit/cluster/test_cluster_item_ticket_api_v2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12

23
from django.shortcuts import reverse
34
from django.test import Client, TestCase
@@ -10,6 +11,8 @@
1011

1112

1213

14+
@pytest.mark.model_cluster
15+
@pytest.mark.module_itim
1316
class ClusterItemTicketAPI(
1417
ItemTicketAPI,
1518
TestCase,
Lines changed: 99 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,107 @@
1-
from django.test import TestCase
1+
import pytest
22

3-
from centurion.tests.unit.test_unit_models import (
4-
TenancyObjectInheritedCases
3+
from django.db import models
4+
5+
6+
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
7+
CenturionAbstractModelInheritedCases
58
)
69

7-
from itim.models.clusters import Cluster
810

911

12+
@pytest.mark.model_cluster
13+
class ClusterModelTestCases(
14+
CenturionAbstractModelInheritedCases
15+
):
16+
17+
18+
@property
19+
def parameterized_class_attributes(self):
20+
21+
return {
22+
'model_tag': {
23+
'type': str,
24+
'value': 'cluster'
25+
},
26+
}
27+
28+
29+
@property
30+
def parameterized_model_fields(self):
1031

11-
class ClusterModel(
12-
TenancyObjectInheritedCases,
13-
TestCase,
32+
return {
33+
'parent_cluster': {
34+
'blank': True,
35+
'default': models.fields.NOT_PROVIDED,
36+
'field_type': models.ForeignKey,
37+
'null': True,
38+
'unique': False,
39+
},
40+
'cluster_type': {
41+
'blank': True,
42+
'default': models.fields.NOT_PROVIDED,
43+
'field_type': models.ForeignKey,
44+
'null': True,
45+
'unique': False,
46+
},
47+
'name': {
48+
'blank': False,
49+
'default': models.fields.NOT_PROVIDED,
50+
'field_type': models.IntegerField,
51+
'length': 50,
52+
'null': False,
53+
'unique': False,
54+
},
55+
'config': {
56+
'blank': True,
57+
'default': models.fields.NOT_PROVIDED,
58+
'field_type': models.JSONField,
59+
'null': True,
60+
'unique': False,
61+
},
62+
'nodes': {
63+
'blank': True,
64+
'default': models.fields.NOT_PROVIDED,
65+
'field_type': models.ManyToManyField,
66+
'null': False,
67+
'unique': False,
68+
},
69+
'devices': {
70+
'blank': True,
71+
'default': models.fields.NOT_PROVIDED,
72+
'field_type': models.ManyToManyField,
73+
'null': False,
74+
'unique': False,
75+
},
76+
'modified': {
77+
'blank': False,
78+
'default': models.fields.NOT_PROVIDED,
79+
'field_type': models.DateTimeField,
80+
'null': False,
81+
'unique': False,
82+
},
83+
}
84+
85+
86+
@pytest.mark.skip(reason="to be written")
87+
def test_cluster_move_organization(user):
88+
"""Move Organization test
89+
90+
When a cluster moves organization, clustersoftware and clustersoftware table data
91+
must also move organizations
92+
"""
93+
pass
94+
95+
96+
97+
class ClusterModelInheritedCases(
98+
ClusterModelTestCases,
1499
):
100+
pass
15101

16-
model = Cluster
102+
103+
@pytest.mark.module_itim
104+
class ClusterModelPyTest(
105+
ClusterModelTestCases,
106+
):
107+
pass

app/itim/tests/unit/cluster/test_unit_cluster_viewset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from django.test import Client, TestCase
24

35
from rest_framework.reverse import reverse
@@ -8,6 +10,8 @@
810

911

1012

13+
@pytest.mark.model_cluster
14+
@pytest.mark.module_itim
1115
class ClusterViewsetList(
1216
ModelViewSetInheritedCases,
1317
TestCase,
@@ -29,7 +33,7 @@ def setUpTestData(self):
2933

3034

3135
client = Client()
32-
36+
3337
url = reverse(
3438
self.route_name + '-list',
3539
kwargs = self.kwargs

app/itim/viewsets/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def list(self, request, pk=None):
2626
return Response(
2727
{
2828
"change": reverse('v2:_api_v2_ticket_change-list', request=request),
29-
"cluster": reverse('v2:_api_v2_cluster-list', request=request),
29+
"cluster": reverse('v2:_api_cluster-list', request=request),
3030
"incident": reverse('v2:_api_v2_ticket_incident-list', request=request),
3131
"problem": reverse('v2:_api_v2_ticket_problem-list', request=request),
3232
"service": reverse('v2:_api_v2_service-list', request=request),

app/tests/fixtures/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
model_checkin,
4444
)
4545

46+
from .model_cluster import (
47+
kwargs_cluster,
48+
model_cluster,
49+
)
50+
4651
from .model_configgroup import (
4752
kwargs_configgroups,
4853
model_configgroups,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import datetime
2+
import pytest
3+
4+
from itim.models.clusters import Cluster
5+
6+
7+
8+
@pytest.fixture( scope = 'class')
9+
def model_cluster():
10+
11+
yield Cluster
12+
13+
14+
@pytest.fixture( scope = 'class')
15+
def kwargs_cluster(kwargs_centurionmodel):
16+
17+
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
18+
random_str = str(random_str).replace(
19+
' ', '').replace(':', '').replace('+', '').replace('.', '')
20+
21+
kwargs = {
22+
**kwargs_centurionmodel.copy(),
23+
'name': 'cluster_' + random_str,
24+
}
25+
26+
yield kwargs.copy()

0 commit comments

Comments
 (0)