Skip to content

Commit 234e853

Browse files
committed
refactor(itam): Update Test Suite for SoftwareVersion model
ref: #823 #822
1 parent 9151018 commit 234e853

6 files changed

Lines changed: 95 additions & 37 deletions

File tree

app/fixtures/fresh_db.sql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ CREATE TABLE IF NOT EXISTS "core_relatedtickets" ("id" integer NOT NULL PRIMARY
3232
CREATE TABLE IF NOT EXISTS "core_ticket" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "status" integer NOT NULL, "title" varchar(100) NOT NULL UNIQUE, "description" text NOT NULL, "urgency" integer NULL, "impact" integer NULL, "priority" integer NULL, "external_ref" integer NULL, "external_system" integer NULL, "ticket_type" integer NOT NULL, "is_deleted" bool NOT NULL, "date_closed" datetime NULL, "planned_start_date" datetime NULL, "planned_finish_date" datetime NULL, "estimate" integer NOT NULL, "real_start_date" datetime NULL, "real_finish_date" datetime NULL, "milestone_id" integer NULL REFERENCES "project_management_projectmilestone" ("id") DEFERRABLE INITIALLY DEFERRED, "opened_by_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "project_id" integer NULL REFERENCES "project_management_project" ("id") DEFERRABLE INITIALLY DEFERRED, "category_id" integer NULL REFERENCES "core_ticketcategory" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "parent_ticket_id" integer NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED);
3333
CREATE TABLE IF NOT EXISTS "core_ticketcomment" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "external_ref" integer NULL, "external_system" integer NULL, "comment_type" integer NOT NULL, "body" text NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "private" bool NOT NULL, "duration" integer NOT NULL, "is_template" bool NOT NULL, "source" integer NOT NULL, "status" integer NOT NULL, "date_closed" datetime NULL, "planned_start_date" datetime NULL, "planned_finish_date" datetime NULL, "real_start_date" datetime NULL, "real_finish_date" datetime NULL, "responsible_team_id" integer NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED, "responsible_user_id" integer NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "ticket_id" integer NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED, "user_id" integer NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "category_id" integer NULL REFERENCES "core_ticketcommentcategory" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "parent_id" integer NULL REFERENCES "core_ticketcomment" ("id") DEFERRABLE INITIALLY DEFERRED, "template_id" integer NULL REFERENCES "core_ticketcomment" ("id") DEFERRABLE INITIALLY DEFERRED);
3434
CREATE TABLE IF NOT EXISTS "core_ticketlinkeditem" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "item_type" integer NOT NULL, "item" integer NOT NULL, "ticket_id" integer NOT NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
35-
CREATE TABLE IF NOT EXISTS "itam_softwareversion" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "slug" varchar(50) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL, "software_id" integer NOT NULL REFERENCES "itam_software" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
3635
CREATE TABLE IF NOT EXISTS "core_model_notes" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "content" text NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "content_type_id" integer NOT NULL REFERENCES "django_content_type" ("id") DEFERRABLE INITIALLY DEFERRED, "created_by_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "modified_by_id" integer NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
3736
CREATE TABLE IF NOT EXISTS "config_management_config_group_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "config_management_configgroups" ("id") DEFERRABLE INITIALLY DEFERRED);
3837
CREATE TABLE IF NOT EXISTS "access_team_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED);
@@ -115,8 +114,8 @@ CREATE TABLE IF NOT EXISTS "devops_gitlab_repository_notes" ("modelnotes_ptr_id"
115114
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);
116115
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 "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);
118-
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);
119117
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);
118+
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);
120119
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);
121120
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);
122121
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);
@@ -201,16 +200,19 @@ CREATE TABLE IF NOT EXISTS "itam_software_centurionmodelnote" ("centurionmodelno
201200
CREATE TABLE IF NOT EXISTS "itam_softwarecategory" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "name" varchar(50) NOT NULL UNIQUE, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
202201
CREATE TABLE IF NOT EXISTS "itam_softwarecategory_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itam_softwarecategory" ("id") DEFERRABLE INITIALLY DEFERRED);
203202
CREATE TABLE IF NOT EXISTS "itam_softwarecategory_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "itam_softwarecategory" ("id") DEFERRABLE INITIALLY DEFERRED);
203+
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);
204+
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);
205+
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);
204206
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);
205207
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);
206208
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);
207209
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);
208210
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)));
209211
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)));
210212
DELETE FROM sqlite_sequence;
211-
INSERT INTO sqlite_sequence VALUES('django_migrations',205);
212-
INSERT INTO sqlite_sequence VALUES('django_content_type',187);
213-
INSERT INTO sqlite_sequence VALUES('auth_permission',793);
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);
214216
INSERT INTO sqlite_sequence VALUES('auth_group',0);
215217
INSERT INTO sqlite_sequence VALUES('auth_user',0);
216218
INSERT INTO sqlite_sequence VALUES('project_management_project',0);
@@ -226,10 +228,9 @@ INSERT INTO sqlite_sequence VALUES('core_relatedtickets',0);
226228
INSERT INTO sqlite_sequence VALUES('core_ticket',0);
227229
INSERT INTO sqlite_sequence VALUES('core_ticketcomment',0);
228230
INSERT INTO sqlite_sequence VALUES('core_ticketlinkeditem',0);
229-
INSERT INTO sqlite_sequence VALUES('itam_softwareversion',0);
230231
INSERT INTO sqlite_sequence VALUES('settings_externallink',0);
231-
INSERT INTO sqlite_sequence VALUES('settings_appsettings',1);
232232
INSERT INTO sqlite_sequence VALUES('settings_usersettings',0);
233+
INSERT INTO sqlite_sequence VALUES('settings_appsettings',1);
233234
INSERT INTO sqlite_sequence VALUES('access_entity',0);
234235
INSERT INTO sqlite_sequence VALUES('core_ticketbase',0);
235236
INSERT INTO sqlite_sequence VALUES('core_ticketcommentbase',0);
@@ -262,6 +263,7 @@ INSERT INTO sqlite_sequence VALUES('itam_operatingsystem',0);
262263
INSERT INTO sqlite_sequence VALUES('itam_operatingsystemversion',0);
263264
INSERT INTO sqlite_sequence VALUES('itam_software',0);
264265
INSERT INTO sqlite_sequence VALUES('itam_softwarecategory',0);
266+
INSERT INTO sqlite_sequence VALUES('itam_softwareversion',0);
265267
INSERT INTO sqlite_sequence VALUES('social_auth_association',0);
266268
INSERT INTO sqlite_sequence VALUES('social_auth_code',0);
267269
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_softwareversion):
7+
8+
yield model_softwareversion
9+
10+
11+
@pytest.fixture( scope = 'class', autouse = True)
12+
def model_kwargs(request, kwargs_softwareversion):
13+
14+
request.cls.kwargs_create_item = kwargs_softwareversion.copy()
15+
16+
yield kwargs_softwareversion.copy()
17+
18+
if hasattr(request.cls, 'kwargs_create_item'):
19+
del request.cls.kwargs_create_item

