test/unittest_cwconfig.py
author sylvain.thenault@logilab.fr
Mon, 04 May 2009 12:55:00 +0200
branchtls-sprint
changeset 1640 65b60f177eb1
parent 1341 9502d02630bf
child 1977 606923dff11b
permissions -rw-r--r--
fix tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
     1
import sys
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     2
import os
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
     3
from os.path import dirname, join, abspath
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     4
from tempfile import mktemp
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     5
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     6
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     7
from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     8
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
from cubicweb.devtools import ApptestConfiguration
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    10
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    11
def unabsolutize(path):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
    parts = path.split(os.sep)
515
92d95b86263e search in reverted order else in case of installed cubes (eg in cubicweb/cubes) we do not remove all expected parts
sylvain.thenault@logilab.fr
parents: 13
diff changeset
    13
    for i, part in reversed(tuple(enumerate(parts))):
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    14
        if part.startswith('cubicweb') or part == 'cubes':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
            return '/'.join(parts[i+1:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
    raise Exception('duh? %s' % path)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    17
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
class CubicWebConfigurationTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    19
    def setUp(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
        self.config = ApptestConfiguration('data')
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    21
        self.config._cubes = ('email', 'file')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    23
    def tearDown(self):
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    24
        os.environ.pop('CW_CUBES_PATH', None)
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    25
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    def test_reorder_cubes(self):
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    27
        # jpl depends on email and file and comment
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    28
        # email depends on file
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    29
        self.assertEquals(self.config.reorder_cubes(['file', 'email', 'jpl']),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    30
                          ('jpl', 'email', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    31
        self.assertEquals(self.config.reorder_cubes(['email', 'file', 'jpl']),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    32
                          ('jpl', 'email', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    33
        self.assertEquals(self.config.reorder_cubes(['email', 'jpl', 'file']),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    34
                          ('jpl', 'email', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    35
        self.assertEquals(self.config.reorder_cubes(['file', 'jpl', 'email']),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    36
                          ('jpl', 'email', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    37
        self.assertEquals(self.config.reorder_cubes(['jpl', 'file', 'email']),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    38
                          ('jpl', 'email', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    39
        self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'file')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    40
                          ('jpl', 'email', 'file'))
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    41
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
    def test_reorder_cubes_recommends(self):
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    43
        from cubes.comment import __pkginfo__ as comment_pkginfo
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    44
        comment_pkginfo.__recommend__ = ('file',)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
        try:
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    46
            # email recommends comment
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    47
            # comment recommends file
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    48
            self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'file', 'comment')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    49
                              ('jpl', 'email', 'comment', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    50
            self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'comment', 'file')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    51
                              ('jpl', 'email', 'comment', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    52
            self.assertEquals(self.config.reorder_cubes(('jpl', 'comment', 'email', 'file')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    53
                              ('jpl', 'email', 'comment', 'file'))
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    54
            self.assertEquals(self.config.reorder_cubes(('comment', 'jpl', 'email', 'file')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    55
                              ('jpl', 'email', 'comment', 'file'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        finally:
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    57
            comment_pkginfo.__use__ = ()
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    58
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    59
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
#     def test_vc_config(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
#         vcconf = self.config.vc_config()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    62
#         self.assertIsInstance(vcconf['EEMAIL'], Version)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    63
#         self.assertEquals(vcconf['EEMAIL'], (0, 3, 1))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    64
#         self.assertEquals(vcconf['CW'], (2, 31, 2))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    65
#         self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    66
#         self.assertRaises(KeyError, vcconf.__getitem__, 'CRM')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    67
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    68
    def test_expand_cubes(self):
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    69
        self.assertEquals(self.config.expand_cubes(('email', 'eblog')),
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    70
                          ['email', 'eblog', 'file'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    71
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    72
    def test_vregistry_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    73
        self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()],
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
                          ['entities', 'web/views', 'sobjects',
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    75
                           'file/entities.py', 'file/views', 'file/hooks.py',
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    76
                           'email/entities.py', 'email/views', 'email/hooks.py',
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    77
                           'test/data/entities.py'])
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    78
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    79
    def test_cubes_path(self):
1023
278f997aa257 fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1015
diff changeset
    80
        # make sure we don't import the email cube, but the stdlib email package
278f997aa257 fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1015
diff changeset
    81
        import email
278f997aa257 fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1015
diff changeset
    82
        self.assertNotEquals(dirname(email.__file__), self.config.CUBES_DIR)
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    83
        os.environ['CW_CUBES_PATH'] = join(dirname(__file__), 'data', 'cubes')
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    84
        self.assertEquals(self.config.cubes_search_path(),
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    85
                          [abspath(join(dirname(__file__), 'data', 'cubes')),
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    86
                           self.config.CUBES_DIR])
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    87
        os.environ['CW_CUBES_PATH'] = '%s%s%s%s%s' % (join(dirname(__file__), 'data', 'cubes'),
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    88
                                                      os.pathsep, self.config.CUBES_DIR,
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    89
                                                      os.pathsep, 'unexistant')
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    90
        # filter out unexistant and duplicates
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    91
        self.assertEquals(self.config.cubes_search_path(),
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    92
                          [abspath(join(dirname(__file__), 'data', 'cubes')),
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    93
                           self.config.CUBES_DIR])
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    94
        self.failUnless('mycube' in self.config.available_cubes())
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    95
        # test cubes python path
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    96
        self.config.adjust_sys_path()
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    97
        import cubes
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    98
        self.assertEquals(cubes.__path__, self.config.cubes_search_path())
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    99
        # this import should succeed once path is adjusted
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   100
        from cubes import mycube
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   101
        self.assertEquals(mycube.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'mycube'))])
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   102
        # file cube should be overriden by the one found in data/cubes
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   103
        sys.modules.pop('cubes.file', None)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   104
        del cubes.file
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   105
        from cubes import file
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   106
        self.assertEquals(file.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'file'))])
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   107
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   108
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    unittest_main()