def test_set_is_related(self): root = content.ContentMetadata.objects.using( self.the_channel_id).get(title="root") c1 = content.ContentMetadata.objects.using( self.the_channel_id).get(title="c1") self.assertFalse(root in api.get_all_related( channel_id=self.the_channel_id, content=c1)) api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) self.assertTrue(root in api.get_all_related( channel_id=self.the_channel_id, content=c1))
def test_get_all_related(self): """ test the nondirectional characteristic of related relationship """ c1 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c1") c2 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c2") # if c1 is related to c2 expected_output = content.ContentMetadata.objects.using(self.the_channel_id).filter(title__in=["c2"]) actual_output = api.get_all_related(channel_id=self.the_channel_id, content=c1) self.assertEqual(set(expected_output), set(actual_output)) # then c2 should be related to c1 expected_output = content.ContentMetadata.objects.using(self.the_channel_id).filter(title__in=["c1"]) actual_output = api.get_all_related(channel_id=self.the_channel_id, content=c2) self.assertEqual(set(expected_output), set(actual_output))
def test_set_is_related_endpoint(self): root = content.ContentMetadata.objects.using( self.the_channel_id).get(title="root") c1 = content.ContentMetadata.objects.using( self.the_channel_id).get(title="c1") self.assertFalse(root in api.get_all_related( channel_id=self.the_channel_id, content=c1)) self.client.put( self._reverse_channel_url("contentmetadata_set_is_related", { "content_id": c1.content_id, "related": root.content_id })) self.assertTrue(root in api.get_all_related( channel_id=self.the_channel_id, content=c1))
def all_related(self, request, channelmetadata_channel_id, *args, **kwargs): """ endpoint for content api method get_all_related(channel_id=None, content=None, **kwargs) """ context = {'request': request, 'channel_id': channelmetadata_channel_id} data = serializers.ContentMetadataSerializer( api.get_all_related(channel_id=channelmetadata_channel_id, content=self.kwargs['content_id']), context=context, many=True ).data return Response(data)
def test_set_is_related_endpoint(self): root = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root") c1 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c1") self.assertFalse(root in api.get_all_related(channel_id=self.the_channel_id, content=c1)) self.client.put(self._reverse_channel_url("contentmetadata_set_is_related", {"content_id": c1.content_id, "related": root.content_id})) self.assertTrue(root in api.get_all_related(channel_id=self.the_channel_id, content=c1))
def test_set_is_related(self): root = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root") c1 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c1") self.assertFalse(root in api.get_all_related(channel_id=self.the_channel_id, content=c1)) api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) self.assertTrue(root in api.get_all_related(channel_id=self.the_channel_id, content=c1))