move card role to cubes.card tls-sprint
authorsylvain.thenault@logilab.fr
Mon, 04 May 2009 13:30:47 +0200
branchtls-sprint
changeset 1643 59c5cec05bbd
parent 1642 12a98b17fb05
child 1644 45bec81a9e1c
move card role to cubes.card
common/test/unittest_rest.py
ext/rest.py
ext/test/unittest_rest.py
--- a/common/test/unittest_rest.py	Mon May 04 13:18:38 2009 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-from logilab.common.testlib import unittest_main
-from cubicweb.devtools.apptest import EnvBasedTC
-
-from cubicweb.common.rest import rest_publish
-        
-class RestTC(EnvBasedTC):
-    def context(self):
-        return self.execute('CWUser X WHERE X login "admin"').get_entity(0, 0)
-    
-    def test_eid_role(self):
-        context = self.context()
-        self.assertEquals(rest_publish(context, ':eid:`%s`' % context.eid),
-                          '<p><a class="reference" href="http://testing.fr/cubicweb/euser/admin">#%s</a></p>\n' % context.eid)
-        self.assertEquals(rest_publish(context, ':eid:`%s:some text`' %  context.eid),
-                          '<p><a class="reference" href="http://testing.fr/cubicweb/euser/admin">some text</a></p>\n')
-        
-    def test_card_role_create(self):
-        self.assertEquals(rest_publish(self.context(), ':card:`index`'),
-                          '<p><a class="reference" href="http://testing.fr/cubicweb/view?etype=Card&amp;wikiid=index&amp;vid=creation">index</a></p>\n')
-
-    def test_card_role_link(self):
-        self.add_entity('Card', wikiid=u'index', title=u'Site index page', synopsis=u'yo')
-        self.assertEquals(rest_publish(self.context(), ':card:`index`'),
-                          '<p><a class="reference" href="http://testing.fr/cubicweb/card/index">index</a></p>\n')
-
-    def test_bad_rest_no_crash(self):
-        data = rest_publish(self.context(), '''
-| card | implication     |
---------------------------
-| 1-1  | N1 = N2         |
-| 1-?  | N1 <= N2        |
-| 1-+  | N1 >= N2        |
-| 1-*  | N1>0 => N2>0    |       
---------------------------
-| ?-?  | N1 # N2         |
-| ?-+  | N1 >= N2        |
-| ?-*  | N1 #  N2        |
---------------------------
-| +-+  | N1>0 => N2>0 et |
-|      | N2>0 => N1>0    |
-| +-*  | N1>+ => N2>0    |
---------------------------
-| *-*  | N1#N2           |
---------------------------
-
-''')
-        
-if __name__ == '__main__':
-    unittest_main()
--- a/ext/rest.py	Mon May 04 13:18:38 2009 +0200
+++ b/ext/rest.py	Mon May 04 13:30:47 2009 +0200
@@ -76,31 +76,6 @@
 register_canonical_role('eid', eid_reference_role)
 
 
-def card_reference_role(role, rawtext, text, lineno, inliner,
-                       options={}, content=[]):
-    text = text.strip()
-    try:
-        wikiid, rest = text.split(u':', 1)
-    except:
-        wikiid, rest = text, text
-    context = inliner.document.settings.context
-    cardrset = context.req.execute('Card X WHERE X wikiid %(id)s',
-                                   {'id': wikiid})
-    if cardrset:
-        ref = cardrset.get_entity(0, 0).absolute_url()
-    else:
-        schema = context.schema
-        if schema.eschema('Card').has_perm(context.req, 'add'):
-            ref = context.req.build_url('view', vid='creation', etype='Card', wikiid=wikiid)
-        else:
-            ref = '#'
-    set_classes(options)
-    return [nodes.reference(rawtext, utils.unescape(rest), refuri=ref,
-                            **options)], []
-
-register_canonical_role('card', card_reference_role)
-
-
 def winclude_directive(name, arguments, options, content, lineno,
                        content_offset, block_text, state, state_machine):
     """Include a reST file as part of the content of this reST file.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ext/test/unittest_rest.py	Mon May 04 13:30:47 2009 +0200
@@ -0,0 +1,40 @@
+from logilab.common.testlib import unittest_main
+from cubicweb.devtools.apptest import EnvBasedTC
+
+from cubicweb.ext.rest import rest_publish
+
+class RestTC(EnvBasedTC):
+    def context(self):
+        return self.execute('CWUser X WHERE X login "admin"').get_entity(0, 0)
+
+    def test_eid_role(self):
+        context = self.context()
+        self.assertEquals(rest_publish(context, ':eid:`%s`' % context.eid),
+                          '<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">#%s</a></p>\n' % context.eid)
+        self.assertEquals(rest_publish(context, ':eid:`%s:some text`' %  context.eid),
+                          '<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">some text</a></p>\n')
+
+    def test_bad_rest_no_crash(self):
+        data = rest_publish(self.context(), '''
+| card | implication     |
+--------------------------
+| 1-1  | N1 = N2         |
+| 1-?  | N1 <= N2        |
+| 1-+  | N1 >= N2        |
+| 1-*  | N1>0 => N2>0    |
+--------------------------
+| ?-?  | N1 # N2         |
+| ?-+  | N1 >= N2        |
+| ?-*  | N1 #  N2        |
+--------------------------
+| +-+  | N1>0 => N2>0 et |
+|      | N2>0 => N1>0    |
+| +-*  | N1>+ => N2>0    |
+--------------------------
+| *-*  | N1#N2           |
+--------------------------
+
+''')
+
+if __name__ == '__main__':
+    unittest_main()