示例#1
0
    def test_sync_files_add(self):
        """
        Test that calling sync_files successfully syncs a file added to the original node to
        the copied node.
        """

        assert not self.derivative_channel.has_changes()

        contentnode = self.channel.main_tree.children.first()

        target_child = None
        children = self.derivative_channel.main_tree.children.first(
        ).get_children()
        assert len(children) > 0
        for child in children:
            if child.title == contentnode.title:
                target_child = child
                break
        assert target_child is not None
        assert target_child.files.count() == contentnode.files.count()

        db_file = self._add_temp_file_to_content_node(contentnode)
        assert target_child.files.count() != contentnode.files.count()

        assert self.channel.has_changes()

        sync_channel(self.derivative_channel, sync_files=True)
        self.derivative_channel.main_tree.refresh_from_db()

        assert target_child.files.count() == contentnode.files.count()

        assert target_child.files.filter(
            checksum=db_file.checksum).count() == 1
        assert self.derivative_channel.has_changes()
示例#2
0
    def test_sync_files_add(self):
        """
        Test that calling sync_files successfully syncs a file added to the original node to
        the copied node.
        """

        self.assertFalse(self.derivative_channel.has_changes())

        contentnode = self.channel.main_tree.children.first()

        target_child = None
        children = self.derivative_channel.main_tree.children.first(
        ).get_children()
        self.assertTrue(len(children) > 0)
        for child in children:
            if child.title == contentnode.title:
                target_child = child
                break
        self.assertIsNotNone(target_child)
        self.assertEqual(target_child.files.count(), contentnode.files.count())

        db_file = self._add_temp_file_to_content_node(contentnode)
        self.assertNotEqual(target_child.files.count(),
                            contentnode.files.count())

        self.assertTrue(self.channel.has_changes())

        sync_channel(self.derivative_channel, sync_files=True)
        self.derivative_channel.main_tree.refresh_from_db()

        self.assertEqual(target_child.files.count(), contentnode.files.count())

        self.assertEqual(
            target_child.files.filter(checksum=db_file.checksum).count(), 1)
        self.assertTrue(self.derivative_channel.has_changes())
示例#3
0
文件: tasks.py 项目: toccotedd/studio
def sync_channel_task(self, user_id, channel_id, sync_attributes, sync_tags,
                      sync_files, sync_assessment_items, sync_sort_order):
    channel = Channel.objects.get(pk=channel_id)
    sync_channel(channel,
                 sync_attributes,
                 sync_tags,
                 sync_files,
                 sync_tags,
                 sync_sort_order,
                 task_object=self)
示例#4
0
    def test_sync_assessment_item_add(self):
        """
        Test that calling sync_assessment_items successfully syncs a file added to the original node to
        the copied node.
        """

        self.assertFalse(self.derivative_channel.has_changes())

        contentnode = (self.channel.main_tree.get_descendants().filter(
            kind_id=content_kinds.EXERCISE).first())

        target_child = self.derivative_channel.main_tree.get_descendants().get(
            source_node_id=contentnode.node_id)

        self.assertIsNotNone(target_child)
        self.assertEqual(target_child.assessment_items.count(),
                         contentnode.assessment_items.count())

        ai = AssessmentItem.objects.create(contentnode=contentnode)

        db_file = self._add_temp_file_to_assessment_item(ai)
        self.assertNotEqual(target_child.assessment_items.count(),
                            contentnode.assessment_items.count())

        sync_channel(self.derivative_channel, sync_assessment_items=True)
        self.derivative_channel.main_tree.refresh_from_db()

        self.assertEqual(target_child.assessment_items.count(),
                         contentnode.assessment_items.count())

        self.assertEqual(
            target_child.assessment_items.filter(
                assessment_id=ai.assessment_id).count(),
            1,
        )

        target_ai = target_child.assessment_items.get(
            assessment_id=ai.assessment_id)

        self.assertEqual(target_ai.files.count(), ai.files.count())

        self.assertEqual(
            target_ai.files.filter(checksum=db_file.checksum).count(), 1)

        self.assertTrue(self.derivative_channel.has_changes())
示例#5
0
    def test_sync_channel_noop(self):
        """
        Test that calling sync channel with no changed nodes does not change the target channel.
        """

        self.assertFalse(self.channel.has_changes())
        self.assertFalse(self.derivative_channel.has_changes())

        sync_channel(
            self.derivative_channel,
            sync_attributes=True,
            sync_tags=True,
            sync_files=True,
            sync_assessment_items=True,
        )

        self.assertFalse(self.channel.has_changes())
        self.assertFalse(self.derivative_channel.has_changes())
示例#6
0
def sync_channel_task(
    self,
    user_id,
    channel_id,
    sync_attributes,
    sync_tags,
    sync_files,
    sync_assessment_items,
):
    channel = Channel.objects.get(pk=channel_id)
    sync_channel(
        channel,
        sync_attributes,
        sync_tags,
        sync_files,
        sync_tags,
        progress_tracker=self.progress,
    )
示例#7
0
    def test_sync_channel_noop(self):
        """
        Test that calling sync channel with no changed nodes does not change the target channel.
        """

        assert not self.channel.has_changes()
        assert not self.derivative_channel.has_changes()

        # Syncing attributes, assessment items, and sort order can lead to changes
        # even directly after a copy, so we avoid syncing them for the no-op test.
        sync_channel(self.derivative_channel,
                     sync_attributes=False,
                     sync_tags=True,
                     sync_files=True,
                     sync_assessment_items=False,
                     sync_sort_order=False)

        assert not self.channel.has_changes()
        assert not self.derivative_channel.has_changes()