Back to index

plone3  3.1.7
Public Member Functions
Archetypes.tests.test_referenceCatalog.ReferenceCatalogTests Class Reference
Inheritance diagram for Archetypes.tests.test_referenceCatalog.ReferenceCatalogTests:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_referenceCatalog.ReferenceCatalogTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def verifyBrains
def test_create
def test_holdingref
def test_cascaderef
def test_delete
def test_custome_metadata

Detailed Description

Definition at line 39 of file test_referenceCatalog.py.


Member Function Documentation

Definition at line 164 of file test_referenceCatalog.py.

00164 
00165     def test_cascaderef(self):
00166         my1stfolder = makeContent(self.folder, portal_type='SimpleFolder', id='my1stfolder')
00167         obj5 = makeContent(my1stfolder, portal_type='Fact', id='obj5')
00168         my2ndfolder = makeContent(self.folder, portal_type='SimpleFolder', id='my2ndfolder')
00169         obj6 = makeContent(my2ndfolder, portal_type='Fact', id='obj6')
00170         obj5.addReference(obj6, relationship="uses", referenceClass=CascadeReference)
00171         my1stfolder.manage_delObjects(['obj5'])
00172         items = my1stfolder.contentIds()
00173         self.failIf('obj5' in items)
00174         items = my2ndfolder.contentIds()
00175         self.failIf('obj6' in items)

Here is the call graph for this function:

Definition at line 58 of file test_referenceCatalog.py.

00058 
00059     def test_create(self):
00060         rc = getattr(self.portal, config.REFERENCE_CATALOG)
00061         uc = getattr(self.portal, config.UID_CATALOG)
00062 
00063         self.failUnless(rc is not None)
00064 
00065         id1 = "firstObject"
00066         obj = makeContent(self.folder, portal_type='Fact', id=id1)
00067         self.failUnless(obj.UID())
00068 
00069         brains = uc(UID=obj.UID())
00070         self.failUnless(len(brains) == 1)
00071 
00072         id2 = "secondObject"
00073         obj2 = makeContent(self.folder, portal_type='Fact', id=id2)
00074 
00075         self.verifyBrains()
00076         obj.addReference(obj2, 'testRelationship', foo="bar")
00077         self.verifyBrains()
00078         uid1 = obj.UID()
00079         uid2 = obj2.UID()
00080 
00081         brains = rc()
00082         ref = brains[0].getObject()
00083         self.failUnless(ref.sourceUID == uid1)
00084         self.failUnless(ref.targetUID == uid2)
00085 
00086         #Check the metadata
00087         self.failUnless(ref.foo == "bar")
00088 
00089         unqualified = obj.getRefs()
00090         byRel = obj.getRefs('testRelationship')
00091         assert unqualified[0] == byRel[0] == ref.getTargetObject()
00092 
00093         back = obj2.getBRefs()
00094         self.failUnless(back[0] == obj)
00095 
00096         self.failUnless(obj.reference_url().endswith(uid1))
00097 
00098         # Make sure all objects have _p_oids and _p_jars
00099         transaction.savepoint(optimistic=True)
00100 
00101         #Rename can't invalidate UID or references
00102         self.verifyBrains()
00103         obj.setId('new1')
00104         self.verifyBrains()
00105 
00106         self.failUnless(obj.getId() == 'new1')
00107         self.failUnless(obj.UID() == uid1)
00108 
00109         b = obj.getRefs()
00110         self.failUnless(b[0].UID() == uid2)
00111 
00112         obj2.setId('new2')
00113         self.failUnless(obj2.getId() == 'new2')
00114         self.failUnless(obj2.UID() == uid2)
00115 
00116         b = obj2.getBRefs()
00117 
00118         self.failUnless(b[0].UID() == uid1)
00119 
00120         #Add another reference with a different relationship (and the
00121         #other direction)
00122 
00123         obj2.addReference(obj, 'betaRelationship', this="that")
00124         b = obj2.getRefs('betaRelationship')
00125         self.failUnless(b[0].UID() == uid1)
00126         b = obj.getBRefs('betaRelationship')
00127         refs = rc.getBackReferences(obj, 'betaRelationship')
00128         # objs back ref should be obj2
00129         self.failUnless(refs[0].sourceUID == b[0].UID() == uid2)
00130         self.verifyBrains()
00131 

Here is the call graph for this function:

Definition at line 213 of file test_referenceCatalog.py.

