Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes
Archetypes.tests.test_referenceable.BaseReferenceableTests Class Reference
Inheritance diagram for Archetypes.tests.test_referenceable.BaseReferenceableTests:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_referenceable.BaseReferenceableTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def verifyBrains
def test_hasUID
def test_renamedontchangeUID
def test_renameKeepsReferences
def test_renamecontainerKeepsReferences
def test_renamecontainerKeepsReferences2
def test_UIDclash
def test_setUID_keeps_relationships
def test_relationships
def test_back_relationships
def test_singleReference
def test_multipleReferences
def test_UIDunderContainment
def test_hasRelationship
def test_graph
def test_folderishDeleteCleanup
def test_reindexUIDCatalog
def test_referenceReference
def test_referenceFieldVocab
def test_noReferenceAfterDelete
def test_noBackReferenceAfterDelete
def test_copyKeepsReferences
def test_copyPasteSupport
def test_cutPasteSupport
def test_folderCopyPasteSupport
def test_folderCutPasteSupport

Static Public Attributes

 FOLDER_TYPE = None

Detailed Description

Definition at line 36 of file test_referenceable.py.


Member Function Documentation

Definition at line 337 of file test_referenceable.py.

00337 
00338     def test_back_relationships(self):
00339 
00340         account_id = 'caixa'
00341         invoice_id = 'fatura'
00342         payment_id = 'entrada'
00343         future_payment_id = 'cta_receber'
00344         payment2_id = 'quitacao'
00345 
00346         account = makeContent( self.folder, portal_type='DDocument',
00347                                title='Account', id=account_id)
00348         invoice = makeContent( self.folder, portal_type='DDocument',
00349                                title='Invoice', id=invoice_id)
00350         payment = makeContent( self.folder, portal_type='DDocument',
00351                                title='Payment', id=payment_id)
00352         future_payment = makeContent( self.folder, portal_type='DDocument',
00353                                       title='Future Payment',
00354                                       id=future_payment_id)
00355         payment2 = makeContent( self.folder, portal_type='DDocument',
00356                                 title='Payment 2', id=payment2_id)
00357 
00358         invoice.addReference(payment, "Owns")
00359         invoice.addReference(future_payment, "Owns")
00360         future_payment.addReference(payment2, "Owns")
00361         payment.addReference(account, "From")
00362         payment2.addReference(account, "From")
00363 
00364         brels = account.getBRelationships()
00365         self.assertEquals(brels, ['From'])
00366         brefs = account.getBRefs('From')
00367         self.assertEquals(brefs, [payment, payment2])
00368 
00369         brels = payment.getBRelationships()
00370         self.assertEquals(brels, ['Owns'])
00371         brefs = payment.getBRefs('Owns')
00372         self.assertEquals(brefs, [invoice])
00373 
00374         brels = payment2.getBRelationships()
00375         self.assertEquals(brels, ['Owns'])
00376         brefs = payment2.getBRefs('Owns')
00377         self.assertEquals(brefs, [future_payment])
00378 
00379         invoice.deleteReference(payment, "Owns")
00380 
00381         self.assertEquals(invoice.getRefs(), [future_payment])
00382         self.assertEquals(payment.getBRefs(), [])

Here is the call graph for this function:

Definition at line 589 of file test_referenceable.py.

00589 
00590     def test_copyKeepsReferences(self):
00591         # when copied a pasted object should NOT lose all references
00592         # if keepReferencesOnCopy is set
00593         # added by DaftDog (for plone tracker issue  #5180)
00594         org_folder = makeContent(self.folder,
00595                                  portal_type=self.FOLDER_TYPE,
00596                                  title='Origin folder',
00597                                  id='org_folder')
00598         dst_folder = makeContent(self.folder,
00599                                  portal_type=self.FOLDER_TYPE,
00600                                  title='Destination folder',
00601                                  id='dst_folder')
00602         a = makeContent(org_folder, portal_type='DDocument', id='a')
00603         b = makeContent(org_folder, portal_type='DDocument', id='b')
00604         related_field = a.getField('related')
00605         related_field.set(a, b.UID())
00606 
00607         self.failUnlessEqual(b.getBRefs(), [a])
00608         self.failUnlessEqual(a.getRefs(), [b])
00609 
00610         cb = org_folder.manage_copyObjects(ids=['a'])
00611         dst_folder.manage_pasteObjects(cb_copy_data=cb)
00612         copy_a = getattr(dst_folder, 'a')
00613 
00614         # The copy should get a new UID
00615         a_uid = a.UID()
00616         ca_uid = copy_a.UID()
00617         self.failIf(a_uid == ca_uid, (a_uid, ca_uid))
00618 
00619         # The copy should have the same references
00620         self.failUnlessEqual(a.getRefs(), copy_a.getRefs())
00621         self.failUnless(copy_a in b.getBRefs())
00622 
00623 
00624         # Original object should keep references
00625         self.failUnlessEqual(a.getRefs(), [b])
00626         # Original non-copied object should point to both the original and the copied object
00627         self.failUnlessEqual(b.getBRefs(), [a, copy_a])

Here is the call graph for this function:

Definition at line 628 of file test_referenceable.py.

00628 
00629     def test_copyPasteSupport(self):
00630         # copy/paste behaviour test
00631         # in another folder, pasted object should lose all references
00632         # added by GL (for bug #985393)
00633         org_folder = makeContent(self.folder,
00634                                  portal_type=self.FOLDER_TYPE,
00635                                  title='Origin folder',
00636                                  id='org_folder')
00637         dst_folder = makeContent(self.folder,
00638                                  portal_type=self.FOLDER_TYPE,
00639                                  title='Destination folder',
00640                                  id='dst_folder')
00641         a = makeContent(org_folder, portal_type='DDocument', id='a')
00642         b = makeContent(org_folder, portal_type='DDocument', id='b')
00643         a.addReference(b)
00644 
00645         self.failUnlessEqual(b.getBRefs(), [a])
00646         self.failUnlessEqual(a.getRefs(), [b])
00647 
00648         cb = org_folder.manage_copyObjects(ids=['a'])
00649         dst_folder.manage_pasteObjects(cb_copy_data=cb)
00650         copy_a = getattr(dst_folder, 'a')
00651 
00652         # The copy should get a new UID
00653         a_uid = a.UID()
00654         ca_uid = copy_a.UID()
00655         self.failIf(a_uid == ca_uid, (a_uid, ca_uid))
00656 
00657         # The copy shouldn't have references
00658         self.failUnlessEqual(copy_a.getRefs(), [])
00659         self.failIf(copy_a in b.getBRefs())
00660 
00661 
00662         # Original object should keep references
00663         self.failUnlessEqual(a.getRefs(), [b])
00664         self.failUnlessEqual(b.getBRefs(), [a])

Here is the call graph for this function:

Definition at line 665 of file test_referenceable.py.

00665 
00666     def test_cutPasteSupport(self):
00667         # cut/paste behaviour test
00668         # in another folder, pasted object should keep the references
00669         # added by GL (for bug #985393)
00670         org_folder = makeContent(self.folder,
00671                                  portal_type=self.FOLDER_TYPE,
00672                                  title='Origin folder',
00673                                  id='org_folder')
00674         dst_folder = makeContent(self.folder,
00675                                  portal_type=self.FOLDER_TYPE,
00676                                  title='Destination folder',
00677                                  id='dst_folder')
00678         a = makeContent(org_folder, portal_type='DDocument', id='a')
00679         b = makeContent(org_folder, portal_type='DDocument', id='b')
00680         a.addReference(b)
00681         transaction.savepoint(optimistic=True)
00682         cb = org_folder.manage_cutObjects(ids=['a'])
00683         dst_folder.manage_pasteObjects(cb_copy_data=cb)
00684         copy_a = getattr(dst_folder, 'a')
00685 
00686         self.failUnlessEqual(copy_a.getRefs(), [b])
00687         self.failUnlessEqual(b.getBRefs(), [copy_a])

Here is the call graph for this function:

Definition at line 688 of file test_referenceable.py.

