diff --git a/contentcuration/contentcuration/tests/viewsets/base.py b/contentcuration/contentcuration/tests/viewsets/base.py index 5eca0415fe..48ddd1c995 100644 --- a/contentcuration/contentcuration/tests/viewsets/base.py +++ b/contentcuration/contentcuration/tests/viewsets/base.py @@ -5,6 +5,9 @@ from contentcuration.celery import app from contentcuration.models import Change from contentcuration.tests.helpers import clear_tasks +from contentcuration.viewsets.sync.constants import CHANNEL +from contentcuration.viewsets.sync.constants import SYNCED +from contentcuration.viewsets.sync.utils import _generate_event as base_generate_event from contentcuration.viewsets.sync.utils import generate_copy_event as base_generate_copy_event from contentcuration.viewsets.sync.utils import generate_create_event as base_generate_create_event from contentcuration.viewsets.sync.utils import generate_delete_event as base_generate_delete_event @@ -35,6 +38,16 @@ def generate_update_event(*args, **kwargs): return event +def generate_sync_channel_event(channel_id, attributes, tags, files, assessment_items): + event = base_generate_event(key=channel_id, table=CHANNEL, event_type=SYNCED, channel_id=channel_id, user_id=None) + event["rev"] = random.randint(1, 10000000) + event["attributes"] = attributes + event["tags"] = tags + event["files"] = files + event["assessment_items"] = assessment_items + return event + + class SyncTestMixin(object): celery_task_always_eager = None diff --git a/contentcuration/contentcuration/tests/viewsets/test_channel.py b/contentcuration/contentcuration/tests/viewsets/test_channel.py index 63b0940ae4..b88f54ad98 100644 --- a/contentcuration/contentcuration/tests/viewsets/test_channel.py +++ b/contentcuration/contentcuration/tests/viewsets/test_channel.py @@ -2,6 +2,7 @@ import uuid +import mock from django.urls import reverse from contentcuration import models @@ -9,6 +10,7 @@ from contentcuration.tests.base import StudioAPITestCase from contentcuration.tests.viewsets.base import generate_create_event from contentcuration.tests.viewsets.base import generate_delete_event +from contentcuration.tests.viewsets.base import generate_sync_channel_event from contentcuration.tests.viewsets.base import generate_update_event from contentcuration.tests.viewsets.base import SyncTestMixin from contentcuration.viewsets.sync.constants import CHANNEL @@ -273,6 +275,30 @@ def test_cannot_delete_some_channels(self): self.assertTrue(models.Channel.objects.get(id=channel1.id).deleted) self.assertFalse(models.Channel.objects.get(id=channel2.id).deleted) + @mock.patch("contentcuration.viewsets.channel.sync_channel") + def test_sync_channel_called_correctly(self, sync_channel_mock): + user = testdata.user() + channel = testdata.channel() + channel.editors.add(user) + channel_node = channel.main_tree.get_descendants().first() + channel_node.copy_to(target=channel.main_tree) + + self.client.force_authenticate(user=user) + for i in range(1, 5): + sync_channel_mock.reset_mock() + args = [channel.id, False, False, False, False] + args[i] = True + + response = self.sync_changes( + [ + generate_sync_channel_event(*args) + ] + ) + + self.assertEqual(response.status_code, 200) + self.assertEqual(sync_channel_mock.call_args.args[i], True) + sync_channel_mock.assert_called_once() + class CRUDTestCase(StudioAPITestCase): @property diff --git a/contentcuration/contentcuration/viewsets/channel.py b/contentcuration/contentcuration/viewsets/channel.py index 9c739cbdfe..81646d0626 100644 --- a/contentcuration/contentcuration/viewsets/channel.py +++ b/contentcuration/contentcuration/viewsets/channel.py @@ -559,7 +559,7 @@ def sync(self, pk, attributes=False, tags=False, files=False, assessment_items=F attributes, tags, files, - tags, + assessment_items, progress_tracker=progress_tracker, )