cubicweb/test/unittest_migration.py
author Laurent Peuch <cortex@worlddomination.be>
Wed, 22 May 2019 17:10:06 +0200
changeset 12745 cc681b6fcffa
parent 12629 6b314fc558ed
permissions -rw-r--r--
[migration/pdb] add option to use pdb.post_mortem if traceback is provided Post mortem is a mode where the pdb shell is opened **where** the exception as occured instead at the breakpoint for set_trace. This is way more useful for debugging for the user because is will have the full context of the error. Closes #17219827
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11269
diff changeset
     1
# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    18
"""cubicweb.migration unit tests"""
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1802
diff changeset
    19
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11269
diff changeset
    20
from os.path import dirname, join
12745
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
    21
from unittest.mock import patch
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
    22
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
from logilab.common.testlib import TestCase, unittest_main
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    24
12745
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
    25
from cubicweb import devtools, utils
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
    26
from logilab.common.shellutils import ASK
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
from cubicweb.cwconfig import CubicWebConfiguration
12629
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
    28
from cubicweb.migration import (
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
    29
    filter_scripts,
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
    30
    split_constraint,
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
    31
    version_strictly_lower,
12745
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
    32
    MigrationHelper,
12629
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
    33
)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
class Schema(dict):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
    def has_entity(self, e_type):
