author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 20 Aug 2010 08:21:15 +0200 | |
branch | stable |
changeset 6126 | aca6a2c357fd |
parent 5895 | 6a3f776292a5 |
child 6142 | 8bc6eac1fac1 |
child 6340 | 470d8e828fda |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
3 |
# 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:
5030
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
5 |
# 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:
5030
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
7 |
# 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:
5030
diff
changeset
|
8 |
# 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:
5030
diff
changeset
|
9 |
# 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:
5030
diff
changeset
|
10 |
# 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:
5030
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# 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:
5030
diff
changeset
|
13 |
# 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:
5030
diff
changeset
|
14 |
# 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:
5030
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5030
diff
changeset
|
17 |
# 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:
5030
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
"""functional tests for core hooks |
20 |
||
21 |
note: most schemahooks.py hooks are actually tested in unittest_migrations.py |
|
22 |
""" |
|
23 |
||
24 |
from logilab.common.testlib import TestCase, unittest_main |
|
2454
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
25 |
|
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
26 |
from datetime import datetime |
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
27 |
|
4689
4eb1f4490538
[test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4667
diff
changeset
|
28 |
from cubicweb import ValidationError, AuthenticationError, BadConnectionId |
4eb1f4490538
[test] skipping versions checking during test is enough, no need for monkey patch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4667
diff
changeset
|
29 |
from cubicweb.devtools.testlib import CubicWebTC |
1787 | 30 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
31 |
class CoreHooksTC(CubicWebTC): |
1787 | 32 |
|
0 | 33 |
def test_delete_internal_entities(self): |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
34 |
self.assertRaises(ValidationError, self.execute, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
35 |
'DELETE CWEType X WHERE X name "CWEType"') |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
36 |
self.assertRaises(ValidationError, self.execute, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
37 |
'DELETE CWRType X WHERE X name "relation_type"') |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
38 |
self.assertRaises(ValidationError, self.execute, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
39 |
'DELETE CWGroup X WHERE X name "owners"') |
0 | 40 |
|
41 |
def test_delete_required_relations_subject(self): |
|
2920
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
42 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop", X in_group Y ' |
64322aa83a1d
start a new workflow engine
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
43 |
'WHERE Y name "users"') |
0 | 44 |
self.commit() |
45 |
self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"') |
|
46 |
self.assertRaises(ValidationError, self.commit) |
|
47 |
self.execute('DELETE X in_group Y WHERE X login "toto"') |
|
48 |
self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"') |
|
49 |
self.commit() |
|
1787 | 50 |
|
0 | 51 |
def test_delete_required_relations_object(self): |
52 |
self.skip('no sample in the schema ! YAGNI ? Kermaat ?') |
|
1787 | 53 |
|
0 | 54 |
def test_static_vocabulary_check(self): |
55 |
self.assertRaises(ValidationError, |
|
56 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
57 |
'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"') |
1787 | 58 |
|
0 | 59 |
def test_missing_required_relations_subject_inline(self): |
1787 | 60 |
# missing in_group relation |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
61 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop"') |
0 | 62 |
self.assertRaises(ValidationError, |
63 |
self.commit) |
|
64 |
||
65 |
def test_inlined(self): |
|
66 |
self.assertEquals(self.repo.schema['sender'].inlined, True) |
|
67 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
68 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
69 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
70 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
71 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
72 |
rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid) |
|
73 |
self.assertEquals(len(rset), 1) |
|
1787 | 74 |
|
0 | 75 |
def test_composite_1(self): |
76 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
77 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
78 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
79 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
80 |
self.failUnless(self.execute('Email X WHERE X sender Y')) |
|
81 |
self.commit() |
|
82 |
self.execute('DELETE Email X') |
|
83 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
84 |
self.assertEquals(len(rset), 1) |
|
85 |
self.commit() |
|
86 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
87 |
self.assertEquals(len(rset), 0) |
|
1787 | 88 |
|
0 | 89 |
def test_composite_2(self): |
90 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
91 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
92 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
93 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
94 |
self.commit() |
|
95 |
self.execute('DELETE Email X') |
|
96 |
self.execute('DELETE EmailPart X') |
|
97 |
self.commit() |
|
98 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
99 |
self.assertEquals(len(rset), 0) |
|
1787 | 100 |
|
0 | 101 |
def test_composite_redirection(self): |
102 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
103 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
104 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
105 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
106 |
self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y ' |
|
107 |
'WHERE Y is EmailAddress') |
|
108 |
self.commit() |
|
109 |
self.execute('DELETE X parts Y WHERE X messageid "<1234>"') |
|
110 |
self.execute('SET X parts Y WHERE X messageid "<2345>"') |
|
111 |
self.commit() |
|
112 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
113 |
self.assertEquals(len(rset), 1) |
|
114 |
self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>') |
|
115 |
||
116 |
def test_unsatisfied_constraints(self): |
|
5895
6a3f776292a5
[selectors]Â avoid spurious warning when using implements by design
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
117 |
releid = self.execute('SET U in_group G WHERE G name "owners", U login "admin"')[0][0] |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
118 |
ex = self.assertRaises(ValidationError, self.commit) |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
119 |
self.assertEquals(ex.errors, |
5895
6a3f776292a5
[selectors]Â avoid spurious warning when using implements by design
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
120 |
{'in_group-object': u'RQLConstraint NOT O name "owners" failed'}) |
0 | 121 |
|
122 |
def test_html_tidy_hook(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
123 |
req = self.request() |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
124 |
entity = req.create_entity('Workflow', name=u'wf1', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
125 |
description=u'yo') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
126 |
self.assertEquals(entity.description, u'yo') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
127 |
entity = req.create_entity('Workflow', name=u'wf2', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
128 |
description=u'<b>yo') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
129 |
self.assertEquals(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
130 |
entity = req.create_entity('Workflow', name=u'wf3', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
131 |
description=u'<b>yo</b>') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
132 |
self.assertEquals(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
133 |
entity = req.create_entity('Workflow', name=u'wf4', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
134 |
description=u'<b>R&D</b>') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
135 |
self.assertEquals(entity.description, u'<b>R&D</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
136 |
entity = req.create_entity('Workflow', name=u'wf5', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
137 |
description=u"<div>c'est <b>l'été") |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
138 |
self.assertEquals(entity.description, u"<div>c'est <b>l'été</b></div>") |
0 | 139 |
|
140 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
141 |
entity = self.request().create_entity('Workflow', name=u'wf1', description_format=u'text/html', |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
142 |
description=u'yo') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
143 |
entity.set_attributes(name=u'wf2') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
144 |
self.assertEquals(entity.description, u'yo') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
145 |
entity.set_attributes(description=u'R&D<p>yo') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
146 |
entity.pop('description') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
147 |
self.assertEquals(entity.description, u'R&D<p>yo</p>') |
1787 | 148 |
|
149 |
||
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
150 |
def test_metadata_cwuri(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
151 |
entity = self.request().create_entity('Workflow', name=u'wf1') |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
152 |
self.assertEquals(entity.cwuri, self.repo.config['base-url'] + 'eid/%s' % entity.eid) |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
153 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
154 |
def test_metadata_creation_modification_date(self): |
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
155 |
_now = datetime.now() |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
156 |
entity = self.request().create_entity('Workflow', name=u'wf1') |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
157 |
self.assertEquals((entity.creation_date - _now).seconds, 0) |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
158 |
self.assertEquals((entity.modification_date - _now).seconds, 0) |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
159 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
160 |
def test_metadata_created_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
161 |
entity = self.request().create_entity('Bookmark', title=u'wf1', path=u'/view') |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
162 |
self.commit() # fire operations |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
163 |
self.assertEquals(len(entity.created_by), 1) # make sure we have only one creator |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
164 |
self.assertEquals(entity.created_by[0].eid, self.session.user.eid) |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
165 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
166 |
def test_metadata_owned_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
167 |
entity = self.request().create_entity('Bookmark', title=u'wf1', path=u'/view') |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
168 |
self.commit() # fire operations |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
169 |
self.assertEquals(len(entity.owned_by), 1) # make sure we have only one owner |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
170 |
self.assertEquals(entity.owned_by[0].eid, self.session.user.eid) |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
171 |
|
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
172 |
def test_user_login_stripped(self): |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
173 |
u = self.create_user(' joe ') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
174 |
tname = self.execute('Any L WHERE E login L, E eid %(e)s', |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
175 |
{'e': u.eid})[0][0] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
176 |
self.assertEquals(tname, 'joe') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
177 |
self.execute('SET X login " jijoe " WHERE X eid %(x)s', {'x': u.eid}) |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
178 |
tname = self.execute('Any L WHERE E login L, E eid %(e)s', |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
179 |
{'e': u.eid})[0][0] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
180 |
self.assertEquals(tname, 'jijoe') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
181 |
|
0 | 182 |
|
183 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
184 |
class UserGroupHooksTC(CubicWebTC): |
1787 | 185 |
|
0 | 186 |
def test_user_synchronization(self): |
187 |
self.create_user('toto', password='hop', commit=False) |
|
188 |
self.assertRaises(AuthenticationError, |
|
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
189 |
self.repo.connect, u'toto', password='hop') |
0 | 190 |
self.commit() |
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
191 |
cnxid = self.repo.connect(u'toto', password='hop') |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
192 |
self.failIfEqual(cnxid, self.session.id) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
193 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 194 |
self.repo.execute(cnxid, 'State X') |
195 |
self.commit() |
|
196 |
self.assertRaises(BadConnectionId, |
|
197 |
self.repo.execute, cnxid, 'State X') |
|
198 |
||
199 |
def test_user_group_synchronization(self): |
|
200 |
user = self.session.user |
|
201 |
self.assertEquals(user.groups, set(('managers',))) |
|
202 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
203 |
self.assertEquals(user.groups, set(('managers',))) |
|
204 |
self.commit() |
|
205 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
206 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
207 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
208 |
self.commit() |
|
209 |
self.assertEquals(user.groups, set(('managers',))) |
|
210 |
||
211 |
def test_user_composite_owner(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
212 |
ueid = self.create_user('toto').eid |
0 | 213 |
# composite of euser should be owned by the euser regardless of who created it |
214 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
215 |
'WHERE U login "toto"') |
|
216 |
self.commit() |
|
217 |
self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,' |
|
218 |
'U login "toto", X address A')[0][0], |
|
219 |
'toto@logilab.fr') |
|
220 |
||
221 |
def test_no_created_by_on_deleted_entity(self): |
|
222 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
223 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
224 |
self.commit() |
|
225 |
self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
|
1787 | 226 |
|
2746 | 227 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
228 |
class CWPropertyHooksTC(CubicWebTC): |
1787 | 229 |
|
0 | 230 |
def test_unexistant_eproperty(self): |
231 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
232 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
233 |
self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'}) |
0 | 234 |
ex = self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
235 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
236 |
self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'}) |
1787 | 237 |
|
0 | 238 |
def test_site_wide_eproperty(self): |
239 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
240 |
self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
241 |
self.assertEquals(ex.errors, {'for_user-subject': "site-wide property can't be set for user"}) |
1787 | 242 |
|
0 | 243 |
def test_bad_type_eproperty(self): |
244 |
ex = self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
245 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
246 |
self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'}) |
0 | 247 |
ex = self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
248 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
249 |
self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'}) |
1787 | 250 |
|
251 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
252 |
class SchemaHooksTC(CubicWebTC): |
1787 | 253 |
|
0 | 254 |
def test_duplicate_etype_error(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
255 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 256 |
# with the same name |
3431
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
257 |
self.assertRaises(ValidationError, |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
258 |
self.execute, 'INSERT CWEType X: X name "CWUser"') |
6944a92c16f2
move hooks test to the hooks package, update them to work with a minimal schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2968
diff
changeset
|
259 |
self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
260 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 261 |
|
0 | 262 |
def test_validation_unique_constraint(self): |
263 |
self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
264 |
self.execute, 'INSERT CWUser X: X login "admin"') |
0 | 265 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
266 |
self.execute('INSERT CWUser X: X login "admin"') |
0 | 267 |
except ValidationError, ex: |
268 |
self.assertIsInstance(ex.entity, int) |
|
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
269 |
self.assertEquals(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 270 |
|
271 |
||
272 |
if __name__ == '__main__': |
|
273 |
unittest_main() |