author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 15 Jul 2010 11:38:31 +0200 | |
branch | stable |
changeset 5975 | 5120d97e2f7e |
parent 5424 | 8ecbcbff9777 |
child 5895 | 6a3f776292a5 |
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): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
117 |
releid = self.execute('INSERT CWRelation X: X from_entity FE, X relation_type RT, X to_entity TE ' |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
118 |
'WHERE FE name "CWUser", RT name "in_group", TE name "String"')[0][0] |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
119 |
self.execute('SET X read_permission Y WHERE X eid %(x)s, Y name "managers"', |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
120 |
{'x': releid}, 'x') |
5030
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
121 |
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
|
122 |
self.assertEquals(ex.errors, |
5238d9a8dfee
[form] put qualified name on validation error, should fix #784299
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4689
diff
changeset
|
123 |
{'to_entity-object': 'RQLConstraint O final FALSE failed'}) |
0 | 124 |
|
125 |
def test_html_tidy_hook(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
126 |
req = self.request() |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
127 |
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
|
128 |
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
|
129 |
self.assertEquals(entity.description, u'yo') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
130 |
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
|
131 |
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
|
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'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
|
134 |
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
|
135 |
self.assertEquals(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
self.assertEquals(entity.description, u'<b>R&D</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
139 |
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
|
140 |
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
|
141 |
self.assertEquals(entity.description, u"<div>c'est <b>l'été</b></div>") |
0 | 142 |
|
143 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
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
|
149 |
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
|
150 |
self.assertEquals(entity.description, u'R&D<p>yo</p>') |
1787 | 151 |
|
152 |
||
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
153 |
def test_metadata_cwuri(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
157 |
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
|
158 |
_now = datetime.now() |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
163 |
def test_metadata_created_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
169 |
def test_metadata_owned_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
|
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
175 |
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
|
176 |
u = self.create_user(' joe ') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
177 |
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
|
178 |
{'e': u.eid})[0][0] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
179 |
self.assertEquals(tname, 'joe') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
{'e': u.eid})[0][0] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
183 |
self.assertEquals(tname, 'jijoe') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
184 |
|
0 | 185 |
|
186 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
187 |
class UserGroupHooksTC(CubicWebTC): |
1787 | 188 |
|
0 | 189 |
def test_user_synchronization(self): |
190 |
self.create_user('toto', password='hop', commit=False) |
|
191 |
self.assertRaises(AuthenticationError, |
|
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
192 |
self.repo.connect, u'toto', password='hop') |
0 | 193 |
self.commit() |
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 197 |
self.repo.execute(cnxid, 'State X') |
198 |
self.commit() |
|
199 |
self.assertRaises(BadConnectionId, |
|
200 |
self.repo.execute, cnxid, 'State X') |
|
201 |
||
202 |
def test_user_group_synchronization(self): |
|
203 |
user = self.session.user |
|
204 |
self.assertEquals(user.groups, set(('managers',))) |
|
205 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
206 |
self.assertEquals(user.groups, set(('managers',))) |
|
207 |
self.commit() |
|
208 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
209 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
210 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
211 |
self.commit() |
|
212 |
self.assertEquals(user.groups, set(('managers',))) |
|
213 |
||
214 |
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
|
215 |
ueid = self.create_user('toto').eid |
0 | 216 |
# composite of euser should be owned by the euser regardless of who created it |
217 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
218 |
'WHERE U login "toto"') |
|
219 |
self.commit() |
|
220 |
self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,' |
|
221 |
'U login "toto", X address A')[0][0], |
|
222 |
'toto@logilab.fr') |
|
223 |
||
224 |
def test_no_created_by_on_deleted_entity(self): |
|
225 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
226 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
227 |
self.commit() |
|
228 |
self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
|
1787 | 229 |
|
2746 | 230 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
231 |
class CWPropertyHooksTC(CubicWebTC): |
1787 | 232 |
|
0 | 233 |
def test_unexistant_eproperty(self): |
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", 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
|
236 |
self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'}) |
0 | 237 |
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
|
238 |
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
|
239 |
self.assertEquals(ex.errors, {'pkey-subject': 'unknown property key'}) |
1787 | 240 |
|
0 | 241 |
def test_site_wide_eproperty(self): |
242 |
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
|
243 |
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
|
244 |
self.assertEquals(ex.errors, {'for_user-subject': "site-wide property can't be set for user"}) |
1787 | 245 |
|
0 | 246 |
def test_bad_type_eproperty(self): |
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", 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
|
249 |
self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'}) |
0 | 250 |
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
|
251 |
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
|
252 |
self.assertEquals(ex.errors, {'value-subject': u'unauthorized value'}) |
1787 | 253 |
|
254 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
255 |
class SchemaHooksTC(CubicWebTC): |
1787 | 256 |
|
0 | 257 |
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
|
258 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 259 |
# 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
|
260 |
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
|
261 |
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
|
262 |
self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
263 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 264 |
|
0 | 265 |
def test_validation_unique_constraint(self): |
266 |
self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
267 |
self.execute, 'INSERT CWUser X: X login "admin"') |
0 | 268 |
try: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
269 |
self.execute('INSERT CWUser X: X login "admin"') |
0 | 270 |
except ValidationError, ex: |
271 |
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
|
272 |
self.assertEquals(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 273 |
|
274 |
||
275 |
if __name__ == '__main__': |
|
276 |
unittest_main() |