def test_get_all_prerequisites(self): """ test the directional characteristic of prerequisite relationship """ c1 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c1") root = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root") # if root is the prerequisite of c1 expected_output = content.ContentMetadata.objects.using(self.the_channel_id).filter(title__in=["root"]) actual_output = api.get_all_prerequisites(channel_id=self.the_channel_id, content=c1) self.assertEqual(set(expected_output), set(actual_output)) # then c1 should not be the prerequisite of root expected_output = content.ContentMetadata.objects.using(self.the_channel_id).filter(title__in=["c1"]) actual_output = api.get_all_prerequisites(channel_id=self.the_channel_id, content=root) self.assertNotEqual(set(actual_output), set(expected_output))
def test_set_prerequisite(self): root = content.ContentMetadata.objects.using( self.the_channel_id).get(title="root") c2 = content.ContentMetadata.objects.using( self.the_channel_id).get(title="c2") self.assertFalse( api.get_all_prerequisites(channel_id=self.the_channel_id, content=root)) api.set_prerequisite(channel_id=self.the_channel_id, content1=c2, content2=root) self.assertTrue( api.get_all_prerequisites(channel_id=self.the_channel_id, content=root))
def test_set_prerequisite_endpoint(self): root = content.ContentMetadata.objects.using( self.the_channel_id).get(title="root") c2 = content.ContentMetadata.objects.using( self.the_channel_id).get(title="c2") self.assertFalse( api.get_all_prerequisites(channel_id=self.the_channel_id, content=root)) self.client.put( self._reverse_channel_url("contentmetadata_set_prerequisite", { "content_id": c2.content_id, "prerequisite": root.content_id })) self.assertTrue( api.get_all_prerequisites(channel_id=self.the_channel_id, content=root))
def all_prerequisites(self, request, channelmetadata_channel_id, *args, **kwargs): """ endpoint for content api method get_all_prerequisites(channel_id=None, content=None, **kwargs) """ context = {'request': request, 'channel_id': channelmetadata_channel_id} data = serializers.ContentMetadataSerializer( api.get_all_prerequisites(channel_id=channelmetadata_channel_id, content=self.kwargs['content_id']), context=context, many=True ).data return Response(data)
def test_set_prerequisite_endpoint(self): root = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root") c2 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c2") self.assertFalse(api.get_all_prerequisites(channel_id=self.the_channel_id, content=root)) self.client.put(self._reverse_channel_url("contentmetadata_set_prerequisite", {"content_id": c2.content_id, "prerequisite": root.content_id})) self.assertTrue(api.get_all_prerequisites(channel_id=self.the_channel_id, content=root))
def test_set_prerequisite(self): root = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root") c2 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c2") self.assertFalse(api.get_all_prerequisites(channel_id=self.the_channel_id, content=root)) api.set_prerequisite(channel_id=self.the_channel_id, content1=c2, content2=root) self.assertTrue(api.get_all_prerequisites(channel_id=self.the_channel_id, content=root))