Skip to content

Commit

Permalink
Add test to ensure that initialization started signals are fired.
Browse files Browse the repository at this point in the history
Manually fire initialization started signal.
  • Loading branch information
rtibbles committed Sep 14, 2023
1 parent 7320330 commit 7898ed3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions morango/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ def create(self, request): # noqa: C901
is_push=is_a_push,
)

# Manually fire the initializing started signal, as the default context
# stage is initializing, so otherwise this never gets fired.
session_controller.signals.initializing.started.fire(context=context)

# If both client and ourselves allow async, we just return accepted status, and the client
# should PATCH the transfer_session to the appropriate stage. If not async, we wait until
# queuing is complete
Expand Down
8 changes: 8 additions & 0 deletions morango/sync/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ def connect(self, handler):
"""
self._handlers.append(handler)

def disconnect(self, handler):
"""
Removes a callable handler that would be called when the signal is fired.
:type handler: function
"""
self._handlers.remove(handler)

def fire(self, **kwargs):
"""
Fires the handler functions connected via `connect`.
Expand Down
15 changes: 15 additions & 0 deletions tests/testapp/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from django.utils import timezone
from django.utils.functional import SimpleLazyObject
from facility_profile.models import MyUser
from mock import Mock
from rest_framework.test import APITestCase as BaseTestCase

from .compat import EnvironmentVarGuard
from morango.api.serializers import BufferSerializer
from morango.api.serializers import CertificateSerializer
from morango.api.serializers import InstanceIDSerializer
from morango.api.viewsets import session_controller
from morango.constants import transfer_stages
from morango.constants import transfer_statuses
from morango.models.certificates import Certificate
Expand Down Expand Up @@ -790,6 +792,19 @@ def test_transfersession_creation_fails_for_nonexistent_syncsession(self):
syncsession=syncsession,
)

def test_transfersession_creation_calls_initializing_started_handler(self):
mock = Mock()
session_controller.signals.initializing.started.connect(mock)
try:

self.make_transfersession_creation_request(
filter=str(self.sub_subset_cert1_with_key.get_scope().write_filter),
push=True,
)
self.assertTrue(mock.called)
finally:
session_controller.signals.initializing.started.disconnect(mock)

def test_transfersession_can_be_deleted(self):

self.test_transfersession_can_be_created()
Expand Down

0 comments on commit 7898ed3

Please sign in to comment.