Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure initialization signals get fired during sync #201

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading