Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
Marshall.tests.test_marshall.ATXMLReferenceMarshallTest Class Reference
Inheritance diagram for Marshall.tests.test_marshall.ATXMLReferenceMarshallTest:
Inheritance graph
[legend]
Collaboration diagram for Marshall.tests.test_marshall.ATXMLReferenceMarshallTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def createPerson
def test_uid_references
def test_path_references
def test_metadata_references
def test_linesfield

Public Attributes

 qi
 tool
 marshaller

Detailed Description

Definition at line 74 of file test_marshall.py.


Member Function Documentation

Definition at line 76 of file test_marshall.py.

00076 
00077     def afterSetUp(self):
00078         super(ATXMLReferenceMarshallTest, self).afterSetUp()
00079         self.loginPortalOwner()
00080         self.qi = self.portal.portal_quickinstaller
00081         self.qi.installProduct('Marshall')
00082         self.tool = getToolByName(self.portal, tool_id)
00083         self.marshaller = getComponent('atxml')

Here is the call graph for this function:

Definition at line 84 of file test_marshall.py.

00084 
00085     def createPerson(self, ctx, id, **kw):
00086         person.addPerson(ctx, id, **kw)
00087         ob = ctx._getOb(id)
00088         ob.indexObject()
00089         return ob

Here is the caller graph for this function:

Definition at line 381 of file test_marshall.py.

00381 
00382     def test_linesfield(self):
00383         sidnei = self.createPerson(
00384             self.portal,
00385             'sidnei',
00386             title='Sidnei da Silva',
00387             description='Familia Silva',
00388             food_preference='BBQ\nPizza\nShrimp')
00389 
00390         self.assertEquals(sidnei.getFoodPrefs(),
00391                           ('BBQ', 'Pizza', 'Shrimp'))
00392 
00393         lines_xml = """<?xml version="1.0" ?>
00394         <metadata xmlns="http://plone.org/ns/archetypes/"
00395                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00396         <field id="food_preference">
00397         BBQ
00398         </field>
00399         <field id="food_preference">
00400         Camaron Diablo
00401         </field>
00402         </metadata>
00403         """
00404         self.marshaller.demarshall(sidnei, lines_xml)
00405         self.assertEquals(sidnei.getFoodPrefs(),
00406                           ('BBQ', 'Camaron Diablo'))
00407         ctype, length, got = self.marshaller.marshall(sidnei)
00408         expected = [s.strip() for s in """\
00409         <field id="food_preference">
00410         BBQ
00411         </field>
00412         <field id="food_preference">
00413         Camaron Diablo
00414         </field>""".splitlines()]
00415         got = [s.strip() for s in got.splitlines()]
00416         comp = [s for s in expected if s in got]
00417         self.assertEquals(comp, expected)

Here is the call graph for this function:

Definition at line 248 of file test_marshall.py.

00248 
00249     def test_metadata_references(self):
00250         paulo = self.createPerson(
00251             self.portal,
00252             'paulo',
00253             title='Paulo da Silva',
00254             description='Familia Silva')
00255         paulo_s = self.createPerson(
00256             self.portal,
00257             'paulo_s',
00258             title='Paulo Schuh',
00259             description='Familia Schuh')
00260         sidnei = self.createPerson(
00261             self.portal,
00262             'sidnei',
00263             title='Sidnei da Silva',
00264             description='Familia Silva')
00265 
00266         self.assertEquals(sidnei.getParents(), [])
00267 
00268         ref_xml = """<?xml version="1.0" ?>
00269         <metadata xmlns="http://plone.org/ns/archetypes/"
00270                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00271         <field id="parents">
00272         <reference>
00273         <metadata>
00274         <dc:title>
00275         Paulo Schuh
00276         </dc:title>
00277         <dc:description>
00278         Familia Schuh
00279         </dc:description>
00280         </metadata>
00281         </reference>
00282         </field>
00283         </metadata>
00284         """
00285         self.marshaller.demarshall(sidnei, ref_xml)
00286         # Test a simple metadata reference
00287         self.assertEquals(sidnei['parents'], [paulo_s.UID()])
00288 
00289         ref_xml = """<?xml version="1.0" ?>
00290         <metadata xmlns="http://plone.org/ns/archetypes/"
00291                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00292         <field id="parents">
00293         <reference>
00294         <metadata>
00295         <dc:title>
00296         Silva
00297         </dc:title>
00298         </metadata>
00299         </reference>
00300         </field>
00301         </metadata>
00302         """
00303 
00304         # Test that a metadata reference that doesn't uniquely
00305         # identifies a target raises an exception
00306         self.assertRaises(MarshallingException, self.marshaller.demarshall,
00307                           sidnei, ref_xml)
00308 
00309         ref_xml = """<?xml version="1.0" ?>
00310         <metadata xmlns="http://plone.org/ns/archetypes/"
00311                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00312         <field id="parents">
00313         <reference>
00314         <metadata>
00315         <dc:title>
00316         Souza
00317         </dc:title>
00318         </metadata>
00319         </reference>
00320         </field>
00321         </metadata>
00322         """
00323         # Test that a metadata reference that doesn't uniquely
00324         # find at least one object raises an exception
00325         self.assertRaises(MarshallingException, self.marshaller.demarshall,
00326                           sidnei, ref_xml)
00327 
00328         ref_xml = """<?xml version="1.0" ?>
00329         <metadata xmlns="http://plone.org/ns/archetypes/"
00330                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00331         <field id="parents">
00332         <reference>
00333         <metadata>
00334         <dc:title>
00335         Paulo da Silva
00336         </dc:title>
00337         <dc:description>
00338         Familia Silva
00339         </dc:description>
00340         </metadata>
00341         </reference>
00342         </field>
00343         </metadata>
00344         """
00345         self.marshaller.demarshall(sidnei, ref_xml)
00346         # Test simple metadata reference
00347         self.assertEquals(sidnei['parents'], [paulo.UID()])
00348 
00349         ref_xml = """<?xml version="1.0" ?>
00350         <metadata xmlns="http://plone.org/ns/archetypes/"
00351                   xmlns:dc="http://purl.org/dc/elements/1.1/">
00352         <field id="parents">
00353         <reference>
00354         <metadata>
00355         <dc:title>
00356         Paulo da Silva
00357         </dc:title>
00358         <dc:description>
00359         Familia Silva
00360         </dc:description>
00361         </metadata>
00362         </reference>
00363         </field>
00364         <field id="parents">
00365         <reference>
00366         <metadata>
00367         <dc:title>
00368         Paulo Schuh
00369         </dc:title>
00370         <dc:description>
00371         Familia Schuh
00372         </dc:description>
00373         </metadata>
00374         </reference>
00375         </field>
00376         </metadata>
00377         """
00378         self.marshaller.demarshall(sidnei, ref_xml)
00379         # Test multiple metadata references
00380         self.assertEquals(sidnei['parents'], [paulo.UID(), paulo_s.UID()])

Here is the call graph for this function:

Definition at line 179 of file test_marshall.py.

00179 
00180     def test_path_references(self):
00181         paulo = self.createPerson(
00182             self.portal,
00183             'paulo',
00184             title='Paulo da Silva')
00185         eligia = self.createPerson(
00186             self.portal,
00187             'eligia',
00188             title='Eligia M. da Silva')
00189         sidnei = self.createPerson(
00190             self.portal,
00191             'sidnei',
00192             title='Sidnei da Silva')
00193 
00194         self.assertEquals(sidnei.getParents(), [])
00195 
00196         ref_xml = """<?xml version="1.0" ?>
00197         <metadata xmlns="http://plone.org/ns/archetypes/">
00198         <field id="parents">
00199         <reference>
00200         <path>
00201         %(path)s
00202         </path>
00203         </reference>
00204         </field>
00205         </metadata>
00206         """ % {'path':'paulo'}
00207         self.marshaller.demarshall(sidnei, ref_xml)
00208         # Test a simple path reference
00209         self.assertEquals(sidnei['parents'], [paulo.UID()])
00210 
00211         ref_xml = """<?xml version="1.0" ?>
00212         <metadata xmlns="http://plone.org/ns/archetypes/">
00213         <field id="parents">
00214         <reference>
00215         <path>
00216         XXX%(path)sXXX
00217         </path>
00218         </reference>
00219         </field>
00220         </metadata>
00221         """ % {'path':'paulo'}
00222         # Test that an invalid path reference raises an exception
00223         self.assertRaises(MarshallingException, self.marshaller.demarshall,
00224                           sidnei, ref_xml)
00225 
00226         ref_xml = """<?xml version="1.0" ?>
00227         <metadata xmlns="http://plone.org/ns/archetypes/">
00228         <field id="parents">
00229         <reference>
00230         <path>
00231         %(path1)s
00232         </path>
00233         </reference>
00234         </field>
00235         <field id="parents">
00236         <reference>
00237         <path>
00238         %(path2)s
00239         </path>
00240         </reference>
00241         </field>
00242         </metadata>
00243         """ % {'path1':'paulo', 'path2':'eligia'}
00244         self.marshaller.demarshall(sidnei, ref_xml)
00245         # Test multiple path references
00246         self.assertEquals(sidnei['parents'], [paulo.UID(), eligia.UID()])
00247 

Here is the call graph for this function:

Definition at line 90 of file test_marshall.py.

00090 
00091     def test_uid_references(self):
00092         paulo = self.createPerson(
00093             self.portal,
00094             'paulo',
00095             title='Paulo da Silva')
00096         eligia = self.createPerson(
00097             self.portal,
00098             'eligia',
00099             title='Eligia M. da Silva')
00100         sidnei = self.createPerson(
00101             self.portal,
00102             'sidnei',
00103             title='Sidnei da Silva')
00104 
00105         self.assertEquals(sidnei.getParents(), [])
00106 
00107         ref_xml = """<?xml version="1.0" ?>
00108         <metadata xmlns="http://plone.org/ns/archetypes/">
00109         <field id="parents">
00110         <reference>
00111         <uid>
00112         %(uid)s
00113         </uid>
00114         </reference>
00115         </field>
00116         </metadata>
00117         """ % {'uid':paulo.UID()}
00118         self.marshaller.demarshall(sidnei, ref_xml)
00119         # Test a simple UID reference
00120         self.assertEquals(sidnei['parents'], [paulo.UID()])
00121 
00122         ref_xml = """<?xml version="1.0" ?>
00123         <metadata xmlns="http://plone.org/ns/archetypes/">
00124         <field id="parents">
00125         <reference>
00126         <uid>
00127         XXX%(uid)sXXX
00128         </uid>
00129         </reference>
00130         </field>
00131         </metadata>
00132         """ % {'uid':paulo.UID()}
00133         # Test that invalid UID reference raises an exception
00134         self.assertRaises(MarshallingException, self.marshaller.demarshall,
00135                           sidnei, ref_xml)
00136 
00137 
00138         ref_xml = """<?xml version="1.0" ?>
00139         <metadata xmlns="http://plone.org/ns/archetypes/">
00140         <field id="parents">
00141         <reference>
00142         <uid>
00143         %(uid1)s
00144         </uid>
00145         </reference>
00146         </field>
00147         <field id="parents">
00148         <reference>
00149         <uid>
00150         %(uid2)s
00151         </uid>
00152         </reference>
00153         </field>
00154         </metadata>
00155         """ % {'uid1':paulo.UID(), 'uid2':eligia.UID()}
00156         self.marshaller.demarshall(sidnei, ref_xml)
00157         # Test that multiple UID references work.
00158         self.assertEquals(sidnei['parents'], [paulo.UID(), eligia.UID()])
00159 
00160         # *WARNING* the tests below are dependent on the one above.
00161         new_uid = '9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9'
00162         old_uid = paulo.UID()
00163         ref_xml = """<?xml version="1.0" ?>
00164         <metadata xmlns="http://plone.org/ns/archetypes/">
00165         <uid>
00166         %(uid)s
00167         </uid>
00168         </metadata>
00169         """ % {'uid':new_uid}
00170         self.marshaller.demarshall(paulo, ref_xml)
00171         # Test modifying a uid by marshalling
00172         self.assertEquals(paulo.UID(), new_uid)
00173         # Test that the references still apply
00174         self.assertEquals(sidnei['parents'], [paulo.UID(), eligia.UID()])
00175         # Test that trying to set a different object to the same UID
00176         # will raise an exception.
00177         self.assertRaises(MarshallingException, self.marshaller.demarshall,
00178                           sidnei, ref_xml)

Here is the call graph for this function:


Member Data Documentation

Definition at line 82 of file test_marshall.py.

Definition at line 79 of file test_marshall.py.

Definition at line 81 of file test_marshall.py.


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