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_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") root_node.refresh_from_db() self.assertFalse(root_node.available) self.assertFalse(root_node.coach_content)
def test_no_content_nodes_coach_content(self): ContentNode.objects.all().update(available=True) ContentNode.objects.all().update(coach_content=False) recurse_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") self.assertEqual( ContentNode.objects.filter(coach_content=True).count(), 0) root = ChannelMetadata.objects.get(id=test_channel_id).root self.assertEqual(root.num_coach_contents, 0)
def test_one_content_node_available(self): ContentNode.objects.filter( id="32a941fb77c2576e8f6b294cde4c3b0c").update(available=True) recurse_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") # Check parent is available self.assertTrue( ContentNode.objects.get( id="da7ecc42e62553eebc8121242746e88a").available)
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_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") root_node.refresh_from_db() self.assertFalse(root_node.coach_content) self.assertEqual(root_node.num_coach_contents, 2)
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_annotation_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)
def test_all_content_nodes_available_coach_content(self): ContentNode.objects.exclude(kind=content_kinds.TOPIC).update( available=True, coach_content=True) recurse_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") self.assertTrue( ContentNode.objects.get( id="da7ecc42e62553eebc8121242746e88a").coach_content) self.assertTrue( ContentNode.objects.get( id="2e8bac07947855369fe2d77642dfc870").coach_content)
def test_no_content_nodes_available(self): ContentNode.objects.filter(kind=content_kinds.TOPIC).update( available=True) recurse_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") # 0, as although there are three childless topics in the fixture, these cannot exist in real databases # all availability for a channel gets set to False for topics before propagating availability up the tree. self.assertEqual( ContentNode.objects.filter(kind=content_kinds.TOPIC).filter( available=True).count(), 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
def test_one_child_coach_content_parent_no_siblings(self): ContentNode.objects.all().update(available=True, coach_content=False) root_node = ContentNode.objects.get(parent__isnull=True) topic_node = ContentNode.objects.filter( parent=root_node, kind=content_kinds.TOPIC).first() parent_node = ContentNode.objects.create( title="test1", id=uuid.uuid4().hex, content_id=uuid.uuid4().hex, channel_id=root_node.channel_id, parent=topic_node, kind=content_kinds.TOPIC, available=True, coach_content=False, ) ContentNode.objects.create( title="test2", id=uuid.uuid4().hex, content_id=uuid.uuid4().hex, channel_id=root_node.channel_id, parent=parent_node, kind=content_kinds.VIDEO, available=True, coach_content=True, ) ContentNode.objects.create( title="test3", id=uuid.uuid4().hex, content_id=uuid.uuid4().hex, channel_id=root_node.channel_id, parent=parent_node, kind=content_kinds.VIDEO, available=True, coach_content=False, ) recurse_annotation_up_tree( channel_id="6199dde695db4ee4ab392222d5af1e5c") parent_node.refresh_from_db() self.assertFalse(parent_node.coach_content) self.assertEqual(parent_node.num_coach_contents, 1)