app/itam/tests/unit/software_version/test_software_version_api_v2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import django
22
import pytest
3-
import unittest
43

54
from django.contrib.auth.models import Permission
65
from django.contrib.contenttypes.models import ContentType
@@ -21,6 +20,8 @@
2120

2221

2322

23+
@pytest.mark.model_softwareversion
24+
@pytest.mark.module_itam
2425
class SoftwareVersionCategoryAPI(
2526
TestCase,
2627
APITenancyObject
Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,69 @@
1-
from django.test import TestCase
1+
import pytest
22

3-
from access.models.tenant import Tenant as Organization
3+
from django.db import models
44

5-
from centurion.tests.unit.test_unit_models import (
6-
TenancyObjectInheritedCases
7-
)
85

9-
from itam.models.software import Software, SoftwareVersion
6+
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
7+
CenturionAbstractModelInheritedCases
8+
)
109

1110

1211

13-
class SoftwareVersionModel(
14-
TenancyObjectInheritedCases,
15-
TestCase,
12+
@pytest.mark.model_softwareversion
13+
class SoftwareVersionModelTestCases(
14+
CenturionAbstractModelInheritedCases
1615
):
1716

18-
model = SoftwareVersion
19-
2017

21-
@classmethod
22-
def setUpTestData(self):
23-
"""Setup Test
18+
@property
19+
def parameterized_class_attributes(self):
2420

25-
1. Create an organization for user and item
26-
. create an organization that is different to item
27-
2. Create a device
28-
3. create teams with each permission: view, add, change, delete
29-
4. create a user per team
30-
"""
21+
return {
22+
'model_tag': {
23+
'value': 'software_version'
24+
},
25+
}
3126

32-
self.organization = Organization.objects.create(name='test_org')
3327

34-
self.software = Software.objects.create(
35-
organization = self.organization,
36-
name = 'deviceone'
37-
)
28+
@property
29+
def parameterized_model_fields(self):
3830

39-
self.kwargs_item_create = {
40-
'name': '12',
41-
'software': self.software
31+
return {
32+
'software': {
33+
'blank': False,
34+
'default': models.fields.NOT_PROVIDED,
35+
'field_type': models.ForeignKey,
36+
'null': False,
37+
'unique': False,
38+
},
39+
'name': {
40+
'blank': False,
41+
'default': models.fields.NOT_PROVIDED,
42+
'field_type': models.CharField,
43+
'length': 50,
44+
'null': False,
45+
'unique': False,
46+
},
47+
'modified': {
48+
'blank': False,
49+
'default': models.fields.NOT_PROVIDED,
50+
'field_type': models.DateTimeField,
51+
'null': False,
52+
'unique': False,
53+
},
4254
}
4355

44-
super().setUpTestData()
56+
57+
58+
class SoftwareVersionModelInheritedCases(
59+
SoftwareVersionModelTestCases,
60+
):
61+
pass
62+
63+
64+
65+
@pytest.mark.module_itam
66+
class SoftwareVersionModelPyTest(
67+
SoftwareVersionModelTestCases,
68+
):
69+
pass

app/itam/tests/unit/software_version/test_unit_software_version_viewset.py

Lines changed: 4 additions & 0 deletions
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
@@ -9,6 +11,8 @@
911

1012

1113

14+
@pytest.mark.model_softwareversion
15+
@pytest.mark.module_itam
1216
class SoftwareVersionViewsetList(
1317
ModelViewSetInheritedCases,
1418
TestCase,

app/tests/fixtures/model_softwareversion.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ def kwargs_softwareversion(django_db_blocker,
1818
):
1919

2020
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
21+
random_str = str(random_str).replace(
22+
' ', '').replace(':', '').replace('+', '').replace('.', '')
2123

2224
with django_db_blocker.unblock():
2325

26+
kwargs = kwargs_software
27+
kwargs.update({
28+
'name': 'sv_' + random_str
29+
})
30+
2431
software = model_software.objects.create( **kwargs_software )
2532

2633
kwargs = {

0 commit comments

Comments
 (0)