cubicweb/hooks/test/unittest_syncsources.py
author Philippe Pepiot <philippe.pepiot@logilab.fr>
Tue, 17 Mar 2020 13:29:08 +0100
branch3.27
changeset 12914 87c3562b3bae
parent 12154 0cf35ffde0e4
permissions -rw-r--r--
[pkg] require python >= 3.4 This avoid pip pulling a version that does not run on python2 when using a python2 environment. Since we already released some 3.27 releases in pypi, I think we should release 3.27.3 and remove releases 3.27.2, 3.27.1 and 3.27.0 from pypi.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12152
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
# copyright 2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
#
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
# This file is part of CubicWeb.
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
#
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
# any later version.
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
#
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
# details.
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
#
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
from cubicweb import ValidationError
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
from cubicweb.devtools.testlib import CubicWebTC
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
class SyncSourcesTC(CubicWebTC):
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
12154
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    25
    def test_source_type_unknown(self):
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    26
        with self.admin_access.cnx() as cnx:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    27
            with self.assertRaises(ValidationError) as cm:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    28
                cnx.create_entity(
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    29
                    'CWSource', name=u'source',
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    30
                    type=u'doesnotexit',
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    31
                    parser=u'doestnotmatter',
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    32
                )
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    33
        self.assertIn('Unknown source type', str(cm.exception))
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    34
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    35
    def test_cant_delete_system_source(self):
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    36
        with self.admin_access.cnx() as cnx:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    37
            with self.assertRaises(ValidationError) as cm:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    38
                cnx.execute('DELETE CWSource X')
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    39
        self.assertIn('You cannot remove the system source', str(cm.exception))
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    40
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    41
    def test_cant_rename_system_source(self):
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    42
        with self.admin_access.cnx() as cnx:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    43
            with self.assertRaises(ValidationError) as cm:
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    44
                cnx.find('CWSource').one().cw_set(name=u'sexy name')
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    45
        self.assertIn('You cannot rename the system source', str(cm.exception))
0cf35ffde0e4 [test] Add some tests for hooks.syncsources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12153
diff changeset
    46
12152
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
    def test_cant_add_config_system_source(self):
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
        with self.admin_access.cnx() as cnx:
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
            source = cnx.find('CWSource').one()
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
12153
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    51
            with self.assertRaises(ValidationError) as cm:
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    52
                source.cw_set(url=u'whatever')
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    53
            self.assertIn("Configuration of the system source goes to the 'sources' file",
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    54
                          str(cm.exception))
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    55
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    56
            with self.assertRaises(ValidationError) as cm:
12152
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
                source.cw_set(config=u'whatever')
12153
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    58
            self.assertIn("Configuration of the system source goes to the 'sources' file",
0ff0aff4413d [sources] Check source's url attribute value on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 12152
diff changeset
    59
                          str(cm.exception))
12152
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
if __name__ == '__main__':
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
    import unittest
f34d18d0603f [sources] Check sources configuration is fine on creation/modification
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
    unittest.main()