fix tests tls-sprint
authorsylvain.thenault@logilab.fr
Mon, 04 May 2009 12:55:00 +0200
branchtls-sprint
changeset 1640 65b60f177eb1
parent 1639 375c857aa0f5
child 1641 2c80b09d8d86
fix tests
test/data/cubes/mycube/__init__.py
test/data/cubes/mycube/__pkginfo__.py
test/unittest_cwconfig.py
test/unittest_entity.py
test/unittest_rset.py
test/unittest_selectors.py
test/unittest_vregistry.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/data/cubes/mycube/__init__.py	Mon May 04 12:55:00 2009 +0200
@@ -0,0 +1,1 @@
+"""mycube's __init__"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/data/cubes/mycube/__pkginfo__.py	Mon May 04 12:55:00 2009 +0200
@@ -0,0 +1,1 @@
+distname = 'cubicweb-mycube'
--- a/test/unittest_cwconfig.py	Mon May 04 12:53:59 2009 +0200
+++ b/test/unittest_cwconfig.py	Mon May 04 12:55:00 2009 +0200
@@ -14,7 +14,7 @@
         if part.startswith('cubicweb') or part == 'cubes':
             return '/'.join(parts[i+1:])
     raise Exception('duh? %s' % path)
-    
+
 class CubicWebConfigurationTC(TestCase):
     def setUp(self):
         self.config = ApptestConfiguration('data')
@@ -38,7 +38,7 @@
                           ('jpl', 'email', 'file'))
         self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'file')),
                           ('jpl', 'email', 'file'))
-        
+
     def test_reorder_cubes_recommends(self):
         from cubes.comment import __pkginfo__ as comment_pkginfo
         comment_pkginfo.__recommend__ = ('file',)
@@ -55,8 +55,8 @@
                               ('jpl', 'email', 'comment', 'file'))
         finally:
             comment_pkginfo.__use__ = ()
-            
-        
+
+
 #     def test_vc_config(self):
 #         vcconf = self.config.vc_config()
 #         self.assertIsInstance(vcconf['EEMAIL'], Version)
@@ -64,7 +64,7 @@
 #         self.assertEquals(vcconf['CW'], (2, 31, 2))
 #         self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION')
 #         self.assertRaises(KeyError, vcconf.__getitem__, 'CRM')
-        
+
     def test_expand_cubes(self):
         self.assertEquals(self.config.expand_cubes(('email', 'eblog')),
                           ['email', 'eblog', 'file'])
@@ -104,7 +104,7 @@
         del cubes.file
         from cubes import file
         self.assertEquals(file.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'file'))])
-                                       
-                          
+
+
 if __name__ == '__main__':
     unittest_main()
--- a/test/unittest_entity.py	Mon May 04 12:53:59 2009 +0200
+++ b/test/unittest_entity.py	Mon May 04 12:55:00 2009 +0200
@@ -15,7 +15,7 @@
 ##         self.add_entity('Tag', name=u'x')
 ##         self.add_entity('Link', title=u'perdu', url=u'http://www.perdu.com',
 ##                         embed=False)
-    
+
     def test_boolean_value(self):
         e = self.etype_instance('CWUser')
         self.failUnless(e)
@@ -37,7 +37,7 @@
         self.assertEquals(e.has_eid(), True)
         e.eid = 2
         self.assertEquals(e.has_eid(), True)
-        
+
     def test_copy(self):
         self.add_entity('Tag', name=u'x')
         p = self.add_entity('Personne', nom=u'toto')
@@ -50,7 +50,7 @@
         self.assertEquals(len(e.ecrit_par), 1)
         self.assertEquals(e.ecrit_par[0].eid, p.eid)
         self.assertEquals(len(e.reverse_tags), 0)
-        
+
     def test_copy_with_nonmeta_composite_inlined(self):
         p = self.add_entity('Personne', nom=u'toto')
         oe = self.add_entity('Note', type=u'x')
@@ -61,7 +61,7 @@
         e.copy_relations(oe.eid)
         self.failIf(e.ecrit_par)
         self.failUnless(oe.ecrit_par)
-            
+
     def test_copy_with_composite(self):
         user = self.user()
         adeleid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org", U use_email X WHERE U login "admin"')[0][0]
@@ -74,7 +74,7 @@
         e.copy_relations(user.eid)
         self.failIf(e.use_email)
         self.failIf(e.primary_email)
-        
+
     def test_copy_with_non_initial_state(self):
         user = self.user()
         eid = self.execute('INSERT CWUser X: X login "toto", X upassword %(pwd)s, X in_group G WHERE G name "users"',
@@ -110,7 +110,7 @@
         self.assertEquals(len(p.related('tags', 'object', limit=2)), 2)
         self.assertEquals(len(p.related('tags', 'object')), 4)
 
-        
+
     def test_fetch_rql(self):
         user = self.user()
         Personne = self.vreg.etype_class('Personne')
@@ -130,7 +130,7 @@
         try:
             # testing unknown attributes
             Personne.fetch_attrs = ('bloug', 'beep')
-            self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne')            
+            self.assertEquals(Personne.fetch_rql(user), 'Any X WHERE X is Personne')
             # testing one non final relation
             Personne.fetch_attrs = ('nom', 'prenom', 'travaille')
             self.assertEquals(Personne.fetch_rql(user),
@@ -179,7 +179,7 @@
         # XXX
         self.assertEquals(aff.related_rql('evaluee'),
                           'Any X,AA ORDERBY Z DESC WHERE X modification_date Z, E eid %(x)s, E evaluee X, X modification_date AA')
-    
+
     def test_entity_unrelated(self):
         p = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
         e = self.add_entity('Tag', name=u'x')
@@ -198,7 +198,7 @@
         self.add_entity('Personne', nom=u'di mascio', prenom=u'gwen')
         self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)),
                           1)
-        
+
     def test_new_entity_unrelated(self):
         e = self.etype_instance('CWUser')
         unrelated = [r[0] for r in e.unrelated('in_group', 'CWGroup', 'subject')]
@@ -209,7 +209,7 @@
         e = self.add_entity('Card', title=u'rest test', content=u'du :eid:`1:*ReST*`',
                             content_format=u'text/rest')
         self.assertEquals(e.printable_value('content'),
-                          '<p>du <a class="reference" href="http://testing.fr/cubicweb/egroup/managers">*ReST*</a></p>\n')
+                          '<p>du <a class="reference" href="http://testing.fr/cubicweb/cwgroup/managers">*ReST*</a></p>\n')
         e['content'] = 'du <em>html</em> <ref rql="CWUser X">users</ref>'
         e['content_format'] = 'text/html'
         self.assertEquals(e.printable_value('content'),
@@ -237,7 +237,7 @@
             e['content_format'] = 'text/cubicweb-page-template'
             self.assertEquals(e.printable_value('content'),
                               '<h1>zou</h1>')
-        
+
 
     def test_printable_value_bytes(self):
         e = self.add_entity('File', data=Binary('lambda x: 1'), data_format=u'text/x-python',
@@ -254,7 +254,7 @@
 <span style="color: #C00000;">lambda</span> <span style="color: #000000;">x</span><span style="color: #0000C0;">:</span> <span style="color: #0080C0;">1</span>
 </pre>
 ''')
-        
+
         e = self.add_entity('File', data=Binary('*héhéhé*'), data_format=u'text/rest',
                             data_encoding=u'utf-8', name=u'toto.txt')
         self.assertEquals(e.printable_value('data'),
@@ -290,8 +290,8 @@
         self.assertEquals(e.printable_value('content'), e['content'])
         e['content'] = u'été'
         self.assertEquals(e.printable_value('content'), e['content'])
-        
-        
+
+
     def test_fulltextindex(self):
         e = self.etype_instance('File')
         e['name'] = 'an html file'
@@ -300,17 +300,17 @@
         e['data'] = Binary('some <em>data</em>')
         e['data_format'] = 'text/html'
         e['data_encoding'] = 'ascii'
-        self.assertEquals(set(e.get_words()), 
+        self.assertEquals(set(e.get_words()),
                           set(['an', 'html', 'file', 'du', 'html', 'some', 'data']))
 
-        
+
     def test_nonregr_relation_cache(self):
         p1 = self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
         p2 = self.add_entity('Personne', nom=u'toto')
         self.execute('SET X evaluee Y WHERE X nom "di mascio", Y nom "toto"')
         self.assertEquals(p1.evaluee[0].nom, "toto")
         self.failUnless(not p1.reverse_evaluee)
-        
+
     def test_complete_relation(self):
         self.execute('SET RT add_permission G WHERE RT name "wf_info_for", G name "managers"')
         self.commit()
@@ -382,7 +382,7 @@
         metainf['source'] = metainf['source'].copy()
         metainf['source']['base-url']  = 'http://cubicweb2.com/'
         self.assertEquals(note.absolute_url(), 'http://cubicweb2.com/note/%s' % note.eid)
-        
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()
--- a/test/unittest_rset.py	Mon May 04 12:53:59 2009 +0200
+++ b/test/unittest_rset.py	Mon May 04 12:55:00 2009 +0200
@@ -12,17 +12,17 @@
 
 from cubicweb.rset import NotAnEntity, ResultSet, attr_desc_iterator
 
-        
+
 def pprelcachedict(d):
     res = {}
     for k, (rset, related) in d.items():
         res[k] = sorted(v.eid for v in related)
     return sorted(res.items())
-        
+
 
 class AttrDescIteratorTC(TestCase):
     """TestCase for cubicweb.rset.attr_desc_iterator"""
-    
+
     def test_relations_description(self):
         """tests relations_description() function"""
         queries = {
@@ -35,7 +35,7 @@
         for rql, relations in queries.items():
             result = list(attr_desc_iterator(parse(rql).children[0]))
             self.assertEquals((rql, result), (rql, relations))
-            
+
     def test_relations_description_indexed(self):
         """tests relations_description() function"""
         queries = {
@@ -49,7 +49,7 @@
 
 
 
-class ResultSetTC(EnvBasedTC):    
+class ResultSetTC(EnvBasedTC):
 
     def setUp(self):
         super(ResultSetTC, self).setUp()
@@ -67,7 +67,7 @@
             params2 = dict(pair.split('=') for pair in info1[3].split('&'))
             self.assertDictEquals(params1, params2)
 
-        
+
     def test_build_url(self):
         req = self.request()
         baseurl = req.base_url()
@@ -79,8 +79,8 @@
         #                  '%stask/title/go' % baseurl)
         # empty _restpath should not crash
         self.compare_urls(req.build_url('view', _restpath=''), baseurl)
-                
-        
+
+
     def test_resultset_build(self):
         """test basic build of a ResultSet"""
         rs = ResultSet([1,2,3], 'CWGroup X', description=['CWGroup', 'CWGroup', 'CWGroup'])
@@ -102,7 +102,7 @@
         self.assertEquals(rs2.get_entity(0, 0).row, 0)
         self.assertEquals(rs.limit(2, offset=2).rows, [[14000, 'nico']])
         self.assertEquals(rs.limit(2, offset=3).rows, [])
-        
+
 
     def test_resultset_filter(self):
         rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']],
@@ -112,11 +112,11 @@
         rs.vreg = self.env.vreg
         def test_filter(entity):
             return entity.login != 'nico'
-        
+
         rs2 = rs.filtered_rset(test_filter)
         self.assertEquals(len(rs2), 2)
         self.assertEquals([login for _, login in rs2], ['adim', 'syt'])
-        
+
     def test_resultset_transform(self):
         rs = ResultSet([[12, 'adim'], [13, 'syt'], [14, 'nico']],
                        'Any U,L where U is CWUser, U login L',
@@ -128,20 +128,20 @@
 
         self.assertEquals(len(rs2), 3)
         self.assertEquals(list(rs2), [['adim'],['syt'],['nico']])
-        
+
     def test_resultset_sort(self):
         rs = ResultSet([[12000, 'adim'], [13000, 'syt'], [14000, 'nico']],
                        'Any U,L where U is CWUser, U login L',
                        description=[['CWUser', 'String']] * 3)
         rs.req = self.request()
         rs.vreg = self.env.vreg
-        
+
         rs2 = rs.sorted_rset(lambda e:e['login'])
         self.assertEquals(len(rs2), 3)
         self.assertEquals([login for _, login in rs2], ['adim', 'nico', 'syt'])
         # make sure rs is unchanged
         self.assertEquals([login for _, login in rs], ['adim', 'syt', 'nico'])
-        
+
         rs2 = rs.sorted_rset(lambda e:e['login'], reverse=True)
         self.assertEquals(len(rs2), 3)
         self.assertEquals([login for _, login in rs2], ['syt', 'nico', 'adim'])
@@ -165,7 +165,7 @@
                        description=[['CWUser', 'String', 'String']] * 5)
         rs.req = self.request()
         rs.vreg = self.env.vreg
-        
+
         rsets = rs.split_rset(lambda e:e['login'])
         self.assertEquals(len(rsets), 3)
         self.assertEquals([login for _, login,_ in rsets[0]], ['adim', 'adim'])
@@ -173,7 +173,7 @@
         self.assertEquals([login for _, login,_ in rsets[2]], ['nico', 'nico'])
         # make sure rs is unchanged
         self.assertEquals([login for _, login,_ in rs], ['adim', 'adim', 'syt', 'nico', 'nico'])
-        
+
         rsets = rs.split_rset(lambda e:e['login'], return_dict=True)
         self.assertEquals(len(rsets), 3)
         self.assertEquals([login for _, login,_ in rsets['nico']], ['nico', 'nico'])
@@ -198,7 +198,7 @@
                            u'Le carrelage en 42 leçons',
                            u'La tarte tatin en 15 minutes',
                            u"L'épluchage du castor commun"])
-        
+
     def test_cached_syntax_tree(self):
         """make sure syntax tree is cached"""
         rqlst1 = self.rset.syntax_tree()
@@ -216,21 +216,20 @@
         e.complete()
         self.assertEquals(e['firstname'], 'adrien')
         self.assertEquals(pprelcachedict(e._related_cache), [])
-        
+
     def test_get_entity_advanced(self):
         self.add_entity('Bookmark', title=u'zou', path=u'/view')
         self.execute('SET X bookmarked_by Y WHERE X is Bookmark, Y login "anon"')
         rset = self.execute('Any X,Y,XT,YN WHERE X bookmarked_by Y, X title XT, Y login YN')
-        
+
         e = rset.get_entity(0, 0)
         self.assertEquals(e.row, 0)
         self.assertEquals(e.col, 0)
         self.assertEquals(e['title'], 'zou')
         self.assertRaises(KeyError, e.__getitem__, 'path')
-        with traced_selection():
-            self.assertEquals(e.view('text'), 'zou')
+        self.assertEquals(e.view('text'), 'zou')
         self.assertEquals(pprelcachedict(e._related_cache), [])
-        
+
         e = rset.get_entity(0, 1)
         self.assertEquals(e.row, 0)
         self.assertEquals(e.col, 1)
@@ -243,7 +242,7 @@
         self.assertEquals(e.view('text'), 'anon')
         self.assertEquals(pprelcachedict(e._related_cache),
                           [])
-        
+
         self.assertRaises(NotAnEntity, rset.get_entity, 0, 2)
         self.assertRaises(NotAnEntity, rset.get_entity, 0, 3)
 
@@ -274,7 +273,7 @@
         self.assertEquals(s['name'], 'activated')
         self.assertRaises(KeyError, s.__getitem__, 'description')
 
-        
+
     def test_get_entity_cache_with_left_outer_join(self):
         eid = self.execute('INSERT CWUser E: E login "joe", E upassword "joe", E in_group G '
                            'WHERE G name "users"')[0][0]
@@ -287,7 +286,7 @@
         cached = e.related_cache('primary_email', 'subject', False)
         self.assertIsInstance(cached, ResultSet)
         self.assertEquals(cached.rowcount, 0)
-        
+
 
     def test_get_entity_union(self):
         e = self.add_entity('Bookmark', title=u'manger', path=u'path')
@@ -303,14 +302,14 @@
             self.assertEquals(entity.id, etype)
             attr = etype == 'Bookmark' and 'title' or 'name'
             self.assertEquals(entity[attr], n)
-        
+
     def test_related_entity_optional(self):
         e = self.add_entity('Bookmark', title=u'aaaa', path=u'path')
         rset = self.execute('Any B,U,L WHERE B bookmarked_by U?, U login L')
         entity, rtype = rset.related_entity(0, 2)
         self.assertEquals(entity, None)
         self.assertEquals(rtype, None)
-        
+
     def test_related_entity_union_subquery(self):
         e = self.add_entity('Bookmark', title=u'aaaa', path=u'path')
         rset = self.execute('Any X,N ORDERBY N WITH X,N BEING '
@@ -330,7 +329,7 @@
         entity, rtype = rset.related_entity(0, 1)
         self.assertEquals(entity.eid, e.eid)
         self.assertEquals(rtype, 'title')
-        
+
     def test_entities(self):
         rset = self.execute('Any U,G WHERE U in_group G')
         # make sure we have at least one element
@@ -340,7 +339,7 @@
         self.assertEquals(set(e.e_schema.type for e in rset.entities(1)),
                           set(['CWGroup',]))
 
-    def test_printable_rql(self):        
+    def test_printable_rql(self):
         rset = self.execute(u'CWEType X WHERE X final FALSE, X meta FALSE')
         self.assertEquals(rset.printable_rql(),
                           'Any X WHERE X final FALSE, X meta FALSE, X is CWEType')
@@ -351,7 +350,7 @@
         self.assertEquals(rset.searched_text(), 'foobar')
         rset = self.execute(u'Any X WHERE X has_text %(text)s', {'text' : 'foo'})
         self.assertEquals(rset.searched_text(), 'foo')
-        
-   
+
+
 if __name__ == '__main__':
     unittest_main()
--- a/test/unittest_selectors.py	Mon May 04 12:53:59 2009 +0200
+++ b/test/unittest_selectors.py	Mon May 04 12:55:00 2009 +0200
@@ -9,7 +9,7 @@
 
 from cubicweb.devtools.testlib import EnvBasedTC
 from cubicweb.vregistry import Selector, AndSelector, OrSelector
-from cubicweb.selectors import implements
+from cubicweb.selectors import implements, match_user_groups
 from cubicweb.interfaces import IDownloadable
 from cubicweb.web import action
 
@@ -109,6 +109,7 @@
             id = 'yo'
             category = 'foo'
             __select__ = match_user_groups('owners')
+        self.vreg._loadedmods[__name__] = {}
         self.vreg.register_vobject_class(SomeAction)
         self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
         try:
@@ -117,16 +118,16 @@
             self.login('john')
             # it should not be possible to use SomeAction not owned objects
             rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"')
-            self.failIf('foo' in self.pactions(req, rset))
+            self.failIf('yo' in dict(self.pactions(req, rset)))
             # insert a new card, and check that we can use SomeAction on our object
             self.execute('INSERT Card C: C title "zoubidou"')
             self.commit()
             rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"')
-            self.failUnless('foo' in self.pactions(req, rset))
+            self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset))
             # make sure even managers can't use the action
             self.restore_connection()
             rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"')
-            self.failIf('foo' in self.pactions(req, rset))
+            self.failIf('yo' in dict(self.pactions(req, rset)))
         finally:
             del self.vreg[SomeAction.__registry__][SomeAction.id]
 
--- a/test/unittest_vregistry.py	Mon May 04 12:53:59 2009 +0200
+++ b/test/unittest_vregistry.py	Mon May 04 12:55:00 2009 +0200
@@ -6,15 +6,16 @@
 from cubicweb.vregistry import VObject
 from cubicweb.cwvreg import CubicWebRegistry, UnknownProperty
 from cubicweb.devtools import TestServerConfiguration
-from cubicweb.entities.lib import Card
 from cubicweb.interfaces import IMileStone
 
+from cubes.card.entities import Card
+
 class YesSchema:
     def __contains__(self, something):
         return True
 
 WEBVIEWSDIR = join(BASE, 'web', 'views')
-    
+
 class VRegistryTC(TestCase):
 
     def setUp(self):
@@ -22,24 +23,26 @@
         self.vreg = CubicWebRegistry(config)
         config.bootstrap_cubes()
         self.vreg.schema = config.load_schema()
-        
+
     def test_load(self):
         self.vreg.init_registration([WEBVIEWSDIR])
-        self.vreg.load_file(join(WEBVIEWSDIR, 'euser.py'), 'cubicweb.web.views.euser')
+        self.vreg.load_file(join(WEBVIEWSDIR, 'cwuser.py'), 'cubicweb.web.views.cwuser')
         self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
         fpvc = [v for v in self.vreg.registry_objects('views', 'primary')
-               if v.__module__ == 'cubicweb.web.views.euser'][0]
+               if v.__module__ == 'cubicweb.web.views.cwuser'][0]
         fpv = fpvc(None, None)
         # don't want a TypeError due to super call
         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
 
     def test_load_interface_based_vojects(self):
         self.vreg.init_registration([WEBVIEWSDIR])
+        self.vreg.load_file(join(BASE, 'entities', '__init__.py'), 'cubicweb.entities.__init__')
         self.vreg.load_file(join(WEBVIEWSDIR, 'idownloadable.py'), 'cubicweb.web.views.idownloadable')
-        self.vreg.load_file(join(WEBVIEWSDIR, 'baseviews.py'), 'cubicweb.web.views.baseviews')
-        # check loading baseviews after idownloadable isn't kicking interface based views
+        self.vreg.load_file(join(WEBVIEWSDIR, 'primary.py'), 'cubicweb.web.views.primary')
         self.assertEquals(len(self.vreg['views']['primary']), 2)
-                              
+        self.vreg.initialization_completed()
+        self.assertEquals(len(self.vreg['views']['primary']), 1)
+
     def test___selectors__compat(self):
         myselector1 = lambda *args: 1
         myselector2 = lambda *args: 1
@@ -63,10 +66,11 @@
         self.vreg.reset()
         self.vreg._loadedmods[__name__] = {}
         self.vreg.register_vobject_class(MyCard)
-        self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
+        self.vreg.register_objects([join(BASE, 'entities', '__init__.py'),
+                                    join(BASE, 'web', 'views', 'iprogress.py')])
         # check progressbar isn't kicked
         self.assertEquals(len(self.vreg['views']['progressbar']), 1)
-        
+
 
 if __name__ == '__main__':
     unittest_main()