00688 
00689     def test_folderCopyPasteSupport(self):
00690         # copy/paste behaviour test
00691         # sub-objects of copy/pasted folders should lose all references,
00692         # and duplicate refs should not be created on the original object.
00693         org_folder = makeContent(self.folder,
00694                                  portal_type=self.FOLDER_TYPE,
00695                                  title='Origin folder',
00696                                  id='org_folder')
00697         dst_folder = makeContent(self.folder,
00698                                  portal_type=self.FOLDER_TYPE,
00699                                  title='Destination folder',
00700                                  id='dst_folder')
00701         my_folder = makeContent(org_folder, portal_type=self.FOLDER_TYPE,
00702                                                              id='my_folder')
00703         a = makeContent(my_folder, portal_type='DDocument', id='a')
00704         b = makeContent(my_folder, portal_type='DDocument', id='b')
00705         a.addReference(b)
00706 
00707         self.failUnlessEqual(b.getBRefs(), [a])
00708         self.failUnlessEqual(a.getRefs(), [b])
00709 
00710         cb = org_folder.manage_copyObjects(ids=['my_folder'])
00711         dst_folder.manage_pasteObjects(cb_copy_data=cb)
00712         copy_folder = getattr(dst_folder, 'my_folder')
00713         copy_a = getattr(copy_folder, 'a')
00714 
00715         # The copy should get a new UID
00716         a_uid = a.UID()
00717         ca_uid = copy_a.UID()
00718         self.failIf(a_uid == ca_uid, (a_uid, ca_uid))
00719 
00720         # The copy shouldn't have references
00721         self.failUnlessEqual(copy_a.getRefs(), [])
00722         self.failIf(copy_a in b.getBRefs())
00723 
00724         #The copy's uid should have changed
00725         self.failIf(ca_uid == a_uid)
00726 
00727         # Original object should keep references
00728         self.failUnlessEqual(a.getRefs(), [b])
00729         self.failUnlessEqual(b.getBRefs(), [a])

Here is the call graph for this function:

Definition at line 730 of file test_referenceable.py.

00730 
00731     def test_folderCutPasteSupport(self):
00732         # copy/paste behaviour test
00733         # sub-objects of copy/pasted folders should lose all references,
00734         # and duplicate refs should not be created on the original object.
00735         org_folder = makeContent(self.folder,
00736                                  portal_type=self.FOLDER_TYPE,
00737                                  title='Origin folder',
00738                                  id='org_folder')
00739         dst_folder = makeContent(self.folder,
00740                                  portal_type=self.FOLDER_TYPE,
00741                                  title='Destination folder',
00742                                  id='dst_folder')
00743         my_folder = makeContent(org_folder, portal_type=self.FOLDER_TYPE,
00744                                                              id='my_folder')
00745         a = makeContent(my_folder, portal_type='DDocument', id='a')
00746         b = makeContent(my_folder, portal_type='DDocument', id='b')
00747         a.addReference(b)
00748 
00749         self.failUnlessEqual(b.getBRefs(), [a])
00750         self.failUnlessEqual(a.getRefs(), [b])
00751         a_uid = a.UID()
00752 
00753         transaction.savepoint(optimistic=True)
00754         cb = org_folder.manage_cutObjects(ids=['my_folder'])
00755         dst_folder.manage_pasteObjects(cb_copy_data=cb)
00756         copy_folder = getattr(dst_folder, 'my_folder')
00757         copy_a = getattr(copy_folder, 'a')
00758         copy_b = getattr(copy_folder, 'b')
00759         ca_uid = copy_a.UID()
00760 
00761         # The copy shouldn't have references
00762         self.failUnlessEqual(copy_a.getRefs(), [copy_b])
00763         self.failUnlessEqual(copy_b.getBRefs(), [copy_a])
00764 
00765         #The copy's uid should have changed
00766         self.failUnless(ca_uid == a_uid, (a_uid, ca_uid))
00767 

Here is the call graph for this function:

Definition at line 467 of file test_referenceable.py.

00467 
00468     def test_folderishDeleteCleanup(self):
00469         self.folder.invokeFactory(type_name="Folder", id="reftest")
00470         folder = getattr(self.folder, "reftest")
00471 
00472         a = makeContent(folder, portal_type='DDocument',title='Foo', id='a')
00473         b = makeContent(folder, portal_type='DDocument',title='Bar', id='b')
00474         a.addReference(b, "KnowsAbout")
00475 
00476         # Again, lets assert the sanity of the UID and Ref Catalogs
00477         uc = self.portal.uid_catalog
00478         rc = self.portal.reference_catalog
00479 
00480         uids = uc.uniqueValuesFor('UID')
00481         self.failUnless(a.UID() in uids, (a.UID(), uids))
00482         self.failUnless(b.UID() in uids, (b.UID(), uids))
00483 
00484         refs = rc()
00485         self.assertEquals(len(refs), 1)
00486         ref = refs[0].getObject()
00487         self.assertEquals(ref.targetUID, b.UID())
00488         self.assertEquals(ref.sourceUID, a.UID())
00489 
00490         # Now Kill the folder and make sure it all went away
00491         self.folder._delObject("reftest")
00492         self.verifyBrains()
00493 
00494         uids = uc.uniqueValuesFor('UID')
00495         self.assertEquals(len(rc()), 0)

