Skip to content

Commit

Permalink
Merge pull request #11854 from rtibbles/cleanupsyncs_push_me_pull_you
Browse files Browse the repository at this point in the history
Pass the correct kwargs to the cleanupsyncs management command.
  • Loading branch information
bjester authored Feb 12, 2024
2 parents b46cbb5 + 7dd81e5 commit 5c30fde
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 32 deletions.
9 changes: 3 additions & 6 deletions kolibri/core/auth/kolibri_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def handle_initial(self, context):
from kolibri.core.device.utils import device_provisioned

if context.is_receiver and device_provisioned():
is_pull = context.is_pull
is_push = context.is_push
pull = context.is_pull
push = context.is_push
sync_filter = str(context.filter)

instance_kwargs = {}
Expand All @@ -51,10 +51,7 @@ def handle_initial(self, context):

cleanupsync.enqueue(
kwargs=dict(
is_pull=is_pull,
is_push=is_push,
sync_filter=sync_filter,
**instance_kwargs
pull=pull, push=push, sync_filter=sync_filter, **instance_kwargs
)
)

Expand Down
14 changes: 6 additions & 8 deletions kolibri/core/auth/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,20 +613,18 @@ def deletefacility(facility):


class CleanUpSyncsValidator(JobValidator):
is_pull = serializers.BooleanField(required=False)
is_push = serializers.BooleanField(required=False)
pull = serializers.BooleanField(required=False)
push = serializers.BooleanField(required=False)
sync_filter = serializers.CharField(required=True)
client_instance_id = HexOnlyUUIDField(required=False)
server_instance_id = HexOnlyUUIDField(required=False)

def validate(self, data):
if data.get("is_pull") is None and data.get("is_push") is None:
if data.get("pull") is None and data.get("push") is None:
raise serializers.ValidationError("Either pull or push must be specified")
elif data.get("pull") is data.get("push"):
raise serializers.ValidationError(
"Either is_pull or is_push must be specified"
)
elif data.get("is_pull") is data.get("is_push"):
raise serializers.ValidationError(
"Only one of is_pull or is_push needs to be specified"
"Only one of pull or push needs to be specified"
)

if (
Expand Down
26 changes: 12 additions & 14 deletions kolibri/core/auth/test/test_auth_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,26 +802,24 @@ class CleanUpSyncsTaskValidatorTestCase(TestCase):
def setUp(self):
self.kwargs = dict(
type=cleanupsync.__name__,
is_push=True,
is_pull=False,
push=True,
pull=False,
sync_filter=uuid4().hex,
client_instance_id=uuid4().hex,
)

def test_validator__no_push_no_pull(self):
self.kwargs.pop("is_push")
self.kwargs.pop("is_pull")
self.kwargs.pop("push")
self.kwargs.pop("pull")
validator = CleanUpSyncsValidator(data=self.kwargs)
with self.assertRaisesRegex(
serializers.ValidationError, "Either is_pull or is_push"
):
with self.assertRaisesRegex(serializers.ValidationError, "Either pull or push"):
validator.is_valid(raise_exception=True)

def test_validator__both_push_and_pull(self):
self.kwargs.update(is_pull=True)
self.kwargs.update(pull=True)
validator = CleanUpSyncsValidator(data=self.kwargs)
with self.assertRaisesRegex(
serializers.ValidationError, "Only one of is_pull or is_push"
serializers.ValidationError, "Only one of pull or push"
):
validator.is_valid(raise_exception=True)

Expand Down Expand Up @@ -853,8 +851,8 @@ def test_validator__no_sync_filter(self):
class CleanUpSyncsTaskTestCase(TestCase):
def setUp(self):
self.kwargs = dict(
is_push=True,
is_pull=False,
push=True,
pull=False,
sync_filter=uuid4().hex,
client_instance_id=uuid4().hex,
)
Expand All @@ -876,8 +874,8 @@ def test_calls_command(self, mock_call_command):
mock_call_command.assert_called_with(
"cleanupsyncs",
expiration=1,
is_push=self.kwargs["is_push"],
is_pull=self.kwargs["is_pull"],
push=self.kwargs["push"],
pull=self.kwargs["pull"],
sync_filter=self.kwargs["sync_filter"],
client_instance_id=self.kwargs["client_instance_id"],
)
Expand All @@ -903,7 +901,7 @@ def _create_sync(self, last_activity_timestamp=None, client_instance_id=None):
id=uuid4().hex,
active=True,
sync_session=sync_session,
push=self.kwargs["is_push"],
push=self.kwargs["push"],
filter=self.kwargs["sync_filter"],
last_activity_timestamp=last_activity_timestamp,
)
Expand Down
8 changes: 4 additions & 4 deletions kolibri/core/auth/test/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_handle_initial__is_server(self, mock_task):
self.assertFalse(result)
mock_task.enqueue.assert_called_once_with(
kwargs=dict(
is_pull=self.context.is_pull,
is_push=self.context.is_push,
pull=self.context.is_pull,
push=self.context.is_push,
sync_filter=str(self.context.filter),
client_instance_id=self.context.sync_session.client_instance_id.hex,
)
Expand All @@ -53,8 +53,8 @@ def test_handle_initial__not_server(self, mock_task):
self.assertFalse(result)
mock_task.enqueue.assert_called_once_with(
kwargs=dict(
is_pull=self.context.is_pull,
is_push=self.context.is_push,
pull=self.context.is_pull,
push=self.context.is_push,
sync_filter=str(self.context.filter),
server_instance_id=self.context.sync_session.server_instance_id.hex,
)
Expand Down

0 comments on commit 5c30fde

Please sign in to comment.