def test_set_is_related_immediate_cyclic(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") api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) # test for immediate cyclic exception with self.assertRaises(IntegrityError): api.set_is_related(channel_id=self.the_channel_id, content1=root, content2=c1)
def test_set_is_related_uniqueness(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") api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) # test for uniqueness exception with self.assertRaises(IntegrityError): api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root)
def test_set_is_related_self_reference(self): c1 = content.ContentMetadata.objects.using( self.the_channel_id).get(title="c1") # test for self reference exception with self.assertRaises(IntegrityError): api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=c1)
def test_set_is_related_immediate_cyclic(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") api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) # test for silently canceling save on immediate cyclic related_relationship try: api.set_is_related(channel_id=self.the_channel_id, content1=root, content2=c1) except: self.assertTrue(False)
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_can_get_content_with_id(self): # pass content_id root_id = content.ContentMetadata.objects.using(self.the_channel_id).get(title="root").content_id expected_output = content.ContentMetadata.objects.using(self.the_channel_id).filter(title__in=["c1", "c2"]) actual_output = api.immediate_children(channel_id=self.the_channel_id, content=str(root_id)) self.assertEqual(set(expected_output), set(actual_output)) # pass content_ids api.set_is_related(channel_id=self.the_channel_id, content1=str(expected_output[0].content_id), content2=str(root_id)) # pass invalid type with self.assertRaises(TypeError): api.immediate_children(channel_id=self.the_channel_id, content=432)
def test_set_is_related_immediate_cyclic(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") api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=root) # test for silently canceling save on immediate cyclic related_relationship try: api.set_is_related(channel_id=self.the_channel_id, content1=root, content2=c1) except: self.assertTrue(False)
def test_set_is_related_self_reference(self): c1 = content.ContentMetadata.objects.using(self.the_channel_id).get(title="c1") # test for self reference exception with self.assertRaises(IntegrityError): api.set_is_related(channel_id=self.the_channel_id, content1=c1, content2=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))
def set_is_related(self, request, channelmetadata_channel_id, *args, **kwargs): """ endpoint for content api method set_is_related(channel_id=None, content1=None, content2=None, **kwargs) """ return Response(api.set_is_related(channel_id=channelmetadata_channel_id, content1=self.kwargs['content_id'], content2=self.kwargs['related']))