basic testing of relation tags tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 08 Apr 2009 11:30:57 +0200
branchtls-sprint
changeset 1284 63ed4f4ff38d
parent 1283 d812bd08c11c
child 1285 d5ce82d65c2b
basic testing of relation tags
test/unittest_entity.py
test/unittest_rtags.py
--- a/test/unittest_entity.py	Wed Apr 08 11:30:32 2009 +0200
+++ b/test/unittest_entity.py	Wed Apr 08 11:30:57 2009 +0200
@@ -208,86 +208,6 @@
         # should be default groups but owners, i.e. managers, users, guests
         self.assertEquals(len(unrelated), 3)
 
-
-    def test_rtags_expansion(self):
-        from cubicweb.entities import AnyEntity
-        class Personne(AnyEntity):
-            id = 'Personne'
-            __rtags__ = {
-                ('travaille', 'Societe', 'subject') : set(('primary',)),
-                ('evaluee', '*', 'subject') : set(('secondary',)),
-                'ecrit_par' : set(('inlineview',)),
-                }
-        self.vreg.register_vobject_class(Personne)
-        rtags = Personne.rtags
-        self.assertEquals(rtags.get_tags('evaluee', 'Note', 'subject'), set(('secondary', 'link')))
-        self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), False)
-        self.assertEquals(rtags.get_tags('evaluee', 'Personne', 'subject'), set(('secondary', 'link')))
-        self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False)
-        self.assertEquals(rtags.get_tags('ecrit_par', 'Note', 'object'), set(('inlineview', 'link')))
-        self.assertEquals(rtags.is_inlined('ecrit_par', 'Note', 'object'), True)
-        class Personne2(Personne):
-            id = 'Personne'
-            __rtags__ = {
-                ('evaluee', 'Note', 'subject') : set(('inlineview',)),
-                }
-        self.vreg.register_vobject_class(Personne2)
-        rtags = Personne2.rtags
-        self.assertEquals(rtags.get_tags('evaluee', 'Note', 'subject'), set(('inlineview', 'link')))
-        self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), True)
-        self.assertEquals(rtags.get_tags('evaluee', 'Personne', 'subject'), set(('secondary', 'link')))
-        self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False)
-    
-    def test_relations_by_category(self):
-        e = self.etype_instance('EUser')
-        def rbc(iterable):
-            return [(rschema.type, x) for rschema, tschemas, x in iterable]
-        self.assertEquals(rbc(e.relations_by_category('primary')),
-                          [('login', 'subject'), ('upassword', 'subject'),
-                           ('in_group', 'subject'), ('in_state', 'subject'),
-                           ('eid', 'subject'),])
-        # firstname and surname are put in secondary category in views.entities.EUserEntity
-        self.assertListEquals(rbc(e.relations_by_category('secondary')),
-                              [('firstname', 'subject'), ('surname', 'subject')])
-        self.assertListEquals(rbc(e.relations_by_category('generic')),
-                              [('primary_email', 'subject'),
-                               ('evaluee', 'subject'),
-                               ('for_user', 'object')])
-        # owned_by is defined both as subject and object relations on EUser
-        self.assertListEquals(rbc(e.relations_by_category('generated')),
-                              [('last_login_time', 'subject'),
-                               ('created_by', 'subject'),
-                               ('creation_date', 'subject'),
-                               ('is', 'subject'),
-                               ('is_instance_of', 'subject'),
-                               ('modification_date', 'subject'),
-                               ('owned_by', 'subject'),
-                               ('created_by', 'object'),
-                               ('wf_info_for', 'object'),
-                               ('owned_by', 'object'),
-                               ('bookmarked_by', 'object')])
-        e = self.etype_instance('Personne')
-        self.assertListEquals(rbc(e.relations_by_category('primary')),
-                              [('nom', 'subject'), ('eid', 'subject')])
-        self.assertListEquals(rbc(e.relations_by_category('secondary')),
-                              [('prenom', 'subject'),
-                               ('type', 'subject'),])
-        self.assertListEquals(rbc(e.relations_by_category('generic')),
-                              [('travaille', 'subject'),
-                               ('evaluee', 'subject'),
-                               ('connait', 'subject'),
-                               ('ecrit_par', 'object'),
-                               ('evaluee', 'object'),
-                               ('tags', 'object')])
-        self.assertListEquals(rbc(e.relations_by_category('generated')),
-                              [('created_by', 'subject'),
-                               ('creation_date', 'subject'),
-                               ('is', 'subject'),
-                               ('is_instance_of', 'subject'),
-                               ('modification_date', 'subject'),
-                               ('owned_by', 'subject')])
-        
-
     def test_printable_value_string(self):
         e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
                             content_format=u'text/rest')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unittest_rtags.py	Wed Apr 08 11:30:57 2009 +0200
@@ -0,0 +1,36 @@
+from logilab.common.testlib import TestCase, unittest_main
+from cubicweb.rtags import RelationTags
+
+class RelationTagsTC(TestCase):
+    
+    def test_rtags_expansion(self):
+        rtags = RelationTags()
+        rtags.set_rtag('primary', 'travaille', 'subject', 'Societe')
+        rtags.set_rtag('secondary', 'evaluee', 'subject')
+        rtags.set_rtag('generated', 'tags', 'object')
+        self.assertEquals(rtags.rtag('evaluee', 'subject', 'Note'), 'secondary')
+        self.assertEquals(rtags.rtag('travaille', 'subject', 'Societe'), 'primary')
+        self.assertEquals(rtags.rtag('travaille', 'subject', 'Note'), None)
+        self.assertEquals(rtags.rtag('tags', 'subject', 'Note'), None)
+        self.assertEquals(rtags.rtag('tags', 'object', 'Note'), 'generated')
+        
+#         self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('secondary', 'link')))
+#         self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), False)
+#         self.assertEquals(rtags.rtag('evaluee', 'Personne', 'subject'), set(('secondary', 'link')))
+#         self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False)
+#         self.assertEquals(rtags.rtag('ecrit_par', 'Note', 'object'), set(('inlineview', 'link')))
+#         self.assertEquals(rtags.is_inlined('ecrit_par', 'Note', 'object'), True)
+#         class Personne2(Personne):
+#             id = 'Personne'
+#             __rtags__ = {
+#                 ('evaluee', 'Note', 'subject') : set(('inlineview',)),
+#                 }
+#         self.vreg.register_vobject_class(Personne2)
+#         rtags = Personne2.rtags
+#         self.assertEquals(rtags.rtag('evaluee', 'Note', 'subject'), set(('inlineview', 'link')))
+#         self.assertEquals(rtags.is_inlined('evaluee', 'Note', 'subject'), True)
+#         self.assertEquals(rtags.rtag('evaluee', 'Personne', 'subject'), set(('secondary', 'link')))
+#         self.assertEquals(rtags.is_inlined('evaluee', 'Personne', 'subject'), False)        
+
+if __name__ == '__main__':
+    unittest_main()