Skip to content

Commit 12f2dae

Browse files
committed
refactor(project_management): Update Test Suite for ProjectType model
ref: #833 #832
1 parent 3b7fda1 commit 12f2dae

8 files changed

Lines changed: 141 additions & 23 deletions

File tree

app/fixtures/fresh_db.sql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ CREATE TABLE IF NOT EXISTS "auth_group" ("id" integer NOT NULL PRIMARY KEY AUTOI
1010
CREATE TABLE IF NOT EXISTS "auth_user" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "password" varchar(128) NOT NULL, "last_login" datetime NULL, "is_superuser" bool NOT NULL, "username" varchar(150) NOT NULL UNIQUE, "last_name" varchar(150) NOT NULL, "email" varchar(254) NOT NULL, "is_staff" bool NOT NULL, "is_active" bool NOT NULL, "date_joined" datetime NOT NULL, "first_name" varchar(150) NOT NULL);
1111
CREATE TABLE IF NOT EXISTS "access_teamusers" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "manager" bool NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "team_id" integer NOT NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
1212
CREATE TABLE IF NOT EXISTS "project_management_project_team_members" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "project_id" integer NOT NULL REFERENCES "project_management_project" ("id") DEFERRABLE INITIALLY DEFERRED, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
13-
CREATE TABLE IF NOT EXISTS "project_management_projecttype" ("is_global" bool NOT NULL, "model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL UNIQUE, "runbook_id" integer NULL REFERENCES "assistance_knowledgebase" ("id") DEFERRABLE INITIALLY DEFERRED, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED);
1413
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);
1514
CREATE TABLE IF NOT EXISTS "core_ticket_assigned_teams" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "ticket_id" integer NOT NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED, "team_id" integer NOT NULL REFERENCES "access_team" ("group_ptr_id") DEFERRABLE INITIALLY DEFERRED);
1615
CREATE TABLE IF NOT EXISTS "core_ticket_assigned_users" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "ticket_id" integer NOT NULL REFERENCES "core_ticket" ("id") DEFERRABLE INITIALLY DEFERRED, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
@@ -104,8 +103,8 @@ CREATE TABLE IF NOT EXISTS "devops_gitlab_repository_notes" ("modelnotes_ptr_id"
104103
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);
105104
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);
106105
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);
107-
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);
108106
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);
107+
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);
109108
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);
110109
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);
111110
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);
@@ -217,27 +216,29 @@ CREATE TABLE IF NOT EXISTS "project_management_projectmilestone_centurionmodelno
217216
CREATE TABLE IF NOT EXISTS "project_management_projectstate" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL UNIQUE, "is_completed" bool NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "runbook_id" integer NULL REFERENCES "assistance_knowledgebase" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
218217
CREATE TABLE IF NOT EXISTS "project_management_projectstate_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projectstate" ("id") DEFERRABLE INITIALLY DEFERRED);
219218
CREATE TABLE IF NOT EXISTS "project_management_projectstate_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projectstate" ("id") DEFERRABLE INITIALLY DEFERRED);
219+
CREATE TABLE IF NOT EXISTS "project_management_projecttype" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "created" datetime NOT NULL, "modified" datetime NOT NULL, "name" varchar(50) NOT NULL UNIQUE, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED, "runbook_id" integer NULL REFERENCES "assistance_knowledgebase" ("id") DEFERRABLE INITIALLY DEFERRED, "model_notes" text NULL);
220+
CREATE TABLE IF NOT EXISTS "project_management_projecttype_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projecttype" ("id") DEFERRABLE INITIALLY DEFERRED);
221+
CREATE TABLE IF NOT EXISTS "project_management_projecttype_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "project_management_projecttype" ("id") DEFERRABLE INITIALLY DEFERRED);
220222
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);
221223
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);
222224
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);
223225
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);
224226
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)));
225227
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)));
226228
DELETE FROM sqlite_sequence;
227-
INSERT INTO sqlite_sequence VALUES('django_migrations',213);
228-
INSERT INTO sqlite_sequence VALUES('django_content_type',203);
229-
INSERT INTO sqlite_sequence VALUES('auth_permission',857);
229+
INSERT INTO sqlite_sequence VALUES('django_migrations',214);
230+
INSERT INTO sqlite_sequence VALUES('django_content_type',205);
231+
INSERT INTO sqlite_sequence VALUES('auth_permission',865);
230232
INSERT INTO sqlite_sequence VALUES('auth_group',0);
231233
INSERT INTO sqlite_sequence VALUES('auth_user',0);
232-
INSERT INTO sqlite_sequence VALUES('project_management_projecttype',0);
233234
INSERT INTO sqlite_sequence VALUES('core_notes',0);
234235
INSERT INTO sqlite_sequence VALUES('core_relatedtickets',0);
235236
INSERT INTO sqlite_sequence VALUES('core_ticket',0);
236237
INSERT INTO sqlite_sequence VALUES('core_ticketcomment',0);
237238
INSERT INTO sqlite_sequence VALUES('core_ticketlinkeditem',0);
238239
INSERT INTO sqlite_sequence VALUES('settings_externallink',0);
239-
INSERT INTO sqlite_sequence VALUES('settings_usersettings',0);
240240
INSERT INTO sqlite_sequence VALUES('settings_appsettings',1);
241+
INSERT INTO sqlite_sequence VALUES('settings_usersettings',0);
241242
INSERT INTO sqlite_sequence VALUES('access_entity',0);
242243
INSERT INTO sqlite_sequence VALUES('core_ticketbase',0);
243244
INSERT INTO sqlite_sequence VALUES('core_ticketcommentbase',0);
@@ -281,6 +282,7 @@ INSERT INTO sqlite_sequence VALUES('itim_service',0);
281282
INSERT INTO sqlite_sequence VALUES('project_management_project',0);
282283
INSERT INTO sqlite_sequence VALUES('project_management_projectmilestone',0);
283284
INSERT INTO sqlite_sequence VALUES('project_management_projectstate',0);
285+
INSERT INTO sqlite_sequence VALUES('project_management_projecttype',0);
284286
INSERT INTO sqlite_sequence VALUES('social_auth_association',0);
285287
INSERT INTO sqlite_sequence VALUES('social_auth_code',0);
286288
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_projecttype):
7+
8+
yield model_projecttype
9+
10+
11+
@pytest.fixture( scope = 'class', autouse = True)
12+
def model_kwargs(request, kwargs_projecttype):
13+
14+
request.cls.kwargs_create_item = kwargs_projecttype.copy()
15+
16+
yield kwargs_projecttype.copy()
17+
18+
if hasattr(request.cls, 'kwargs_create_item'):
19+
del request.cls.kwargs_create_item

