hooks/test/unittest_integrity.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Sat, 11 Jun 2011 09:22:25 +0200
changeset 7497 7beb71d76d82
parent 6964 4813efcee2c6
child 7791 31bb51ea5485
permissions -rw-r--r--
[rql2sql] add test case for 7493:3c46b9390871
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6964
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
#
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
# This file is part of CubicWeb.
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
#
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
# CubicWeb is free software: you can redistribute it and/or modify it under the
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
# terms of the GNU Lesser General Public License as published by the Free
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
# Software Foundation, either version 2.1 of the License, or (at your option)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
# any later version.
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
#
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    15
# details.
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    16
#
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    17
# You should have received a copy of the GNU Lesser General Public License along
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
"""functional tests for integrity hooks"""
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from __future__ import with_statement
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
from cubicweb import ValidationError
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
from cubicweb.devtools.testlib import CubicWebTC
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
class CoreHooksTC(CubicWebTC):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
    def test_delete_internal_entities(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
        self.assertRaises(ValidationError, self.execute,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
                          'DELETE CWEType X WHERE X name "CWEType"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
        self.assertRaises(ValidationError, self.execute,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
                          'DELETE CWRType X WHERE X name "relation_type"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
        self.assertRaises(ValidationError, self.execute,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
                          'DELETE CWGroup X WHERE X name "owners"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
    def test_delete_required_relations_subject(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
        self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y '
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
                     'WHERE Y name "users"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
        self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
        self.assertRaises(ValidationError, self.commit)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
        self.execute('DELETE X in_group Y WHERE X login "toto"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
        self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
    def test_delete_required_relations_object(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        self.skipTest('no sample in the schema ! YAGNI ? Kermaat ?')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    def test_static_vocabulary_check(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
        self.assertRaises(ValidationError,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
                          self.execute,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
                          'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
    def test_missing_required_relations_subject_inline(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
        # missing in_group relation
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    56
        self.execute('INSERT CWUser X: X login "toto", X upassword "hop"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
        self.assertRaises(ValidationError,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
                          self.commit)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
    def test_composite_1(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
                     'WHERE Y is EmailAddress, P is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
        self.failUnless(self.execute('Email X WHERE X sender Y'))
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
        self.execute('DELETE Email X')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
        rset = self.execute('Any X WHERE X is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
        self.assertEqual(len(rset), 1)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
        rset = self.execute('Any X WHERE X is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
        self.assertEqual(len(rset), 0)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
    def test_composite_2(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
                     'WHERE Y is EmailAddress, P is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
        self.execute('DELETE Email X')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
        self.execute('DELETE EmailPart X')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    83
        rset = self.execute('Any X WHERE X is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
        self.assertEqual(len(rset), 0)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    86
    def test_composite_redirection(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
        self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    88
        self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
        self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P '
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    90
                     'WHERE Y is EmailAddress, P is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
        self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y '
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
                     'WHERE Y is EmailAddress')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
        self.execute('DELETE X parts Y WHERE X messageid "<1234>"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
        self.execute('SET X parts Y WHERE X messageid "<2345>"')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    97
        rset = self.execute('Any X WHERE X is EmailPart')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
        self.assertEqual(len(rset), 1)
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
        self.assertEqual(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
    def test_unsatisfied_constraints(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   102
        releid = self.execute('SET U in_group G WHERE G name "owners", U login "admin"')[0][0]
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
        with self.assertRaises(ValidationError) as cm:
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
            self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
        self.assertEqual(cm.exception.errors,
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
                          {'in_group-object': u'RQLConstraint NOT O name "owners" failed'})
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
    def test_unique_constraint(self):
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        req = self.request()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   110
        entity = req.create_entity('CWGroup', name=u'trout')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   112
        self.assertRaises(ValidationError, req.create_entity, 'CWGroup', name=u'trout')
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
        self.rollback()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   114
        req.execute('SET X name "trout" WHERE X eid %(x)s', {'x': entity.eid})
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
        self.commit()
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   117
if __name__ == '__main__':
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   118
    from logilab.common.testlib import unittest_main
4813efcee2c6 [test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
    unittest_main()