author | Julien Cristau <julien.cristau@logilab.fr> |
Wed, 02 Apr 2014 12:44:57 +0200 | |
changeset 9642 | 9a42eaeea263 |
parent 9548 | be001628edad |
child 9854 | 4071c52b8fca |
permissions | -rw-r--r-- |
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 -*- |
9548
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
2 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
6964
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 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
|
22 |
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
|
23 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
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
|
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 |
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
|
27 |
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
|
28 |
'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
|
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 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
|
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 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
|
33 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
'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
|
37 |
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
|
38 |
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
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
'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
|
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_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
|
50 |
# 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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
55 |
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
|
56 |
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
|
57 |
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
|
58 |
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
|
59 |
'WHERE Y is EmailAddress, P is EmailPart') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6964
diff
changeset
|
60 |
self.assertTrue(self.execute('Email X WHERE X sender Y')) |
6964
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.commit() |
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('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
|
63 |
rset = self.execute('Any X WHERE X is EmailPart') |
9548
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
64 |
self.assertEqual(len(rset), 0) |
6964
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.commit() |
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
'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
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
'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
|
86 |
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
|
87 |
'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
|
88 |
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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
|
9548
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
96 |
def test_composite_object_relation_deletion(self): |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
97 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
98 |
root = req.create_entity('Folder', name=u'root') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
99 |
a = req.create_entity('Folder', name=u'a', parent=root) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
100 |
b = req.create_entity('Folder', name=u'b', parent=a) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
101 |
c = req.create_entity('Folder', name=u'c', parent=root) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
102 |
self.commit() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
103 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
104 |
req.execute('DELETE Folder F WHERE F name "a"') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
105 |
req.execute('DELETE F parent R WHERE R name "root"') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
106 |
self.commit() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
107 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
108 |
self.assertEqual([['root'], ['c']], |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
109 |
req.execute('Any NF WHERE F is Folder, F name NF').rows) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
110 |
self.assertEqual([], |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
111 |
req.execute('Any NF,NP WHERE F parent P, F name NF, P name NP').rows) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
112 |
|
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
113 |
def test_composite_subject_relation_deletion(self): |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
114 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
115 |
root = req.create_entity('Folder', name=u'root') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
116 |
a = req.create_entity('Folder', name=u'a') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
117 |
b = req.create_entity('Folder', name=u'b') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
118 |
c = req.create_entity('Folder', name=u'c') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
119 |
root.cw_set(children=(a, c)) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
120 |
a.cw_set(children=b) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
121 |
self.commit() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
122 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
123 |
req.execute('DELETE Folder F WHERE F name "a"') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
124 |
req.execute('DELETE R children F WHERE R name "root"') |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
125 |
self.commit() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
126 |
req = self.request() |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
127 |
self.assertEqual([['root'], ['c']], |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
128 |
req.execute('Any NF WHERE F is Folder, F name NF').rows) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
129 |
self.assertEqual([], |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
130 |
req.execute('Any NF,NP WHERE F parent P, F name NF, P name NP').rows) |
be001628edad
[schema] fix composite deletion handling
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9275
diff
changeset
|
131 |
|
6964
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
{'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
|
138 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
|
4813efcee2c6
[test] test extracted from unittest_hooks + new test for unique constraint check
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
148 |
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
|
149 |
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
|
150 |
unittest_main() |