test: Migrate models to use refactored model tests
ref: #719 closes #708
This commit is contained in:
@ -1,44 +0,0 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
|
||||
from assistance.models.knowledge_base import KnowledgeBase
|
||||
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class KnowledgeBaseModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = KnowledgeBase
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
title = 'one',
|
||||
content = 'dict({"key": "one", "existing": "dont_over_write"})'
|
||||
)
|
||||
|
||||
self.second_item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
title = 'one_two',
|
||||
content = 'dict({"key": "two"})',
|
||||
)
|
@ -0,0 +1,21 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from assistance.models.knowledge_base import KnowledgeBase
|
||||
|
||||
|
||||
|
||||
class KnowledgeBaseModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
kwargs_item_create = {
|
||||
'title': 'one',
|
||||
'content': 'dict({"key": "one", "existing": "dont_over_write"})'
|
||||
}
|
||||
|
||||
model = KnowledgeBase
|
@ -1,42 +0,0 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
|
||||
from assistance.models.knowledge_base import KnowledgeBaseCategory
|
||||
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class KnowledgeBaseModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = KnowledgeBaseCategory
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'one',
|
||||
)
|
||||
|
||||
self.second_item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'one_two',
|
||||
)
|
@ -0,0 +1,16 @@
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from assistance.models.knowledge_base import KnowledgeBaseCategory
|
||||
|
||||
|
||||
|
||||
class KnowledgeBaseModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = KnowledgeBaseCategory
|
@ -1,37 +1,16 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.test_unit_model_notes_model import ModelNotesModel
|
||||
from core.tests.unit.model_notes.test_unit_model_notes_model import (
|
||||
ModelNotesInheritedCases
|
||||
)
|
||||
|
||||
from assistance.models.knowledge_base_category_notes import KnowledgeCategoryBaseNotes
|
||||
|
||||
|
||||
|
||||
class KnowledgeCategoryBaseNotesModel(
|
||||
ModelNotesModel,
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = KnowledgeCategoryBaseNotes
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment for an exiting item',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model existing item',
|
||||
),
|
||||
created_by = self.user,
|
||||
)
|
||||
|
@ -1,38 +1,16 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.test_unit_model_notes_model import ModelNotesModel
|
||||
from core.tests.unit.model_notes.test_unit_model_notes_model import (
|
||||
ModelNotesInheritedCases
|
||||
)
|
||||
|
||||
from assistance.models.knowledge_base_notes import KnowledgeBaseNotes
|
||||
|
||||
|
||||
|
||||
class KnowledgeBaseNotesNotesModel(
|
||||
ModelNotesModel,
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = KnowledgeBaseNotes
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment for an exiting item',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
title = 'note model existing item',
|
||||
content = 'sadsadsad',
|
||||
),
|
||||
created_by = self.user,
|
||||
)
|
||||
|
@ -1,11 +1,13 @@
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from assistance.models.model_knowledge_base_article import KnowledgeBase, ModelKnowledgeBaseArticle
|
||||
|
||||
@ -13,10 +15,9 @@ from itam.models.device import Device
|
||||
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class ModelKnowledgeBaseArticleModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = ModelKnowledgeBaseArticle
|
||||
@ -35,12 +36,18 @@ class ModelKnowledgeBaseArticleModel(
|
||||
self.organization_two = Organization.objects.create(name='test_org_two')
|
||||
|
||||
knowledge_base = KnowledgeBase.objects.create(
|
||||
organization = self.organization_two,
|
||||
organization = self.organization,
|
||||
title = 'title',
|
||||
content = 'sdfsdf'
|
||||
)
|
||||
|
||||
knowledge_base_two = KnowledgeBase.objects.create(
|
||||
self.knowledge_base = KnowledgeBase.objects.create(
|
||||
organization = self.organization,
|
||||
title = 'title two',
|
||||
content = 'sdfsdfdsf'
|
||||
)
|
||||
|
||||
KnowledgeBase.objects.create(
|
||||
organization = self.organization_two,
|
||||
title = 'title two',
|
||||
content = 'sdfsdf'
|
||||
@ -52,17 +59,13 @@ class ModelKnowledgeBaseArticleModel(
|
||||
)
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
article = knowledge_base,
|
||||
model = str( self.device._meta.app_label ) + '.' + str( self.device._meta.model_name ),
|
||||
model_pk = self.device.id
|
||||
)
|
||||
self.kwargs_item_create = {
|
||||
'article': knowledge_base,
|
||||
'model': str( self.device._meta.app_label ) + '.' + str( self.device._meta.model_name ),
|
||||
'model_pk': self.device.id
|
||||
}
|
||||
|
||||
self.second_item = self.model.objects.create(
|
||||
article = knowledge_base_two,
|
||||
model = str( self.device._meta.app_label ) + '.' + str( self.device._meta.model_name ),
|
||||
model_pk = self.device.id
|
||||
)
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
@ -103,3 +106,35 @@ class ModelKnowledgeBaseArticleModel(
|
||||
|
||||
assert self.item.get_url() is None
|
||||
|
||||
|
||||
def test_create_validation_exception_no_organization(self):
|
||||
""" Tenancy objects must have an organization
|
||||
|
||||
This test case is a duplicate of a test with the same name. this
|
||||
model does not require this test as the org is derived from the model.org
|
||||
|
||||
Must not be able to create an item without an organization
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def test_create_no_validation_exception_organization_match_model(self):
|
||||
""" Tenancy objects must have an organization
|
||||
|
||||
Must not be able to create an item without an organization
|
||||
"""
|
||||
|
||||
kwargs_item_create = self.kwargs_item_create.copy()
|
||||
|
||||
kwargs_item_create.update({
|
||||
'article': self.knowledge_base
|
||||
})
|
||||
|
||||
del kwargs_item_create['organization']
|
||||
|
||||
article = self.model.objects.create(
|
||||
**kwargs_item_create,
|
||||
)
|
||||
|
||||
assert article.organization == self.organization
|
Reference in New Issue
Block a user