fix tests tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 14 Apr 2009 14:50:28 +0200
branchtls-sprint
changeset 1341 9502d02630bf
parent 1340 12e46a39f3f2
child 1342 4273e44852cb
fix tests
test/data/cubes/file/__init__.py
test/data/cubes/file/__pkginfo__.py
test/unittest_cwconfig.py
test/unittest_entity.py
test/unittest_vregistry.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/data/cubes/file/__pkginfo__.py	Tue Apr 14 14:50:28 2009 +0200
@@ -0,0 +1,54 @@
+# pylint: disable-msg=W0622
+"""cubicweb-file packaging information"""
+
+distname = "cubicweb-file"
+modname = distname.split('-', 1)[1]
+
+numversion = (1, 4, 3)
+version = '.'.join(str(num) for num in numversion)
+
+license = 'LGPL'
+copyright = '''Copyright (c) 2003-2009 LOGILAB S.A. (Paris, FRANCE).
+http://www.logilab.fr/ -- mailto:contact@logilab.fr'''
+
+author = "Logilab"
+author_email = "contact@logilab.fr"
+web = ''
+
+short_desc = "Raw file support for the CubicWeb framework"
+long_desc = """CubicWeb is a entities / relations bases knowledge management system
+developped at Logilab.
+.
+This package provides schema and views to store files and images in cubicweb
+applications.
+.
+"""
+
+from os import listdir
+from os.path import join
+
+CUBES_DIR = join('share', 'cubicweb', 'cubes')
+try:
+    data_files = [
+        [join(CUBES_DIR, 'file'),
+         [fname for fname in listdir('.')
+          if fname.endswith('.py') and fname != 'setup.py']],
+        [join(CUBES_DIR, 'file', 'data'),
+         [join('data', fname) for fname in listdir('data')]],
+        [join(CUBES_DIR, 'file', 'wdoc'),
+         [join('wdoc', fname) for fname in listdir('wdoc')]],
+        [join(CUBES_DIR, 'file', 'views'),
+         [join('views', fname) for fname in listdir('views') if fname.endswith('.py')]],
+        [join(CUBES_DIR, 'file', 'i18n'),
+         [join('i18n', fname) for fname in listdir('i18n')]],
+        [join(CUBES_DIR, 'file', 'migration'),
+         [join('migration', fname) for fname in listdir('migration')]],
+        ]
+except OSError:
+    # we are in an installed directory
+    pass
+
+
+cube_eid = 20320
+# used packages
+__use__ = ()
--- a/test/unittest_cwconfig.py	Tue Apr 14 11:26:50 2009 +0200
+++ b/test/unittest_cwconfig.py	Tue Apr 14 14:50:28 2009 +0200
@@ -11,7 +11,7 @@
 def unabsolutize(path):
     parts = path.split(os.sep)
     for i, part in reversed(tuple(enumerate(parts))):
-        if part in ('cubicweb', 'cubes', 'cubes'):
+        if part.startswith('cubicweb') or part == 'cubes':
             return '/'.join(parts[i+1:])
     raise Exception('duh? %s' % path)
     
@@ -20,6 +20,9 @@
         self.config = ApptestConfiguration('data')
         self.config._cubes = ('email', 'file')
 
+    def tearDown(self):
+        os.environ.pop('CW_CUBES_PATH', None)
+
     def test_reorder_cubes(self):
         # jpl depends on email and file and comment
         # email depends on file
--- a/test/unittest_entity.py	Tue Apr 14 11:26:50 2009 +0200
+++ b/test/unittest_entity.py	Tue Apr 14 14:50:28 2009 +0200
@@ -183,28 +183,25 @@
     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')
-        rschema = e.e_schema.subject_relation('tags')
         related = [r.eid for r in e.tags]
         self.failUnlessEqual(related, [])
-        unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')]
+        unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')]
         self.failUnless(p.eid in unrelated)
         self.execute('SET X tags Y WHERE X is Tag, Y is Personne')
         e = self.entity('Any X WHERE X is Tag')
-        unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')]
+        unrelated = [r[0] for r in e.unrelated('tags', 'Personne', 'subject')]
         self.failIf(p.eid in unrelated)
 
     def test_entity_unrelated_limit(self):
         e = self.add_entity('Tag', name=u'x')
         self.add_entity('Personne', nom=u'di mascio', prenom=u'adrien')
         self.add_entity('Personne', nom=u'di mascio', prenom=u'gwen')
-        rschema = e.e_schema.subject_relation('tags')
-        self.assertEquals(len(e.unrelated(rschema, 'Personne', 'subject', limit=1)),
+        self.assertEquals(len(e.unrelated('tags', 'Personne', 'subject', limit=1)),
                           1)
         
     def test_new_entity_unrelated(self):
         e = self.etype_instance('EUser')
-        rschema = e.e_schema.subject_relation('in_group')
-        unrelated = [reid for rview, reid in e.vocabulary(rschema, 'subject')]
+        unrelated = [r[0] for r in e.unrelated('in_group', 'EGroup', 'subject')]
         # should be default groups but owners, i.e. managers, users, guests
         self.assertEquals(len(unrelated), 3)
 
--- a/test/unittest_vregistry.py	Tue Apr 14 11:26:50 2009 +0200
+++ b/test/unittest_vregistry.py	Tue Apr 14 14:50:28 2009 +0200
@@ -12,6 +12,8 @@
 class YesSchema:
     def __contains__(self, something):
         return True
+
+WEBVIEWSDIR = join(BASE, 'web', 'views')
     
 class VRegistryTC(TestCase):
 
@@ -20,10 +22,11 @@
         self.vreg = CubicWebRegistry(config)
         config.bootstrap_cubes()
         self.vreg.schema = config.load_schema()
-
+        
     def test_load(self):
-        self.vreg.load_file(join(BASE, 'web', 'views'), 'euser.py')
-        self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
+        self.vreg.init_registration([WEBVIEWSDIR])
+        self.vreg.load_file(join(WEBVIEWSDIR, 'euser.py'), 'cubicweb.web.views.euser')
+        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]
         fpv = fpvc(None, None)
@@ -31,8 +34,9 @@
         self.assertRaises(AttributeError, fpv.render_entity_attributes, None, None)
 
     def test_load_interface_based_vojects(self):
-        self.vreg.load_file(join(BASE, 'web', 'views'), 'idownloadable.py')
-        self.vreg.load_file(join(BASE, 'web', 'views'), 'baseviews.py')
+        self.vreg.init_registration([WEBVIEWSDIR])
+        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.assertEquals(len(self.vreg['views']['primary']), 2)
                               
@@ -57,6 +61,7 @@
         class MyCard(Card):
             __implements__ = (IMileStone,)
         self.vreg.reset()
+        self.vreg._loadedmods[__name__] = {}
         self.vreg.register_vobject_class(MyCard)
         self.vreg.register_objects([join(BASE, 'web', 'views', 'iprogress.py')])
         # check progressbar isn't kicked