Skip to content

Commit

Permalink
Merge pull request #3859 from vkWeb/fix/sync_channel_assessment_item
Browse files Browse the repository at this point in the history
Fixes `sync_channel` assessment item bug
  • Loading branch information
bjester authored Dec 2, 2022
2 parents 706d7d6 + f0986c7 commit b63e0a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
13 changes: 13 additions & 0 deletions contentcuration/contentcuration/tests/viewsets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
26 changes: 26 additions & 0 deletions contentcuration/contentcuration/tests/viewsets/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import uuid

import mock
from django.urls import reverse

from contentcuration import models
from contentcuration.tests import testdata
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion contentcuration/contentcuration/viewsets/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down

0 comments on commit b63e0a3

Please sign in to comment.