test: Migrate models to use refactored model tests
ref: #719 closes #708
This commit is contained in:
@ -1,41 +0,0 @@
|
||||
import pytest
|
||||
import unittest
|
||||
import requests
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
|
||||
from core.models.manufacturer import Manufacturer
|
||||
|
||||
|
||||
class ManufacturerModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = Manufacturer
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
. create an organization that is different to item
|
||||
2. Create a device
|
||||
3. create teams with each permission: view, add, change, delete
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=organization,
|
||||
name = 'man',
|
||||
)
|
@ -0,0 +1,27 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.manufacturer import Manufacturer
|
||||
|
||||
|
||||
class ManufacturerModelTestCases(
|
||||
TenancyObjectInheritedCases,
|
||||
):
|
||||
|
||||
kwargs_item_create = {
|
||||
'name': 'man'
|
||||
}
|
||||
|
||||
model = Manufacturer
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelTest(
|
||||
ManufacturerModelTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
@ -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 core.models.manufacturer_notes import ManufacturerNotes
|
||||
|
||||
|
||||
|
||||
class ManufacturerNotesModel(
|
||||
ModelNotesModel,
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ManufacturerNotes
|
||||
|
||||
|
||||
@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,
|
||||
)
|
||||
|
@ -0,0 +1,89 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.unit.test_unit_models import TenancyObjectInheritedCases
|
||||
|
||||
from core.models.model_notes import ModelNotes
|
||||
|
||||
|
||||
|
||||
class ModelNotesTestCases(
|
||||
TenancyObjectInheritedCases
|
||||
):
|
||||
|
||||
model = ModelNotes
|
||||
|
||||
|
||||
|
||||
class ModelNotesInheritedCases(
|
||||
ModelNotesTestCases
|
||||
):
|
||||
|
||||
kwargs_item_create = None
|
||||
|
||||
|
||||
model = None
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
if not hasattr(self, 'organization'):
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
if not hasattr(self, 'kwargs_create_related_model'):
|
||||
|
||||
if 'organization' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model: dict = {
|
||||
'organization': self.organization,
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
self.kwargs_create_related_model: dict = {}
|
||||
|
||||
|
||||
if 'organization' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model.update({
|
||||
'organization': self.organization,
|
||||
})
|
||||
|
||||
|
||||
if 'name' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model.update({
|
||||
'name': 'model for note'
|
||||
})
|
||||
|
||||
|
||||
|
||||
self.user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
self.kwargs_item_create = {
|
||||
'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(
|
||||
**self.kwargs_create_related_model,
|
||||
),
|
||||
'created_by': self.user,
|
||||
}
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
class ModelNotesTest(
|
||||
ModelNotesTestCases
|
||||
):
|
||||
|
||||
pass
|
@ -3,19 +3,36 @@ from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
from app.tests.unit.test_unit_models import TenancyObjectInheritedCases
|
||||
|
||||
from core.models.manufacturer_history import Manufacturer, ManufacturerHistory
|
||||
from core.models.manufacturer_history import Manufacturer
|
||||
from core.models.model_history import ModelHistory
|
||||
|
||||
|
||||
class ManufacturerModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
|
||||
class ModelHistoryTestCases(
|
||||
TenancyObjectInheritedCases
|
||||
):
|
||||
|
||||
model = ModelHistory
|
||||
|
||||
should_model_history_be_saved = True
|
||||
|
||||
|
||||
|
||||
class ModelHistoryInheritedCases(
|
||||
ModelHistoryTestCases
|
||||
):
|
||||
|
||||
model = None
|
||||
|
||||
|
||||
|
||||
class ModelHistoryTest(
|
||||
ModelHistoryTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
should_model_history_be_saved = False
|
||||
|
||||
|
||||
@ -37,23 +54,42 @@ class ManufacturerModel(
|
||||
name = 'man',
|
||||
)
|
||||
|
||||
|
||||
self.history_entry = ManufacturerHistory.objects.create(
|
||||
organization = self.organization,
|
||||
action = self.model.Actions.ADD,
|
||||
user = User.objects.create_user(
|
||||
self.kwargs_item_create = {
|
||||
'action': self.model.Actions.ADD,
|
||||
'user': User.objects.create_user(
|
||||
username="test_user_view", password="password", is_superuser=True
|
||||
),
|
||||
before = {},
|
||||
after = {},
|
||||
content_type = ContentType.objects.get(
|
||||
'before': {},
|
||||
'after': {},
|
||||
'content_type': ContentType.objects.get(
|
||||
app_label = model._meta.app_label,
|
||||
model = model._meta.model_name,
|
||||
),
|
||||
model = model,
|
||||
)
|
||||
}
|
||||
|
||||
self.item = ModelHistory.objects.get(
|
||||
pk = self.history_entry.pk
|
||||
)
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
def test_attribute_type_get_url(self):
|
||||
"""Attribute Type
|
||||
|
||||
This test case is a duplicate test of a case with the same name.
|
||||
This model does not require this attribute.
|
||||
|
||||
get_url is of type str
|
||||
"""
|
||||
|
||||
assert not hasattr(self, 'item.get_url')
|
||||
|
||||
|
||||
def test_attribute_type_get_url_kwargs(self):
|
||||
"""Attribute Type
|
||||
|
||||
This test case is a duplicate test of a case with the same name.
|
||||
This model does not require this attribute.
|
||||
|
||||
get_url_kwargs is of type dict
|
||||
"""
|
||||
|
||||
assert not hasattr(self, 'item.get_url_kwargs')
|
||||
|
@ -1,20 +1,16 @@
|
||||
import pytest
|
||||
import unittest
|
||||
import requests
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket import Ticket
|
||||
|
||||
|
||||
class TicketModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = Ticket
|
||||
@ -38,19 +34,16 @@ class TicketModel(
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.add_user = User.objects.create_user(username="test_user_add", password="password")
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=organization,
|
||||
title = 'A ticket',
|
||||
description = 'the ticket body',
|
||||
ticket_type = Ticket.TicketType.REQUEST,
|
||||
opened_by = self.add_user,
|
||||
status = int(Ticket.TicketStatus.All.NEW.value)
|
||||
)
|
||||
self.kwargs_item_create = {
|
||||
'title': 'A ticket',
|
||||
'description': 'the ticket body',
|
||||
'ticket_type': Ticket.TicketType.REQUEST,
|
||||
'opened_by': self.add_user,
|
||||
'status': int(Ticket.TicketStatus.All.NEW.value)
|
||||
}
|
||||
|
||||
super().setUpTestData()
|
||||
|
@ -1,51 +0,0 @@
|
||||
import pytest
|
||||
# import unittest
|
||||
# import requests
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
|
||||
from core.models.ticket.ticket_category import TicketCategory
|
||||
|
||||
|
||||
class TicketCategoryModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = TicketCategory
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
. create an organization that is different to item
|
||||
2. Create a device
|
||||
3. create teams with each permission: view, add, change, delete
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=organization,
|
||||
name = 'cat',
|
||||
)
|
||||
|
||||
|
||||
# def test_attribute_duration_ticket_value(self):
|
||||
# """Attribute value test
|
||||
|
||||
# This aattribute calculates the ticket duration from
|
||||
# it's comments. must return total time in seconds
|
||||
# """
|
||||
|
||||
# pass
|
@ -0,0 +1,15 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket_category import TicketCategory
|
||||
|
||||
|
||||
class TicketCategoryModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCategory
|
@ -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 core.models.ticket.ticket_category_notes import TicketCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesModel(
|
||||
ModelNotesModel,
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCategoryNotes
|
||||
|
||||
|
||||
@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,20 +1,20 @@
|
||||
import pytest
|
||||
# import unittest
|
||||
# import requests
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket_comment import Ticket, TicketComment
|
||||
|
||||
|
||||
class TicketCommentModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = TicketComment
|
||||
@ -38,15 +38,13 @@ class TicketCommentModel(
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.add_user = User.objects.create_user(username="test_user_add", password="password")
|
||||
|
||||
|
||||
self.ticket = Ticket.objects.create(
|
||||
organization=organization,
|
||||
organization = self.organization,
|
||||
title = 'A ticket',
|
||||
description = 'the ticket body',
|
||||
ticket_type = Ticket.TicketType.REQUEST,
|
||||
@ -54,11 +52,13 @@ class TicketCommentModel(
|
||||
status = int(Ticket.TicketStatus.All.NEW.value)
|
||||
)
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=organization,
|
||||
body = 'note',
|
||||
ticket = self.ticket,
|
||||
)
|
||||
self.kwargs_item_create = {
|
||||
'body': 'note',
|
||||
'ticket': self.ticket,
|
||||
}
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
def test_attribute_duration_ticket_value(self):
|
||||
@ -68,4 +68,33 @@ class TicketCommentModel(
|
||||
it's comments. must return total time in seconds
|
||||
"""
|
||||
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
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 ticket.org
|
||||
|
||||
Must not be able to create an item without an organization
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def test_create_no_exception_organization_match_ticket(self):
|
||||
""" organization must be same as ticket organization
|
||||
|
||||
during save, org is set from self.ticket.organization
|
||||
"""
|
||||
|
||||
kwargs_item_create = self.kwargs_item_create.copy()
|
||||
|
||||
del kwargs_item_create['organization']
|
||||
|
||||
comment = self.model.objects.create(
|
||||
**kwargs_item_create,
|
||||
)
|
||||
|
||||
assert comment.organization == comment.ticket.organization
|
@ -1,51 +0,0 @@
|
||||
import pytest
|
||||
# import unittest
|
||||
# import requests
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from app.tests.abstract.models import TenancyModel
|
||||
|
||||
from core.models.ticket.ticket_comment_category import TicketCommentCategory
|
||||
|
||||
|
||||
class TicketCommentCategoryModel(
|
||||
TestCase,
|
||||
TenancyModel
|
||||
):
|
||||
|
||||
model = TicketCommentCategory
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
. create an organization that is different to item
|
||||
2. Create a device
|
||||
3. create teams with each permission: view, add, change, delete
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=organization,
|
||||
name = 'ticket cat',
|
||||
)
|
||||
|
||||
|
||||
# def test_attribute_duration_ticket_value(self):
|
||||
# """Attribute value test
|
||||
|
||||
# This aattribute calculates the ticket duration from
|
||||
# it's comments. must return total time in seconds
|
||||
# """
|
||||
|
||||
# pass
|
@ -0,0 +1,15 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from app.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket_comment_category import TicketCommentCategory
|
||||
|
||||
|
||||
class TicketCommentCategoryModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCommentCategory
|
@ -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 core.models.ticket.ticket_comment_category_notes import TicketCommentCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesModel(
|
||||
ModelNotesModel,
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCommentCategoryNotes
|
||||
|
||||
|
||||
@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,5 +1,5 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
Reference in New Issue
Block a user