Here is the call graph for this function:

Definition at line 449 of file test_referenceable.py.

00449 
00450     def test_graph(self):
00451         if not HAS_GRAPHVIZ:
00452             return
00453 
00454         # This just asserts that nothing went wrong
00455         a = makeContent(self.folder, portal_type='DDocument',title='Foo', id='a')
00456         b = makeContent( self.folder, portal_type='DDocument',title='Foo', id='b')
00457         c = makeContent( self.folder, portal_type='DDocument',title='Foo', id='c')
00458 
00459         # Two made up kinda refs
00460         a.addReference(b, "KnowsAbout")
00461         c.addReference(a, "Owns")
00462         refmap = a.getReferenceMap()
00463         self.failUnless(refmap, refmap)
00464         png = a.getReferencePng()
00465         self.failUnless(png, png)
00466 

Here is the call graph for this function:

Definition at line 433 of file test_referenceable.py.

00433 
00434     def test_hasRelationship(self):
00435         a = makeContent(self.folder, portal_type='DDocument',title='Foo', id='a')
00436         b = makeContent(self.folder, portal_type='DDocument',title='Foo', id='b')
00437         c = makeContent(self.folder, portal_type='DDocument',title='Foo', id='c')
00438 
00439         # Two made up kinda refs
00440         a.addReference(b, "KnowsAbout")
00441 
00442         self.assertEquals(a.hasRelationshipTo(b), 1)
00443         self.assertEquals(a.hasRelationshipTo(b, "KnowsAbout"), 1)
00444         self.assertEquals(a.hasRelationshipTo(b, "Foo"), 0)
00445         self.assertEquals(a.hasRelationshipTo(c), 0)
00446         self.assertEquals(a.hasRelationshipTo(c, "KnowsAbout"), 0)
00447 
00448         # XXX HasRelationshipFrom  || ( 1 for ref 2 for bref?)

Here is the call graph for this function:

Definition at line 55 of file test_referenceable.py.

00055 
00056     def test_hasUID( self ):
00057         doc = makeContent( self.folder
00058                            , portal_type='DDocument'
00059                            , title='Foo' )
00060 
00061         self.failUnless(hasattr(aq_base(doc), UUID_ATTR))
00062         self.failUnless(getattr(aq_base(doc), UUID_ATTR, None))
00063 

Here is the call graph for this function:

Definition at line 399 of file test_referenceable.py.

00399 
00400     def test_multipleReferences(self):
00401         # If you provide updateReferences=False to addReference, it
00402         # will add, not replace the reference
00403         a = makeContent( self.folder, portal_type='DDocument',title='Foo', id='a')
00404         b = makeContent( self.folder, portal_type='DDocument',title='Foo', id='b')
00405 
00406         #Add the same ref twice
00407         a.addReference(b, "KnowsAbout", updateReferences=False)
00408         a.addReference(b, "KnowsAbout", updateReferences=False)
00409 
00410         self.assertEquals(len(a.getRefs('KnowsAbout')),  2)
00411 
00412         #In this case its a different relationship
00413         a.addReference(b, 'Flogs')
00414         self.assertEquals(len(a.getRefs('KnowsAbout')), 2)
00415         self.assertEquals(len(a.getRefs()), 3)
00416         

Here is the call graph for this function:

Definition at line 579 of file test_referenceable.py.

00579 
00580     def test_noBackReferenceAfterDelete(self):
00581         # Deleting source should delete back reference
00582         # added by GL
00583         a = makeContent(self.folder, portal_type='DDocument', id='a')
00584         b = makeContent(self.folder, portal_type='DDocument', id='b')
00585         a.addReference(b)
00586         self.folder._delObject('a')
00587 
00588         self.failUnlessEqual(b.getBRefs(), [])

Here is the call graph for this function:

Definition at line 569 of file test_referenceable.py.

00569 
00570     def test_noReferenceAfterDelete(self):
00571         # Deleting target should delete reference
00572         # added by GL
00573         a = makeContent(self.folder, portal_type='DDocument', id='a')
00574         b = makeContent(self.folder, portal_type='DDocument', id='b')
00575         a.addReference(b)
00576         self.folder._delObject('b')
00577 
00578         self.failUnlessEqual(a.getRefs(), [])

Here is the call graph for this function:

Definition at line 521 of file test_referenceable.py.

00521 
00522     def test_referenceFieldVocab(self):
00523         dummy = makeContent(self.folder, portal_type="Refnode", id="dummy")
00524         test123 = makeContent(self.folder, portal_type="Refnode",
00525                               id="Test123")
00526         test124 = makeContent(self.folder, portal_type="Refnode",
00527                               id="Test124")
00528         test125 = makeContent(self.folder, portal_type="Refnode",
00529                               id="Test125")
00530 
00531         field = dummy.Schema()['adds']
00532 
00533         expected = DisplayList([
00534             (test123.UID(), test123.getId()),
00535             (test124.UID(), test124.getId()),
00536             (test125.UID(), test125.getId()),
00537             (dummy.UID(), dummy.getId()),
00538             ])
00539 
00540         got = field.Vocabulary(dummy)
00541         self.assertEquals(got, expected)
00542 
00543         # We should have the option of nothing
00544         field = field.copy()
00545         field.required = 0
00546         field.multiValued = 0
00547 
00548         expected = DisplayList([
00549             (test123.UID(), test123.getId()),
00550             (test124.UID(), test124.getId()),
00551             (test125.UID(), test125.getId()),
00552             (dummy.UID(), dummy.getId()),
00553             ('', u'label_no_reference'),
00554             ])
00555         self.assertEquals(field.Vocabulary(dummy), expected)
00556 
00557         field = field.copy()
00558         field.vocabulary_display_path_bound = 1
00559         expected = DisplayList([
00560             (test123.UID(), test123.getId()),
00561             (test124.UID(), test124.getId()),
00562             (test125.UID(), test125.getId()),
00563             (dummy.UID(), dummy.getId()),
00564             ('', u'label_no_reference'),
00565             ])
00566         self.failIfEqual(field.Vocabulary(dummy), expected)
00567         field.vocabulary_display_path_bound = -1
00568         self.assertEquals(field.Vocabulary(dummy), expected)

Here is the call graph for this function:

Definition at line 506 of file test_referenceable.py.

00506 
00507     def test_referenceReference(self):
00508         # Reference a reference object for fun (no, its like RDFs
00509         # metamodel)
00510         rc = self.portal.reference_catalog
00511 
00512         a = makeContent( self.folder, portal_type='DDocument',title='Foo', id='a')
00513         b = makeContent( self.folder, portal_type='DDocument',title='Foo', id='b')
00514         c = makeContent( self.folder, portal_type='DDocument',title='Foo', id='c')
00515         a.addReference(b)
00516 
00517         ref = a._getReferenceAnnotations().objectValues()[0]
00518         c.addReference(ref)
00519         ref.addReference(c)
00520         self.verifyBrains()

Here is the call graph for this function:

Definition at line 496 of file test_referenceable.py.

00496 
00497     def test_reindexUIDCatalog(self):
00498         catalog = self.portal.uid_catalog
00499 
00500         doc = makeContent(self.folder,
00501                           portal_type='DDocument',
00502                           id='demodoc')
00503         doc.update(title="sometitle")
00504         brain = catalog(UID=doc.UID())[0]
00505         self.assertEquals(brain.Title, doc.Title())

Here is the call graph for this function:

Definition at line 295 of file test_referenceable.py.

00295 
00296     def test_relationships(self):
00297 
00298         obj_id   = 'demodoc'
00299         known_id = 'known_doc'
00300         owned_id = 'owned_doc'
00301         other_id = 'other_doc'
00302 
00303         a = makeContent( self.folder, portal_type='DDocument',
00304                          title='Foo', id=obj_id)
00305         b = makeContent( self.folder, portal_type='DDocument',
00306                          title='Foo', id=known_id)
00307         c = makeContent( self.folder, portal_type='DDocument',
00308                          title='Foo', id=owned_id)
00309 
00310         #Two made up kinda refs
00311         a.addReference(b, "KnowsAbout")
00312         a.addReference(c, "Owns")
00313 
00314         refs = a.getRefs()
00315         self.failUnless(b in refs, (b, refs))
00316         self.failUnless(c in refs, (c, refs))
00317         self.assertEquals(a.getRefs('Owns'), [c])
00318         self.assertEquals(c.getBRefs('Owns'), [a])
00319         rels = a.getRelationships()
00320         self.failUnless("KnowsAbout" in rels, ("KnowsAbout", rels))
00321         self.failUnless("Owns" in rels, ("Owns", rels))
00322 
00323         a.deleteReference(c, "Owns")
00324         self.assertEquals(a.getRefs(), [b])
00325         self.assertEquals(c.getBRefs(), [])
00326 
00327         #test querying references using the targetObject parameter
00328         d = makeContent( self.folder, portal_type='DDocument',
00329                          title='Foo', id=other_id)
00330 
00331         a.addReference(d,'Owns')
00332         a.addReference(d,'KnowsAbout')
00333 
00334         self.assertEqual(len(a.getReferenceImpl()),3)
00335         #get only refs to d
00336         self.assertEqual(len(a.getReferenceImpl(targetObject=d)),2)

Here is the call graph for this function:

Definition at line 122 of file test_referenceable.py.

00122 
00123     def test_renamecontainerKeepsReferences( self ):
00124         # test for #956677: renaming the container causes contained objects
00125         #                   to lose their refs
00126         container = makeContent(self.folder,
00127                                 portal_type=self.FOLDER_TYPE,
00128                                 title='Spam',
00129                                 id='container')
00130         obj1 = makeContent(self.folder.container,
00131                            portal_type='SimpleType',
00132                            title='Eggs',
00133                            id='obj1')
00134         obj2 = makeContent(self.folder,
00135                            portal_type='SimpleType',
00136                            title='Foo',
00137                            id='obj2')
00138 
00139         obj1.addReference(obj2)
00140 
00141         a,b = self.verifyBrains()
00142         transaction.savepoint(optimistic=True)
00143 
00144         self.assertEquals(obj2.getBRefs(), [obj1])
00145         self.assertEquals(obj1.getRefs(), [obj2])
00146 
00147         self.folder.manage_renameObject(id='container',
00148                                         new_id='cont4iner')
00149         c, d = self.verifyBrains()
00150 
00151         obj1 = self.folder.cont4iner.obj1
00152         obj2 = self.folder.cont4iner.obj2
00153 
00154         self.assertEquals(obj2.getBRefs(), [obj1])
00155         self.assertEquals(obj1.getRefs(), [obj2])

Here is the call graph for this function:

Definition at line 156 of file test_referenceable.py.

00156 
00157     def test_renamecontainerKeepsReferences2( self ):
00158         # test for [ 1013363 ] References break on folder rename
00159         folderA = makeContent(self.folder,
00160                                 portal_type=self.FOLDER_TYPE,
00161                                 title='Spam',
00162                                 id='folderA')
00163         objA = makeContent(self.folder.folderA,
00164                            portal_type='SimpleType',
00165                            title='Eggs',
00166                            id='objA')
00167 
00168         folderB = makeContent(self.folder,
00169                                 portal_type=self.FOLDER_TYPE,
00170                                 title='Spam',
00171                                 id='folderB')
00172         objB = makeContent(self.folder.folderB,
00173                            portal_type='SimpleType',
00174                            title='Eggs',
00175                            id='objB')
00176 
00177         objA.addReference(objB)
00178 
00179         a, b = self.verifyBrains()
00180         transaction.savepoint(optimistic=True)
00181 
00182         self.assertEquals(objB.getBRefs(), [objA])
00183         self.assertEquals(objA.getRefs(), [objB])
00184 
00185         # now rename folder B and see if objA still points to objB
00186         self.folder.manage_renameObject(id='folderB',
00187                                         new_id='folderC')
00188         c, d = self.verifyBrains()
00189 
00190         objB = self.folder.folderC.objB
00191 
00192         # check references
00193         self.assertEquals(objB.getBRefs(), [objA])
00194         self.assertEquals(objA.getRefs(), [objB])

Here is the call graph for this function:

Definition at line 64 of file test_referenceable.py.

00064 
00065     def test_renamedontchangeUID( self ):
00066         catalog = self.portal.uid_catalog
00067 
00068         obj_id = 'demodoc'
00069         new_id = 'new_demodoc'
00070         doc = makeContent(self.folder
00071                           , portal_type='DDocument'
00072                           , title='Foo'
00073                           , id=obj_id)
00074 
00075 
00076         UID = doc.UID()
00077         # This test made an assumption about other UIDs in the system
00078         # that are wrong with things like ATCT
00079         self.failUnless(UID in catalog.uniqueValuesFor('UID'))
00080         # ensure object has a _p_jar
00081         transaction.savepoint(optimistic=True)
00082         self.folder.manage_renameObject(id=obj_id, new_id=new_id)
00083         doc = getattr(self.folder, new_id)
00084         self.failUnless(UID in catalog.uniqueValuesFor('UID'))
00085         self.assertEquals(doc.UID(), UID)
00086 

Here is the call graph for this function:

Definition at line 87 of file test_referenceable.py.

00087 
00088     def test_renameKeepsReferences(self):
00089         container = makeContent(self.folder,
00090                                 portal_type=self.FOLDER_TYPE,
00091                                 title='Spam',
00092                                 id='container')
00093 
00094         obj1 = makeContent(self.folder.container,
00095                            portal_type='SimpleType',
00096                            title='Eggs',
00097                            id='obj1')
00098         obj2 = makeContent(self.folder.container,
00099                            portal_type='SimpleType',
00100                            title='Foo',
00101                            id='obj2')
00102 
00103         obj1.addReference(obj2)
00104 
00105         self.verifyBrains()
00106         transaction.savepoint(optimistic=True)
00107         obj1.setId('foo')
00108         transaction.savepoint(optimistic=True)
00109 
00110         self.assertEquals(obj2.getBRefs(), [obj1])
00111         self.assertEquals(obj1.getRefs(), [obj2])
00112 
00113         self.verifyBrains()
00114         transaction.savepoint(optimistic=True)
00115         obj2.setId('bar')
00116         transaction.savepoint(optimistic=True)
00117 
00118         self.assertEquals(obj2.getBRefs(), [obj1])
00119         self.assertEquals(obj1.getRefs(), [obj2])
00120 
00121         self.verifyBrains()

Here is the call graph for this function:

Definition at line 222 of file test_referenceable.py.

00222 
00223     def test_setUID_keeps_relationships(self):
00224         obj_id   = 'demodoc'
00225         known_id = 'known_doc'
00226         owned_id = 'owned_doc'
00227 
00228         a = makeContent(self.folder, portal_type='DDocument',
00229                         title='Foo', id=obj_id)
00230         b = makeContent(self.folder, portal_type='DDocument',
00231                         title='Foo', id=known_id)
00232         c = makeContent(self.folder, portal_type='DDocument',
00233                         title='Foo', id=owned_id)
00234 
00235         #Two made up kinda refs
00236         a.addReference(b, "KnowsAbout")
00237         b.addReference(a, "KnowsAbout")
00238         a.addReference(c, "Owns")
00239 
00240         refs = a.getRefs()
00241         self.failUnless(b in refs, (b, refs))
00242         self.failUnless(c in refs, (c, refs))
00243         self.assertEquals(a.getRefs('KnowsAbout'), [b])
00244         self.assertEquals(b.getRefs('KnowsAbout'), [a])
00245         self.assertEquals(a.getRefs('Owns'), [c])
00246         self.assertEquals(c.getBRefs('Owns'), [a])
00247 
00248         old_uid = a.UID()
00249 
00250         # Check existing forward refs
00251         fw_refs = a.getReferenceImpl()
00252         old_refs = []
00253         [old_refs.append(o.sourceUID) for o in fw_refs
00254          if not o.sourceUID in old_refs]
00255         self.assertEquals(len(old_refs), 1)
00256         self.assertEquals(old_refs[0], old_uid)
00257 
00258         # Check existing backward refs
00259         fw_refs = a.getBackReferenceImpl()
00260         old_refs = []
00261         [old_refs.append(o.targetUID) for o in fw_refs
00262          if not o.targetUID in old_refs]
00263         self.assertEquals(len(old_refs), 1)
00264         self.assertEquals(old_refs[0], old_uid)
00265 
00266         new_uid = '9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9'
00267         a._setUID(new_uid)
00268         self.assertEquals(a.UID(), new_uid)
00269 
00270         # Check existing forward refs got reassigned
00271         fw_refs = a.getReferenceImpl()
00272         new_refs = []
00273         [new_refs.append(o.sourceUID) for o in fw_refs
00274          if not o.sourceUID in new_refs]
00275         self.assertEquals(len(new_refs), 1)
00276         self.assertEquals(new_refs[0], new_uid)
00277 
00278         # Check existing backward refs got reassigned
00279         fw_refs = a.getBackReferenceImpl()
00280         new_refs = []
00281         [new_refs.append(o.targetUID) for o in fw_refs
00282          if not o.targetUID in new_refs]
00283         self.assertEquals(len(new_refs), 1)
00284         self.assertEquals(new_refs[0], new_uid)
00285 
00286         refs = a.getRefs()
00287         self.failUnless(b in refs, (b, refs))
00288         self.failUnless(c in refs, (c, refs))
00289         self.assertEquals(a.getRefs('KnowsAbout'), [b])
00290         self.assertEquals(b.getRefs('KnowsAbout'), [a])
00291         self.assertEquals(a.getRefs('Owns'), [c])
00292         self.assertEquals(c.getBRefs('Owns'), [a])
00293 
00294         self.verifyBrains()

Here is the call graph for this function:

Definition at line 383 of file test_referenceable.py.

00383 
00384     def test_singleReference(self):
00385         # If an object is referenced don't record its reference again
00386         a = makeContent( self.folder, portal_type='DDocument',title='Foo', id='a')
00387         b = makeContent( self.folder, portal_type='DDocument',title='Foo', id='b')
00388 
00389         #Add the same ref twice
00390         a.addReference(b, "KnowsAbout")
00391         a.addReference(b, "KnowsAbout")
00392 
00393         self.assertEquals(len(a.getRefs('KnowsAbout')),  1)
00394 
00395         #In this case its a different relationship
00396         a.addReference(b, 'Flogs')
00397         self.assertEquals(len(a.getRefs('KnowsAbout')), 1)
00398         self.assertEquals(len(a.getRefs()), 2)

Here is the call graph for this function:

Definition at line 195 of file test_referenceable.py.

00195 
00196     def test_UIDclash( self ):
00197         catalog = getattr(self.portal, UID_CATALOG)
00198 
00199         obj_id = 'demodoc'
00200         new_id = 'new_demodoc'
00201         doc = makeContent( self.folder
00202                            , portal_type='DDocument'
00203                            , title='Foo'
00204                            , id=obj_id)
00205 
00206         UID = doc.UID()
00207         # ensure object has a _p_jar
00208         transaction.savepoint(optimistic=True)
00209         self.folder.manage_renameObject(id=obj_id, new_id=new_id)
00210 
00211         #now, make a new one with the same ID and check it gets a different UID
00212         doc2 = makeContent( self.folder
00213                             , portal_type='DDocument'
00214                             , title='Foo'
00215                             , id=obj_id)
00216 
00217         UID2 = doc2.UID()
00218         self.failIf(UID == UID2)
00219         uniq = catalog.uniqueValuesFor('UID')
00220         self.failUnless(UID in uniq, (UID, uniq))
00221         self.failUnless(UID2 in uniq, (UID, uniq))

Here is the call graph for this function:

Definition at line 417 of file test_referenceable.py.

00417 
00418     def test_UIDunderContainment(self):
00419         # If an object is referenced don't record its reference again
00420         at = self.portal.archetype_tool
00421 
00422         folder = makeContent( self.folder, portal_type=self.FOLDER_TYPE,
00423                               title='Foo', id='folder')
00424         nonRef = makeContent( folder, portal_type='Document',
00425                               title='Foo', id='nonRef')
00426 
00427         fuid = folder.UID()
00428         nuid = nonRef.UID()
00429         # We expect this to break, an aq_explicit would fix it but
00430         # we can't change the calling convention
00431         # XXX: but proxy index could
00432         # XXX: assert fuid != nuid

Here is the call graph for this function:

Definition at line 40 of file test_referenceable.py.

00040 
00041     def verifyBrains(self):
00042         uc = getattr(self.portal, UID_CATALOG)
00043         rc = getattr(self.portal, REFERENCE_CATALOG)
00044 
00045         #Verify all UIDs resolve
00046         brains = uc()
00047         uobjects = [b.getObject() for b in brains]
00048         self.failIf(None in uobjects, """bad uid resolution""")
00049 
00050         #Verify all references resolve
00051         brains = rc()
00052         robjects = [b.getObject() for b in brains]
00053         self.failIf(None in robjects, """bad ref catalog resolution""")
00054         return uobjects, robjects

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation


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