示例#1
0
 def test_two_channels_no_annotation_collision_child_true(self):
     root_node = ContentNode.objects.create(
         title='test',
         id=uuid.uuid4().hex,
         content_id=uuid.uuid4().hex,
         channel_id=uuid.uuid4().hex,
         kind=content_kinds.TOPIC,
         available=False,
         coach_content=False,
     )
     ContentNode.objects.create(
         title='test1',
         id=uuid.uuid4().hex,
         content_id=uuid.uuid4().hex,
         channel_id=root_node.channel_id,
         parent=root_node,
         kind=content_kinds.VIDEO,
         available=True,
         coach_content=True,
     )
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     root_node.refresh_from_db()
     self.assertFalse(root_node.available)
     self.assertFalse(root_node.coach_content)
示例#2
0
 def test_no_content_nodes_coach_content(self):
     ContentNode.objects.all().update(available=True)
     ContentNode.objects.all().update(coach_content=False)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     self.assertEqual(
         ContentNode.objects.filter(coach_content=True).count(), 0)
示例#3
0
 def test_one_content_node_available(self):
     ContentNode.objects.filter(
         id='32a941fb77c2576e8f6b294cde4c3b0c').update(available=True)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     # Check parent is available
     self.assertTrue(
         ContentNode.objects.get(
             id='da7ecc42e62553eebc8121242746e88a').available)
示例#4
0
 def test_no_content_nodes_available(self):
     ContentNode.objects.filter(kind=content_kinds.TOPIC).update(
         available=True)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     # 2, as there are two childless topics in the fixture, these cannot exist in real databases
     self.assertEqual(
         ContentNode.objects.filter(kind=content_kinds.TOPIC).filter(
             available=True).count(), 2)
示例#5
0
 def test_all_root_content_nodes_coach_content(self):
     ContentNode.objects.all().update(available=True, coach_content=False)
     root_node = ContentNode.objects.get(parent__isnull=True)
     ContentNode.objects.filter(parent=root_node).exclude(
         kind=content_kinds.TOPIC).update(coach_content=True)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     root_node.refresh_from_db()
     self.assertFalse(root_node.coach_content)
示例#6
0
 def test_all_content_nodes_available(self):
     ContentNode.objects.exclude(kind=content_kinds.TOPIC).update(
         available=True)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     self.assertTrue(
         ContentNode.objects.get(
             id="da7ecc42e62553eebc8121242746e88a").available)
     self.assertTrue(
         ContentNode.objects.get(
             id="2e8bac07947855369fe2d77642dfc870").available)
示例#7
0
 def test_one_content_node_many_siblings_coach_content(self):
     ContentNode.objects.filter(kind=content_kinds.TOPIC).update(
         available=True)
     ContentNode.objects.filter(
         id='32a941fb77c2576e8f6b294cde4c3b0c').update(coach_content=True)
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     # Check parent is not marked as coach_content True because there are non-coach_content siblings
     self.assertFalse(
         ContentNode.objects.get(
             id='da7ecc42e62553eebc8121242746e88a').coach_content)
示例#8
0
 def test_one_child_node_coach_content(self):
     ContentNode.objects.all().update(available=True, coach_content=False)
     root_node = ContentNode.objects.get(parent__isnull=True)
     node = ContentNode.objects.filter(parent=root_node,
                                       kind=content_kinds.TOPIC).first()
     ContentNode.objects.create(
         title='test1',
         id=uuid.uuid4().hex,
         content_id=uuid.uuid4().hex,
         channel_id=root_node.channel_id,
         parent=node,
         kind=content_kinds.VIDEO,
         available=True,
         coach_content=True,
     )
     recurse_availability_up_tree(
         channel_id="6199dde695db4ee4ab392222d5af1e5c")
     root_node.refresh_from_db()
     node.refresh_from_db()
     self.assertFalse(root_node.coach_content)
     self.assertFalse(node.coach_content)
    def test_existing_localfiles_are_not_overwritten(self):

        with patch('kolibri.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_availability_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
示例#10
0
 def test_one_content_node_available(self):
     ContentNode.objects.filter(id='32a941fb77c2576e8f6b294cde4c3b0c').update(available=True)
     recurse_availability_up_tree(channel_id="6199dde695db4ee4ab392222d5af1e5c")
     # Check parent is available
     self.assertTrue(ContentNode.objects.get(id='da7ecc42e62553eebc8121242746e88a').available)
示例#11
0
 def test_no_content_nodes_available(self):
     ContentNode.objects.filter(kind=content_kinds.TOPIC).update(available=True)
     recurse_availability_up_tree(channel_id="6199dde695db4ee4ab392222d5af1e5c")
     # 2, as there are two childless topics in the fixture, these cannot exist in real databases
     self.assertEqual(ContentNode.objects.filter(kind=content_kinds.TOPIC).filter(available=True).count(), 2)
示例#12
0
 def test_all_content_nodes_available(self):
     ContentNode.objects.exclude(kind=content_kinds.TOPIC).update(available=True)
     recurse_availability_up_tree(channel_id="6199dde695db4ee4ab392222d5af1e5c")
     self.assertTrue(ContentNode.objects.get(id="da7ecc42e62553eebc8121242746e88a").available)
     self.assertTrue(ContentNode.objects.get(id="2e8bac07947855369fe2d77642dfc870").available)