Example #1
0
    def test_all_local_files_available_include_orignial_exclude_duplicate_topic(
            self):
        ContentNode.objects.all().update(available=False)
        LocalFile.objects.all().update(available=True)
        parent = ContentNode.objects.get(title="c3")
        copy = ContentNode.objects.get(title="c2c1")
        original_id = copy.id
        copy.id = uuid.uuid4().hex
        copy.parent = None
        copy.lft = None
        copy.rght = None
        copy.tree_id = None
        copy.save()
        copy.move_to(parent)
        copy.save()
        original = ContentNode.objects.get(id=original_id)
        for file in original.files.all():
            file.id = uuid.uuid4().hex
            file.contentnode = copy
            file.save()
        exclude_ids = [parent.id]

        set_leaf_node_availability_from_local_file_availability(
            test_channel_id,
            node_ids=[original.parent.id],
            exclude_node_ids=exclude_ids)
        self.assertEqual(ContentNode.objects.filter(title="c2c1").count(), 2)
        self.assertEqual(
            ContentNode.objects.filter(title="c2c1", available=True).count(),
            1)
Example #2
0
 def test_all_local_files_available(self):
     LocalFile.objects.all().update(available=True)
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id)
     self.assertTrue(
         all(
             ContentNode.objects.exclude(kind=content_kinds.TOPIC).exclude(
                 files=None).values_list("available", flat=True)))
Example #3
0
 def test_all_local_files_available_include_one(self):
     ContentNode.objects.all().update(available=False)
     LocalFile.objects.all().update(available=True)
     include_ids = [
         ContentNode.objects.exclude(kind=content_kinds.TOPIC).first().id
     ]
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id, node_ids=include_ids)
     self.assertEqual(ContentNode.objects.filter(available=True).count(), 1)
Example #4
0
 def test_no_local_files_available(self):
     LocalFile.objects.all().update(available=False)
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id)
     self.assertEqual(
         ContentNode.objects.exclude(kind=content_kinds.TOPIC).filter(
             available=True).count(),
         0,
     )
Example #5
0
 def test_other_channel_node_still_available(self):
     test = ContentNode.objects.filter(kind=content_kinds.VIDEO).first()
     test.id = uuid.uuid4().hex
     test.channel_id = uuid.uuid4().hex
     test.available = True
     test.parent = None
     test.save()
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id)
     test.refresh_from_db()
     self.assertTrue(test.available)
Example #6
0
 def test_all_local_files_available_exclude_root(self):
     ContentNode.objects.all().update(available=False)
     LocalFile.objects.all().update(available=True)
     exclude_ids = list(
         ContentNode.objects.filter(parent__isnull=True).values_list(
             "id", flat=True))
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id, exclude_node_ids=exclude_ids)
     self.assertFalse(
         any(
             ContentNode.objects.exclude(kind=content_kinds.TOPIC).exclude(
                 files=None).values_list("available", flat=True)))
Example #7
0
 def test_one_local_file_available(self):
     LocalFile.objects.all().update(available=False)
     LocalFile.objects.filter(id="6bdfea4a01830fdd4a585181c0b8068c").update(
         available=True)
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id)
     self.assertTrue(
         ContentNode.objects.get(
             id="32a941fb77c2576e8f6b294cde4c3b0c").available)
     self.assertFalse(
         all(
             ContentNode.objects.exclude(kind=content_kinds.TOPIC).exclude(
                 id="32a941fb77c2576e8f6b294cde4c3b0c").values_list(
                     "available", flat=True)))
Example #8
0
 def test_all_local_files_available_non_include_exclude_unaffected(self):
     ContentNode.objects.all().update(available=False)
     LocalFile.objects.all().update(available=True)
     exclude = ContentNode.objects.get(title="c3")
     include = ContentNode.objects.get(title="c2")
     node = ContentNode.objects.get(title="copy", kind=content_kinds.VIDEO)
     self.assertFalse(node.available)
     node.available = True
     node.save()
     set_leaf_node_availability_from_local_file_availability(
         test_channel_id,
         node_ids=[include.id],
         exclude_node_ids=[exclude.id])
     node.refresh_from_db()
     self.assertTrue(node.available)
Example #9
0
    def test_existing_localfiles_are_not_overwritten(self):

        with patch(
                "kolibri.core.content.utils.sqlalchemybridge.get_engine",
                new=self.get_engine,
        ):

            channel_id = "6199dde695db4ee4ab392222d5af1e5c"

            channel = ChannelMetadata.objects.get(id=channel_id)

            # mark LocalFile objects as available
            for f in channel.root.children.first().files.all():
                f.local_file.available = True
                f.local_file.save()

            # channel's not yet available, as we haven't done the annotation
            assert not channel.root.available

            # propagate availability up the tree
            set_leaf_node_availability_from_local_file_availability(channel_id)
            recurse_annotation_up_tree(channel_id=channel_id)

            # after reloading, channel should now be available
            channel.root.refresh_from_db()
            assert channel.root.available

            # set the channel version to a low number to ensure we trigger a re-import of metadata
            ChannelMetadata.objects.filter(id=channel_id).update(version=-1)

            # reimport the metadata
            self.set_content_fixture()

            # after reloading, the files and their ancestor ContentNodes should all still be available
            channel.root.refresh_from_db()
            assert channel.root.available
            assert channel.root.children.first().available
            assert channel.root.children.first().files.all()[0].available
            assert channel.root.children.first().files.all(
            )[0].local_file.available