From a6e0f4e7289357986185b9256c24c82936f5f2dd Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 10 May 2025 16:46:13 +0930 Subject: [PATCH] test(core): ensure slash command is called on ticket comment ref: #744 #726 --- .../test_unit_ticket_comment_base_model.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/app/core/tests/unit/ticket_comment_base/test_unit_ticket_comment_base_model.py b/app/core/tests/unit/ticket_comment_base/test_unit_ticket_comment_base_model.py index 95c6c569..0457c6c1 100644 --- a/app/core/tests/unit/ticket_comment_base/test_unit_ticket_comment_base_model.py +++ b/app/core/tests/unit/ticket_comment_base/test_unit_ticket_comment_base_model.py @@ -186,6 +186,7 @@ class TicketCommentBaseModelTestCases( ticket = TicketBase.objects.create( organization = request.cls.organization, title = 'tester comment ticket', + description = 'aa', opened_by = request.cls.view_user, ) @@ -480,6 +481,28 @@ class TicketCommentBaseModelTestCases( assert spy.assert_called_once + def test_function_save_called_slash_command(self, model, mocker, ticket): + """Function Check + + Ensure function `TicketCommentBase.clean` is called + """ + + spy = mocker.spy(self.model, 'slash_command') + + valid_data = self.kwargs_create_item.copy() + + valid_data['ticket'] = ticket + + del valid_data['external_system'] + del valid_data['external_ref'] + + item = model.objects.create( + **valid_data + ) + + spy.assert_called_with(item, valid_data['body']) + + class TicketCommentBaseModelInheritedCases( TicketCommentBaseModelTestCases, @@ -526,3 +549,28 @@ class TicketCommentBaseModelPyTest( ) assert err.value.get_codes()['date_closed'] == 'ticket_closed_no_date' + + + def test_function_save_called_slash_command(self, model, mocker, ticket): + """Function Check + + This test case is a duplicate of a test with the same name. This + test is required so that the base class `save()` function can be tested. + + Ensure function `TicketCommentBase.clean` is called + """ + + spy = mocker.spy(self.model, 'slash_command') + + valid_data = self.kwargs_create_item.copy() + + valid_data['ticket'] = ticket + + del valid_data['external_system'] + del valid_data['external_ref'] + + item = model.objects.create( + **valid_data + ) + + spy.assert_called_with(item, valid_data['body'])