8697
574bb05e40a4 [toward py3k] rewrite has_key() (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8558
diff changeset
    38
        return e_type in self
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
6631
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    40
SMIGRDIR = join(dirname(__file__), 'data', 'server_migration') + '/'
26c303c3f1aa [test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    41
TMIGRDIR = join(dirname(__file__), 'data', 'migration') + '/'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
11768
b8b71dd09a2c [test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
    43
b8b71dd09a2c [test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
    44
class MigrTestConfig(devtools.TestServerConfiguration):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
    verbosity = 0
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11269
diff changeset
    46
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
    def migration_scripts_dir(cls):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
        return SMIGRDIR
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
    def cube_migration_scripts_dir(cls, cube):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
        return TMIGRDIR
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 755
diff changeset
    52
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
class MigrationToolsTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
    def setUp(self):
11269
73ac69970047 [devtools] Simplify test configuration's init
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    55
        self.config = MigrTestConfig('data', __file__)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
        from yams.schema import Schema
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
        self.config.load_schema = lambda expand_cubes=False: Schema('test')
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2275
diff changeset
    58
        self.config.__class__.cubicweb_appobject_path = frozenset()
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2275
diff changeset
    59
        self.config.__class__.cube_appobject_path = frozenset()
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 755
diff changeset
    60
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    61
    def test_filter_scripts_base(self):
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    62
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,3,0), (2,4,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    63
                              [])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    64
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,5,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    65
                              [((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql')])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    66
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,6,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    67
                              [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    68
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,4,0), (2,6,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    69
                              [((2, 5, 0), SMIGRDIR+'2.5.0_Any.sql'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    70
                               ((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    71
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,5,1)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    72
                              [])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    73
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,0), (2,10,2)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    74
                              [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    75
                               ((2, 10, 2), SMIGRDIR+'2.10.2_Any.sql')])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    76
        self.assertListEqual(filter_scripts(self.config, SMIGRDIR, (2,5,1), (2,6,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    77
                              [((2, 6, 0), SMIGRDIR+'2.6.0_Any.sql')])
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 755
diff changeset
    78
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    79
        self.assertListEqual(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,3)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    80
                              [((0, 0, 3), TMIGRDIR+'0.0.3_Any.py')])
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    81
        self.assertListEqual(filter_scripts(self.config, TMIGRDIR, (0,0,2), (0,0,4)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    82
                              [((0, 0, 3), TMIGRDIR+'0.0.3_Any.py'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    83
                               ((0, 0, 4), TMIGRDIR+'0.0.4_Any.py')])
1802
d628defebc17 delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 755
diff changeset
    84
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    85
    def test_filter_scripts_for_mode(self):
11269
73ac69970047 [devtools] Simplify test configuration's init
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
    86
        config = CubicWebConfiguration('data', __file__)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        config.verbosity = 0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    88
        config = self.config
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    89
        config.__class__.name = 'repository'
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    90
        self.assertListEqual(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    91
                              [((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    92
                               ((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    93
                               ((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py')])
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    94
        config.__class__.name = 'all-in-one'
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    95
        self.assertListEqual(filter_scripts(config, TMIGRDIR, (0,0,4), (0,1,0)),
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    96
                              [((0, 1 ,0), TMIGRDIR+'0.1.0_Any.py'),
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    97
                               ((0, 1 ,0), TMIGRDIR+'0.1.0_common.py'),
9251
e4d753c8b1c4 remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 8697
diff changeset
    98
                               ((0, 1 ,0), TMIGRDIR+'0.1.0_repository.py')])
2275
bc0bed0616a3 fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    99
        config.__class__.name = 'repository'
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   100
10720
201028085e12 [migration] NoneType is no longer comparable in py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10567
diff changeset
   101
    def test_version_strictly_lower(self):
201028085e12 [migration] NoneType is no longer comparable in py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10567
diff changeset
   102
        self.assertTrue(version_strictly_lower(None, '1.0.0'))
201028085e12 [migration] NoneType is no longer comparable in py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10567
diff changeset
   103
        self.assertFalse(version_strictly_lower('1.0.0', None))
201028085e12 [migration] NoneType is no longer comparable in py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents: 10567
diff changeset
   104
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   105
7078
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6631
diff changeset
   106
from cubicweb.devtools import ApptestConfiguration, get_test_db_handler
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   107
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   108
class BaseCreationTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   109
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   110
    def test_db_creation(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   111
        """make sure database can be created"""
11269
73ac69970047 [devtools] Simplify test configuration's init
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11057
diff changeset
   112
        config = ApptestConfiguration('data', __file__)
9460
a2a0bc984863 [config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 9251
diff changeset
   113
        source = config.system_source_config
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
   114
        self.assertEqual(source['db-driver'], 'sqlite')
7078
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6631
diff changeset
   115
        handler = get_test_db_handler(config)
bad26a22fe29 [test] New Handling of database for test.
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6631
diff changeset
   116
        handler.init_test_database()
8558
133101245cac [db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
   117
        handler.build_db_cache()
133101245cac [db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
   118
        repo, cnx = handler.get_repo_and_cnx()
9576
5d4f662f5e31 [devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents: 9460
diff changeset
   119
        with cnx:
5d4f662f5e31 [devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents: 9460
diff changeset
   120
            self.assertEqual(cnx.execute('Any SN WHERE X is CWUser, X login "admin", X in_state S, S name SN').rows,
5d4f662f5e31 [devtools] make get_repo_and_cnx return a repoapi ClientConnection
Julien Cristau <julien.cristau@logilab.fr>
parents: 9460
diff changeset
   121
                             [['activated']])
8558
133101245cac [db creation test] more testing of db initialization: call build_db_cache and ensure admin user exists
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 8544
diff changeset
   122
        repo.shutdown()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   123
12629
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   124
def test_split_constraint():
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   125
    assert split_constraint(">=0.1.0") == (">=", "0.1.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   126
    assert split_constraint(">= 0.1.0") == (">=", "0.1.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   127
    assert split_constraint(">0.1.1") == (">", "0.1.1")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   128
    assert split_constraint("> 0.1.1") == (">", "0.1.1")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   129
    assert split_constraint("<0.2.0") == ("<", "0.2.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   130
    assert split_constraint("< 0.2.0") == ("<", "0.2.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   131
    assert split_constraint("<=42.1.0") == ("<=", "42.1.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   132
    assert split_constraint("<= 42.1.0") == ("<=", "42.1.0")
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   133
6b314fc558ed [fix] parse cube version number without space in them
Laurent Peuch <cortex@worlddomination.be>
parents: 11768
diff changeset
   134
12745
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   135
class WontColideWithOtherExceptionsException(Exception):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   136
    pass
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   137
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   138
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   139
class MigrationHelperTC(TestCase):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   140
    @patch.object(utils, 'get_pdb')
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   141
    @patch.object(ASK, 'ask', return_value="pdb")
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   142
    def test_confirm_no_traceback(self, ask, get_pdb):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   143
        post_mortem = get_pdb.return_value.post_mortem
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   144
        set_trace = get_pdb.return_value.set_trace
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   145
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   146
        # we need to break after post_mortem is called otherwise we get
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   147
        # infinite recursion
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   148
        set_trace.side_effect = WontColideWithOtherExceptionsException
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   149
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   150
        mh = MigrationHelper(config=None)
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   151
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   152
        with self.assertRaises(WontColideWithOtherExceptionsException):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   153
            mh.confirm("some question")
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   154
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   155
        get_pdb.assert_called_once()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   156
        set_trace.assert_called_once()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   157
        post_mortem.assert_not_called()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   158
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   159
    @patch.object(utils, 'get_pdb')
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   160
    @patch.object(ASK, 'ask', return_value="pdb")
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   161
    def test_confirm_got_traceback(self, ask, get_pdb):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   162
        post_mortem = get_pdb.return_value.post_mortem
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   163
        set_trace = get_pdb.return_value.set_trace
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   164
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   165
        # we need to break after post_mortem is called otherwise we get
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   166
        # infinite recursion
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   167
        post_mortem.side_effect = WontColideWithOtherExceptionsException
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   168
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   169
        mh = MigrationHelper(config=None)
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   170
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   171
        fake_traceback = object()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   172
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   173
        with self.assertRaises(WontColideWithOtherExceptionsException):
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   174
            mh.confirm("some question", traceback=fake_traceback)
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   175
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   176
        get_pdb.assert_called_once()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   177
        set_trace.assert_not_called()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   178
        post_mortem.assert_called_once()
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   179
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   180
        # we want post_mortem to actually receive the traceback
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   181
        self.assertEqual(post_mortem.call_args, ((fake_traceback,),))
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   182
cc681b6fcffa [migration/pdb] add option to use pdb.post_mortem if traceback is provided
Laurent Peuch <cortex@worlddomination.be>
parents: 12629
diff changeset
   183
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   184
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   185
    unittest_main()