app/project_management/tests/unit/project_type/test_project_type_api_v2.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
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
76
from django.shortcuts import reverse
87
from django.test import Client, TestCase
98

10-
from rest_framework.relations import Hyperlink
119

1210
from access.models.tenant import Tenant as Organization
1311
from access.models.team import Team
1412
from access.models.team_user import TeamUsers
1513

1614
from api.tests.abstract.api_fields import APITenancyObject
1715

18-
from assistance.models.knowledge_base import KnowledgeBase
16+
from assistance.models.knowledge_base import KnowledgeBase, KnowledgeBaseCategory
1917

2018
from project_management.models.project_types import ProjectType
2119

@@ -25,7 +23,8 @@
2523

2624

2725

28-
@pytest.mark.skip( reason = 'to be re-written' )
26+
@pytest.mark.model_projecttype
27+
@pytest.mark.module_project_management
2928
class ProjectTypeAPI(
3029
TestCase,
3130
APITenancyObject
@@ -45,9 +44,17 @@ def setUpTestData(self):
4544
self.organization = Organization.objects.create(name='test_org')
4645

4746

47+
self.view_user = User.objects.create_user(username="test_user_view", password="password")
48+
4849
kb = KnowledgeBase.objects.create(
4950
organization = self.organization,
50-
title = 'kb article'
51+
title = 'kb article',
52+
category = KnowledgeBaseCategory.objects.create(
53+
organization = self.organization,
54+
name = 'kb_cat'
55+
),
56+
responsible_user = self.view_user,
57+
target_user = self.view_user,
5158
)
5259

5360
self.item = self.model.objects.create(
@@ -73,10 +80,8 @@ def setUpTestData(self):
7380

7481
view_team.permissions.set([view_permissions])
7582

76-
self.view_user = User.objects.create_user(username="test_user_view", password="password")
77-
7883
user_settings = UserSettings.objects.get(user = self.view_user)
79-
84+
8085
user_settings.default_organization = self.organization
8186

8287
user_settings.save()
Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,71 @@
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 project_management.models.project_types import ProjectType
810

911

10-
class ProjectTypeModel(
11-
TenancyObjectInheritedCases,
12-
TestCase,
12+
@pytest.mark.model_projecttype
13+
class ProjectTypeModelTestCases(
14+
CenturionAbstractModelInheritedCases
15+
):
16+
17+
18+
@property
19+
def parameterized_class_attributes(self):
20+
21+
return {
22+
'model_tag': {
23+
'type': str,
24+
'value': 'project_type'
25+
},
26+
}
27+
28+
29+
@property
30+
def parameterized_model_fields(self):
31+
32+
return {
33+
'name': {
34+
'blank': False,
35+
'default': models.fields.NOT_PROVIDED,
36+
'field_type': models.CharField,
37+
'length': 100,
38+
'null': False,
39+
'unique': True,
40+
},
41+
'runbook': {
42+
'blank': True,
43+
'default': models.fields.NOT_PROVIDED,
44+
'field_type': models.ForeignKey,
45+
'null': True,
46+
'unique': False,
47+
},
48+
'modified': {
49+
'blank': False,
50+
'default': models.fields.NOT_PROVIDED,
51+
'field_type': models.DateTimeField,
52+
'null': False,
53+
'unique': False,
54+
},
55+
}
56+
57+
58+
59+
class ProjectTypeModelInheritedCases(
60+
ProjectTypeModelTestCases,
61+
):
62+
pass
63+
64+
65+
66+
@pytest.mark.module_project_management
67+
class ProjectTypeModelPyTest(
68+
ProjectTypeModelTestCases,
1369
):
1470

15-
model = ProjectType
71+
pass

app/project_management/tests/unit/project_type/test_unit_project_type_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
@@ -8,6 +10,8 @@
810

911

1012

13+
@pytest.mark.model_projecttype
14+
@pytest.mark.module_project_management
1115
class ProjectTypeViewsetList(
1216
ModelViewSetInheritedCases,
1317
TestCase,

app/tests/fixtures/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@
183183
model_projectstate,
184184
)
185185

186+
from .model_projecttype import (
187+
kwargs_projecttype,
188+
model_projecttype,
189+
)
190+
186191
from .model_service import (
187192
kwargs_service,
188193
model_service,
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 project_management.models.project_types import ProjectType
5+
6+
7+
8+
@pytest.fixture( scope = 'class')
9+
def model_projecttype():
10+
11+
yield ProjectType
12+
13+
14+
@pytest.fixture( scope = 'class')
15+
def kwargs_projecttype(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': 'projecttype_' + random_str,
24+
}
25+
26+
yield kwargs.copy()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ markers = [
10971097
"model_project: Selects tests for model Project.",
10981098
"model_projectmilestone: Selects tests for model Project Milestone.",
10991099
"model_projectstate: Selects tests for model Project State.",
1100+
"model_projecttype: Selects tests for model Project Type.",
11001101
"model_service: Selects tests for model Service.",
11011102
"model_software: Selects tests for model Software.",
11021103
"model_softwarecategory: Selects tests for model Software Category.",

0 commit comments

Comments
 (0)