refactor(core): Update Test Suite for TicketCommentSolution model
ref: #871 #866
This commit is contained in:
@ -10,6 +10,8 @@ class TicketCommentSolution(
|
||||
TicketCommentBase,
|
||||
):
|
||||
|
||||
_is_submodel = True
|
||||
|
||||
class Meta:
|
||||
|
||||
ordering = [
|
||||
@ -40,9 +42,9 @@ class TicketCommentSolution(
|
||||
code = 'ticket_already_solved'
|
||||
)
|
||||
|
||||
|
||||
|
||||
try:
|
||||
|
||||
|
||||
self.ticket.get_can_resolve(raise_exceptions = True)
|
||||
|
||||
except centurion_exception.ValidationError as err:
|
||||
@ -55,13 +57,18 @@ class TicketCommentSolution(
|
||||
)
|
||||
|
||||
|
||||
|
||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||
def clean_fields(self, exclude=None):
|
||||
|
||||
self.is_closed = True
|
||||
|
||||
self.date_closed = datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0).isoformat()
|
||||
|
||||
super().clean_fields(exclude = exclude)
|
||||
|
||||
|
||||
|
||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||
|
||||
super().save(force_insert = force_insert, force_update = force_update, using = using, update_fields = update_fields)
|
||||
|
||||
self.ticket.is_solved = self.is_closed
|
||||
@ -76,5 +83,3 @@ class TicketCommentSolution(
|
||||
if hasattr(self.ticket, '_ticket_comments'):
|
||||
|
||||
del self.ticket._ticket_comments
|
||||
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.ticket_comment_base.test_functional_ticket_comment_base_model import TicketCommentBaseModelInheritedTestCases
|
||||
|
||||
|
||||
@pytest.mark.model_ticketcommentsolution
|
||||
class TicketCommentSolutionModelTestCases(
|
||||
TicketCommentBaseModelInheritedTestCases
|
||||
):
|
||||
@ -21,6 +24,7 @@ class TicketCommentSolutionModelInheritedTestCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class TicketCommentSolutionModelPyTest(
|
||||
TicketCommentSolutionModelTestCases
|
||||
):
|
||||
|
@ -1,14 +1,20 @@
|
||||
import pytest
|
||||
|
||||
from core.models.ticket_comment_solution import TicketCommentSolution
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(request):
|
||||
def model(request, model_ticketcommentsolution):
|
||||
|
||||
request.cls.model = TicketCommentSolution
|
||||
request.cls.model = model_ticketcommentsolution
|
||||
|
||||
yield request.cls.model
|
||||
|
||||
del request.cls.model
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_ticketcommentsolution):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_ticketcommentsolution.copy()
|
||||
|
||||
yield kwargs_ticketcommentsolution.copy()
|
||||
|
@ -1,35 +1,136 @@
|
||||
import pytest
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
from django.apps import apps
|
||||
|
||||
from core.models.ticket_comment_solution import TicketCommentSolution
|
||||
|
||||
from core.tests.unit.ticket_comment_base.test_unit_ticket_comment_base_model import (
|
||||
TicketCommentBaseModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_ticketcommentsolution
|
||||
class TicketCommentSolutionModelTestCases(
|
||||
TicketCommentBaseModelInheritedCases,
|
||||
TicketCommentBaseModelInheritedCases
|
||||
):
|
||||
|
||||
sub_model_type = 'solution'
|
||||
"""Sub Model Type
|
||||
|
||||
sub-models must have this attribute defined in `ModelName.Meta.sub_model_type`
|
||||
"""
|
||||
|
||||
kwargs_create_item: dict = {
|
||||
'comment_type': sub_model_type,
|
||||
}
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'_audit_enabled': {
|
||||
'value': False
|
||||
},
|
||||
'_is_submodel': {
|
||||
'value': True
|
||||
},
|
||||
'_notes_enabled': {
|
||||
'value': False
|
||||
},
|
||||
'model_tag': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'url_model_name': {
|
||||
'type': str,
|
||||
'value': 'ticket_comment_base'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_class_inherits_ticketcommentsolution(self):
|
||||
@property
|
||||
def parameterized_model_fields(self):
|
||||
|
||||
return {}
|
||||
|
||||
@pytest.fixture( scope = 'function', autouse = True)
|
||||
def model_instance(cls, model_kwarg_data, model, model_kwargs):
|
||||
|
||||
class MockModel(model):
|
||||
class Meta:
|
||||
app_label = 'core'
|
||||
verbose_name = 'mock instance'
|
||||
managed = False
|
||||
|
||||
if 'mockmodel' in apps.all_models['core']:
|
||||
|
||||
del apps.all_models['core']['mockmodel']
|
||||
|
||||
if model._meta.abstract:
|
||||
|
||||
instance = MockModel()
|
||||
|
||||
else:
|
||||
|
||||
kwargs = model_kwargs
|
||||
|
||||
kwargs['ticket'].is_closed = False
|
||||
kwargs['ticket'].date_closed = None
|
||||
kwargs['ticket'].is_solved = False
|
||||
kwargs['ticket'].date_solved = None
|
||||
|
||||
kwargs['ticket'].status = kwargs['ticket'].TicketStatus.NEW
|
||||
|
||||
kwargs['ticket'].save()
|
||||
|
||||
instance = model_kwarg_data(
|
||||
model = model,
|
||||
model_kwargs = kwargs,
|
||||
create_instance = True,
|
||||
)
|
||||
|
||||
instance = instance['instance']
|
||||
|
||||
|
||||
yield instance
|
||||
|
||||
if 'mockmodel' in apps.all_models['core']:
|
||||
|
||||
del apps.all_models['core']['mockmodel']
|
||||
|
||||
if type(instance) is dict:
|
||||
|
||||
instance['instance'].delete()
|
||||
|
||||
elif instance.id and type(instance) is not MockModel:
|
||||
|
||||
instance.delete()
|
||||
|
||||
del instance
|
||||
|
||||
|
||||
|
||||
def test_method_centurion_save_called(self, mocker, model_instance):
|
||||
"""Test Class Method
|
||||
|
||||
Ensure method `core.mixins.centurion.Centurion.save()` is called
|
||||
when `model.save()` is called.
|
||||
"""
|
||||
|
||||
class MockManager:
|
||||
|
||||
def get(*args, **kwargs):
|
||||
return model_instance
|
||||
|
||||
model_instance.objects = MockManager()
|
||||
|
||||
save = mocker.patch('core.mixins.centurion.Centurion.save', return_value = None)
|
||||
|
||||
|
||||
model_instance.save()
|
||||
|
||||
save.assert_called()
|
||||
|
||||
|
||||
def test_class_inherits_ticketcommentsolution(self, model):
|
||||
""" Class inheritence
|
||||
|
||||
TenancyObject must inherit SaveHistory
|
||||
"""
|
||||
|
||||
assert issubclass(self.model, TicketCommentSolution)
|
||||
assert issubclass(model, TicketCommentSolution)
|
||||
|
||||
|
||||
|
||||
@ -45,8 +146,8 @@ class TicketCommentSolutionModelTestCases(
|
||||
|
||||
valid_data['ticket'] = ticket
|
||||
|
||||
del valid_data['external_system']
|
||||
del valid_data['external_ref']
|
||||
# del valid_data['external_system']
|
||||
# del valid_data['external_ref']
|
||||
|
||||
comment = model.objects.create(
|
||||
**valid_data
|
||||
@ -61,26 +162,14 @@ class TicketCommentSolutionModelTestCases(
|
||||
class TicketCommentSolutionModelInheritedCases(
|
||||
TicketCommentSolutionModelTestCases,
|
||||
):
|
||||
"""Sub-Ticket Test Cases
|
||||
|
||||
Test Cases for Ticket models that inherit from model TicketCommentSolution
|
||||
"""
|
||||
|
||||
kwargs_create_item: dict = {}
|
||||
|
||||
model = None
|
||||
|
||||
|
||||
sub_model_type = None
|
||||
"""Ticket Sub Model Type
|
||||
|
||||
Ticket sub-models must have this attribute defined in `ModelNam.Meta.sub_model_type`
|
||||
"""
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class TicketCommentSolutionModelPyTest(
|
||||
TicketCommentSolutionModelTestCases,
|
||||
):
|
||||
|
||||
pass
|
||||
sub_model_type = 'solution'
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from core.models.ticket_comment_solution import TicketCommentSolution
|
||||
@ -5,6 +7,7 @@ from core.tests.unit.ticket_comment_base.test_unit_ticket_comment_base_viewset i
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_ticketcommentsolution
|
||||
class TicketCommentSolutionViewsetTestCases(
|
||||
TicketCommentBaseViewsetInheritedCases,
|
||||
):
|
||||
@ -32,6 +35,7 @@ class TicketCommentSolutionViewsetInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class TicketCommentSolutionViewsetTest(
|
||||
TicketCommentSolutionViewsetTestCases,
|
||||
TestCase,
|
||||
|
@ -1,9 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.unit.ticket_comment_base.test_unit_ticket_comment_base_api_fields import (
|
||||
TicketCommentBaseAPIInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_ticketcommentsolution
|
||||
class TicketCommentSolutionAPITestCases(
|
||||
TicketCommentBaseAPIInheritedCases,
|
||||
):
|
||||
@ -24,6 +27,7 @@ class TicketCommentSolutionAPIInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class TicketCommentSolutionAPIPyTest(
|
||||
TicketCommentSolutionAPITestCases,
|
||||
):
|
||||
|
5
app/tests/fixtures/__init__.py
vendored
5
app/tests/fixtures/__init__.py
vendored
@ -288,6 +288,11 @@ from .model_ticketcommentbase import (
|
||||
model_ticketcommentbase,
|
||||
)
|
||||
|
||||
from .model_ticketcommentsolution import (
|
||||
kwargs_ticketcommentsolution,
|
||||
model_ticketcommentsolution,
|
||||
)
|
||||
|
||||
from .model_team import (
|
||||
kwargs_team,
|
||||
model_team,
|
||||
|
23
app/tests/fixtures/model_ticketcommentsolution.py
vendored
Normal file
23
app/tests/fixtures/model_ticketcommentsolution.py
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
|
||||
from core.models.ticket_comment_solution import TicketCommentSolution
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_ticketcommentsolution():
|
||||
|
||||
yield TicketCommentSolution
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_ticketcommentsolution(
|
||||
model_ticketcommentsolution, kwargs_ticketcommentbase,
|
||||
):
|
||||
|
||||
kwargs = {
|
||||
**kwargs_ticketcommentbase,
|
||||
'comment_type': model_ticketcommentsolution._meta.sub_model_type,
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
@ -1149,6 +1149,7 @@ markers = [
|
||||
"model_ticketcategory: Select all ticket category tests.",
|
||||
"model_ticketcommentaction: Select test for model ticket Action Comment.",
|
||||
"model_ticketcommentbase: Select all ticket Comment.",
|
||||
"model_ticketcommentsolution: Select test for model ticket Action Solution.",
|
||||
"model_ticketcommentcategory: Select all ticket comment category tests.",
|
||||
"models: Selects all models tests.",
|
||||
"model_tenant: Select all Tentant model tests.",
|
||||
|
Reference in New Issue
Block a user