00213 
00214     def test_custome_metadata(self):
00215         # create two objects
00216         # make ref from one object to the other
00217         # place a custom attribute on the reference
00218         # update schemas
00219         # test if attribute still exists on the reference object
00220         rc = self.portal.reference_catalog
00221 
00222         obj1 = makeContent(self.folder, portal_type='Refnode',
00223                            id='one')
00224         uid = obj1.UID()
00225         obj2 = makeContent(self.folder, portal_type='Refnode', id='two')
00226         uid2 = obj2.UID()
00227         # create reference
00228         obj1.update(link=[obj2.UID()])
00229         ref = rc.getReferences(obj1)[0]
00230         ref.attribute1 = "some_value"
00231         ruid = ref.UID()
00232         self.failUnless(ref.attribute1=='some_value')
00233 
00234 
00235         transaction.savepoint(optimistic=True)
00236         # update schema
00237         self.app.REQUEST.form['Archetypes.Refnode']=1
00238         self.app.REQUEST.form['update_all']=1
00239         self.portal.archetype_tool.manage_updateSchema(REQUEST=self.app.REQUEST)
00240         del obj1
00241 
00242         # get the reference for obj1
00243         obj1 = rc.lookupObject(uid)
00244         refs = rc.getReferences(obj1, relationship=obj1.Schema()['link'].relationship)
00245         ref = refs[0]
00246         ruid2 = ref.UID()
00247         assert ruid == ruid2, """ref uid got reassigned"""
00248         #check for the attribute
00249         self.failUnless(hasattr(ref, 'attribute1'), 'Custom attribute on reference object is lost during schema update')
00250         self.assertEqual(ref.attribute1, 'some_value')
00251 

Here is the call graph for this function:

Definition at line 176 of file test_referenceCatalog.py.

00176 
00177     def test_delete(self):
00178         rc = getattr(self.portal, config.REFERENCE_CATALOG)
00179         uc = getattr(self.portal, config.UID_CATALOG)
00180 
00181         obj1 = makeContent(self.folder, portal_type='Fact', id='obj1')
00182         obj2 = makeContent(self.folder, portal_type='Fact', id='obj2')
00183 
00184         uid1 = obj1.UID()
00185         uid2 = obj2.UID()
00186 
00187 
00188         #Make a reference
00189         obj1.addReference(obj2, relationship="example")
00190 
00191         #and clean it up
00192         self.folder._delObject(obj1.id)
00193 
00194         # Assert that the reference is gone, that the UID is gone and
00195         # that the content is gone
00196         self.failUnless(obj2.getBRefs() == [])
00197         self.failIf(obj1.id in self.folder.contentIds())
00198 
00199         self.failIf(uid1 in uc.uniqueValuesFor('UID'))
00200         self.failUnless(uid2 in uc.uniqueValuesFor('UID'))
00201 
00202         sourceRefs = rc(sourceUID = uid1)
00203         targetRefs = rc(targetUID = uid1)
00204 
00205         assert len(sourceRefs) == 0
00206         assert len(targetRefs) == 0
00207 
00208         #also make sure there is nothing in the reference Catalog
00209         assert len(rc.getReferences(uid1)) == 0
00210         assert len(rc.getBackReferences(uid1)) == 0
00211         assert len(rc.getReferences(uid2)) == 0
00212         assert len(rc.getBackReferences(uid2)) == 0

Here is the call graph for this function:

Definition at line 132 of file test_referenceCatalog.py.

00132 
00133     def test_holdingref(self):
00134         rc = getattr(self.portal, config.REFERENCE_CATALOG)
00135         uc = getattr(self.portal, config.UID_CATALOG)
00136 
00137         obj1 = makeContent(self.folder, portal_type='Fact', id='obj1')
00138         obj2 = makeContent(self.folder, portal_type='Fact', id='obj2')
00139 
00140         obj1.addReference(obj2, relationship="uses", referenceClass=HoldingReference)
00141 
00142         self.failUnless(obj2 in obj1.getRefs('uses'))
00143 
00144         # a holding reference says obj2 can't be deleted cause its held
00145         try:
00146             self.folder._delObject(obj2.id)
00147         except BeforeDeleteException, E:
00148             pass
00149         else:
00150             raise AssertionError("holding reference didn't hold")
00151 
00152         #and just check to make sure its still there
00153         self.failUnless(hasattr(self.folder, obj2.id))
00154 
00155         obj3 = makeContent(self.folder, portal_type='Fact', id='obj3')
00156         obj4 = makeContent(self.folder, portal_type='Fact', id='obj4')
00157 
00158         obj3.addReference(obj4, relationship="uses", referenceClass=CascadeReference)
00159 
00160         self.folder.manage_delObjects(obj3.id)
00161         items = self.folder.contentIds()
00162         self.failIf(obj3.id in items)
00163         self.failIf(obj4.id in items)

Here is the call graph for this function:

Definition at line 41 of file test_referenceCatalog.py.

00041 
00042     def verifyBrains(self):
00043         uc = getattr(self.portal, config.UID_CATALOG)
00044         rc = getattr(self.portal, config.REFERENCE_CATALOG)
00045 
00046         #Verify all UIDs resolve
00047         brains = uc()
00048         objects = [b.getObject() for b in brains]
00049         self.failIf(None in objects, """bad uid resolution""")
00050         for b in brains:
00051             if b.getPath().startswith('/'):
00052                 print "Bad Brain", b, b.getObject()
00053 
00054         #Verify all references resolve
00055         brains = rc()
00056         objects = [b.getObject() for b in brains]
00057         self.failIf(None in objects, """bad ref catalog resolution""")

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: