Author: jmorliaguet
Date: Sun Dec 11 16:40:23 2005
New Revision: 2013

Added:
   cpsskins/branches/jmo-perspectives/tests/test_relation_io.py   (contents, 
props changed)
Modified:
   cpsskins/branches/jmo-perspectives/io/relation.py
   cpsskins/branches/jmo-perspectives/io/relation.xml
Log:

- updated the relation exporter

- fixed test setup



Modified: cpsskins/branches/jmo-perspectives/io/relation.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/io/relation.py   (original)
+++ cpsskins/branches/jmo-perspectives/io/relation.py   Sun Dec 11 16:40:23 2005
@@ -23,27 +23,10 @@
 
 from cpsskins.relations.interfaces import IRelation
 from cpsskins.io.interfaces import IDataExporter, IDataImporter
+from zope.app.location.traversing import LocationPhysicallyLocatable
 
 class Exporter(object):
     """This view is used to exports relations to XML
-
-    >>> from zope.publisher.browser import TestRequest
-    >>> from zope.component import getMultiAdapter
-
-    >>> from cpsskins.relations import TestRelate as Relate, Predicate
-    >>> from cpsskins.relations import TriadicRelation
-
-    >>> first = Relate('converter')
-    >>> second = Relate('text')
-    >>> third = Relate('html')
-    >>> predicate = Predicate('_ converts _ into _')
-    >>> r = TriadicRelation(predicate=predicate, \
-                            first=first, second=second, third=third)
-
-    >>> request = TestRequest()
-    >>> exporter = getMultiAdapter((r, request), IDataExporter)
-    # TODO
-
     """
     implements(IDataExporter)
 
@@ -60,9 +43,9 @@
         context = self.context
         relate_info = []
 
-        for r in context:
+        for relate in context:
             relate_info.append({
-                'path': zapi.getPath(r),
+                'uri': zapi.name(relate),
                 })
 
         return {

Modified: cpsskins/branches/jmo-perspectives/io/relation.xml
==============================================================================
--- cpsskins/branches/jmo-perspectives/io/relation.xml  (original)
+++ cpsskins/branches/jmo-perspectives/io/relation.xml  Sun Dec 11 16:40:23 2005
@@ -3,5 +3,5 @@
           tal:define="info view/getInfo"
           tal:attributes="predicate info/predicate">
   <relate tal:repeat="relate info/relates"
-          tal:attributes="path relate/path" />
+          tal:attributes="uri relate/uri" />
 </relation>

Added: cpsskins/branches/jmo-perspectives/tests/test_relation_io.py
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/tests/test_relation_io.py        Sun Dec 
11 16:40:23 2005
@@ -0,0 +1,78 @@
+##############################################################################
+#
+# Copyright (c) 2005 Nuxeo and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Format tests
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import re
+import unittest
+
+from zope.app.testing import ztapi
+from zope.component import getMultiAdapter
+from zope.publisher.browser import TestRequest
+from zope.app.component.testing import PlacefulSetup
+from zope.app.folder import Folder
+
+from cpsskins.io.interfaces import IDataExporter, IDataImporter
+from cpsskins.relations.interfaces import IRelation
+from cpsskins.relations import TestRelate, Predicate
+
+def normalized(text=u''):
+    text = re.sub(r'\n', '', text)
+    text = re.sub(r'>\s+<', '><', text)
+    text = re.sub(r'\s+<', '<', text)
+    text = re.sub(r'>\s+', '>', text)
+    return text
+
+class Relate(TestRelate):
+
+    def __init__(self, name=u''):
+        self.name = name
+        self.__name__ = name
+
+class TestRelation(PlacefulSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self)
+        from cpsskins.io import relation
+        ztapi.browserViewProviding(IRelation, relation.Exporter, IDataExporter)
+        ztapi.provideAdapter(IRelation, relation.Importer, IDataImporter)
+
+    def test_export_triadic_relation(self):
+        from cpsskins.relations import TriadicRelation
+        rel = TriadicRelation(predicate=Predicate(u'_ A _ B _'),
+                              first=Relate(u'first'),
+                              second=Relate(u'second'),
+                              third=Relate(u'third'))
+
+        exporter = getMultiAdapter((rel, TestRequest()), IDataExporter)
+        expected = u"""
+          <?xml version="1.0"?>
+          <relation predicate="_ A _ B _">
+            <relate uri="first"/>
+            <relate uri="second"/>
+            <relate uri="third"/>
+          </relation>
+          """
+        self.assertEqual(normalized(exporter()), normalized(expected))
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestRelation),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to