Skip to content

Commit

Permalink
#330 backend: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Oct 16, 2024
1 parent 5f0fcb0 commit 14deec8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
17 changes: 12 additions & 5 deletions backend/dps_training_k/game/tests/test_channel_notifications.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
19 changes: 12 additions & 7 deletions backend/dps_training_k/game/tests/test_resource_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 14deec8

Please sign in to comment.