-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11101 from ozer550/Override_Cleanupsyncs
Garbage Collection Integration for Morango SyncSessions
- Loading branch information
Showing
5 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.core.management.base import CommandError | ||
from morango.management.commands.cleanupsyncs import Command as CleanupsyncCommand | ||
|
||
from kolibri.core.device.utils import device_provisioned | ||
|
||
|
||
class Command(CleanupsyncCommand): | ||
def handle(self, *args, **options): | ||
if not device_provisioned(): | ||
raise CommandError("Kolibri is unprovisioned") | ||
|
||
return super(Command, self).handle(*args, **options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import uuid | ||
|
||
import mock | ||
from django.test import TestCase | ||
from morango.sync.context import LocalSessionContext | ||
|
||
from kolibri.core.auth.kolibri_plugin import AuthSyncHook | ||
from kolibri.core.auth.kolibri_plugin import CleanUpTaskOperation | ||
|
||
|
||
@mock.patch("kolibri.core.auth.kolibri_plugin.cleanupsync") | ||
class CleanUpTaskOperationTestCase(TestCase): | ||
def setUp(self): | ||
self.context = mock.MagicMock( | ||
spec=LocalSessionContext(), | ||
filter=uuid.uuid4().hex, | ||
is_push=True, | ||
is_pull=False, | ||
sync_session=mock.MagicMock( | ||
spec="morango.sync.session.SyncSession", | ||
client_instance_id=uuid.uuid4().hex, | ||
server_instance_id=uuid.uuid4().hex, | ||
), | ||
) | ||
self.operation = CleanUpTaskOperation() | ||
|
||
def test_handle_initial__not_receiver(self, mock_task): | ||
self.context.is_receiver = False | ||
result = self.operation.handle_initial(self.context) | ||
self.assertFalse(result) | ||
mock_task.enqueue.assert_not_called() | ||
|
||
def test_handle_initial__is_server(self, mock_task): | ||
self.context.is_receiver = True | ||
self.context.is_server = True | ||
result = self.operation.handle_initial(self.context) | ||
self.assertFalse(result) | ||
mock_task.enqueue.assert_called_once_with( | ||
kwargs=dict( | ||
is_pull=self.context.is_pull, | ||
is_push=self.context.is_push, | ||
sync_filter=str(self.context.filter), | ||
client_instance_id=self.context.sync_session.client_instance_id, | ||
) | ||
) | ||
|
||
def test_handle_initial__not_server(self, mock_task): | ||
self.context.is_receiver = True | ||
self.context.is_server = False | ||
result = self.operation.handle_initial(self.context) | ||
self.assertFalse(result) | ||
mock_task.enqueue.assert_called_once_with( | ||
kwargs=dict( | ||
is_pull=self.context.is_pull, | ||
is_push=self.context.is_push, | ||
sync_filter=str(self.context.filter), | ||
server_instance_id=self.context.sync_session.server_instance_id, | ||
) | ||
) | ||
|
||
|
||
class AuthSyncHookTestCase(TestCase): | ||
def test_cleanup_operations(self): | ||
operation = AuthSyncHook().cleanup_operations[0] | ||
self.assertIsInstance(operation, CleanUpTaskOperation) |