From 14deec8704d97152392d0cf8f39bf28925721597 Mon Sep 17 00:00:00 2001 From: Wolkenfarmer Date: Wed, 16 Oct 2024 16:56:52 +0200 Subject: [PATCH] #330 backend: fix tests --- .../game/tests/test_channel_notifications.py | 17 ++++++++++++----- .../game/tests/test_resource_assignment.py | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/backend/dps_training_k/game/tests/test_channel_notifications.py b/backend/dps_training_k/game/tests/test_channel_notifications.py index 9af47c1b..ca18c3ca 100644 --- a/backend/dps_training_k/game/tests/test_channel_notifications.py +++ b/backend/dps_training_k/game/tests/test_channel_notifications.py @@ -1,13 +1,15 @@ +from unittest.mock import patch + from django.test import TestCase + +import game.channel_notifications as cn +from game.models import ActionInstanceStateNames from .factories import ( ActionInstanceFactory, ActionInstanceStateFactory, PatientFactory, ) from .mixin import TestUtilsMixin -import game.channel_notifications as cn -from game.models import ActionInstanceStateNames -from unittest.mock import patch class ChannelNotifierTestCase(TestUtilsMixin, TestCase): @@ -28,11 +30,16 @@ def test_action_dispatcher(self, notify_group_mock): previous_function_calls = notify_group_mock.call_count action_instance.save(update_fields=["current_state"]) - self.assertEqual(notify_group_mock.call_count, previous_function_calls + 1) + self.assertEqual( + notify_group_mock.call_count, previous_function_calls + 2 + ) # action list & continuous variables @patch.object(cn.ChannelNotifier, "_notify_group") def test_patient_dispatcher(self, notify_group_mock): patient_instance = PatientFactory() previous_function_calls = notify_group_mock.call_count patient_instance.save(update_fields=["patient_state"]) - self.assertEqual(notify_group_mock.call_count, previous_function_calls + 1) + + self.assertEqual( + notify_group_mock.call_count, previous_function_calls + 2 + ) # state & continuous variables diff --git a/backend/dps_training_k/game/tests/test_resource_assignment.py b/backend/dps_training_k/game/tests/test_resource_assignment.py index 48a2df33..d093e44d 100644 --- a/backend/dps_training_k/game/tests/test_resource_assignment.py +++ b/backend/dps_training_k/game/tests/test_resource_assignment.py @@ -45,18 +45,23 @@ def test_channel_notifications_being_send( """ self.deactivate_live_updates() self.material_instance.try_moving_to(self.area) + # as the resource is already assigned to the area, no notification should be sent self.assertEqual(_notify_exercise_update.call_count, 0) - self.assertEqual( - _notify_group.call_count, 0 - ) # as the resource is already assigned to the area, no notification should be sent + self.assertEqual(_notify_group.call_count, 0) self.material_instance.try_moving_to(self.lab) - self.assertEqual(_notify_exercise_update.call_count, 0) - self.assertEqual(_notify_group.call_count, 1) + self.assertEqual( + _notify_exercise_update.call_count, 1 + ) # lab should be outside of area -> exercise update + self.assertEqual(_notify_group.call_count, 1) # + assignment self.material_instance.try_moving_to(self.patient) - self.assertEqual(_notify_exercise_update.call_count, 0) - self.assertEqual(_notify_group.call_count, 2) + self.assertEqual( + _notify_exercise_update.call_count, 2 + ) # patient should be inside of area again -> exercise update + self.assertEqual( + _notify_group.call_count, 3 + ) # + assignment & + continuous_variable self.activate_live_updates() def test_resource_block_and_release(self):