def test_create_reference_raises_given_a_reference(self): content = self.repository['content'] with self.assertRaises(TypeError) as e: ReferenceProperty.create_reference( source=content, attribute='references', target=content.references.create(self.repository['target']), xml_reference_name='test') self.assertIn('data loss', str(e.exception))
def test_create_reference_raises_given_a_reference_even_if_suppress_error( self): # Suppressing errors is only forwarded to the XMLReferenceUpdater. # It does not mean that the method itself does not raise errors. content = self.repository['content'] with self.assertRaises(TypeError) as e: ReferenceProperty.create_reference( source=content, attribute='references', target=content.references.create(self.repository['target']), xml_reference_name='test', suppress_errors=True) self.assertIn('data loss', str(e.exception))
def test_create_reference_accepts_ICMSContent(self): from zeit.cms.content.interfaces import IReference content = self.repository['content'] target = self.repository['target'] result = ReferenceProperty.create_reference( source=content, attribute='references', target=target, xml_reference_name='test') self.assertTrue(IReference.providedBy(result)) self.assertEqual(target.uniqueId, result.target.uniqueId)
def setUp(self): super(ReferenceFixture, self).setUp() ExampleContentType.references = ReferenceProperty( '.body.references.reference', 'test') zope.security.protectclass.protectName(ExampleContentType, 'references', 'zope.Public') zope.security.protectclass.protectSetAttribute(ExampleContentType, 'references', 'zope.Public') zope.security.protectclass.protectLikeUnto( ExampleReference, zeit.cms.content.reference.Reference) zope.security.protectclass.protectName(ExampleReference, 'foo', 'zope.Public') zope.security.protectclass.protectSetAttribute(ExampleReference, 'foo', 'zope.Public') self.zca.patch_adapter(zeit.cms.related.related.BasicReference, name='test') self.zca.patch_adapter(ExampleReference, name='test') self.repository['content'] = ExampleContentType() self.repository['target'] = ExampleContentType()
def setUp(self): super(ImageReferenceTest, self).setUp() ExampleContentType.images = ReferenceProperty('.body.image', 'image')