author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 17 Jan 2011 12:42:27 +0100 | |
branch | stable |
changeset 6834 | b4befa12bbcc |
parent 6798 | c3d5c0a215b7 |
child 6957 | ffda12be2e9f |
child 6965 | 343c79c3f04a |
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 |
""" |
|
6798
c3d5c0a215b7
missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
23 |
from __future__ import with_statement |
0 | 24 |
|
25 |
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
|
26 |
|
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
27 |
from datetime import datetime |
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
28 |
|
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
|
29 |
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
|
30 |
from cubicweb.devtools.testlib import CubicWebTC |
1787 | 31 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
32 |
class CoreHooksTC(CubicWebTC): |
1787 | 33 |
|
0 | 34 |
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
|
35 |
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
|
36 |
'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
|
37 |
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
|
38 |
'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
|
39 |
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
|
40 |
'DELETE CWGroup X WHERE X name "owners"') |
0 | 41 |
|
42 |
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
|
43 |
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
|
44 |
'WHERE Y name "users"') |
0 | 45 |
self.commit() |
46 |
self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"') |
|
47 |
self.assertRaises(ValidationError, self.commit) |
|
48 |
self.execute('DELETE X in_group Y WHERE X login "toto"') |
|
49 |
self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"') |
|
50 |
self.commit() |
|
1787 | 51 |
|
0 | 52 |
def test_delete_required_relations_object(self): |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
53 |
self.skipTest('no sample in the schema ! YAGNI ? Kermaat ?') |
1787 | 54 |
|
0 | 55 |
def test_static_vocabulary_check(self): |
56 |
self.assertRaises(ValidationError, |
|
57 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
58 |
'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"') |
1787 | 59 |
|
0 | 60 |
def test_missing_required_relations_subject_inline(self): |
1787 | 61 |
# 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
|
62 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop"') |
0 | 63 |
self.assertRaises(ValidationError, |
64 |
self.commit) |
|
65 |
||
66 |
def test_inlined(self): |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
67 |
self.assertEqual(self.repo.schema['sender'].inlined, True) |
0 | 68 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
69 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
70 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
71 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
72 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
73 |
rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
74 |
self.assertEqual(len(rset), 1) |
1787 | 75 |
|
0 | 76 |
def test_composite_1(self): |
77 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
78 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
79 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
80 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
81 |
self.failUnless(self.execute('Email X WHERE X sender Y')) |
|
82 |
self.commit() |
|
83 |
self.execute('DELETE Email X') |
|
84 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
85 |
self.assertEqual(len(rset), 1) |
0 | 86 |
self.commit() |
87 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
88 |
self.assertEqual(len(rset), 0) |
1787 | 89 |
|
0 | 90 |
def test_composite_2(self): |
91 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
92 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
93 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
94 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
95 |
self.commit() |
|
96 |
self.execute('DELETE Email X') |
|
97 |
self.execute('DELETE EmailPart X') |
|
98 |
self.commit() |
|
99 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
100 |
self.assertEqual(len(rset), 0) |
1787 | 101 |
|
0 | 102 |
def test_composite_redirection(self): |
103 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
104 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
105 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
106 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
107 |
self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y ' |
|
108 |
'WHERE Y is EmailAddress') |
|
109 |
self.commit() |
|
110 |
self.execute('DELETE X parts Y WHERE X messageid "<1234>"') |
|
111 |
self.execute('SET X parts Y WHERE X messageid "<2345>"') |
|
112 |
self.commit() |
|
113 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
114 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
115 |
self.assertEqual(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>') |
0 | 116 |
|
117 |
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
|
118 |
releid = self.execute('SET U in_group G WHERE G name "owners", U login "admin"')[0][0] |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
119 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
120 |
self.commit() |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
121 |
self.assertEqual(cm.exception.errors, |
5895
6a3f776292a5
[selectors]Â avoid spurious warning when using implements by design
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
122 |
{'in_group-object': u'RQLConstraint NOT O name "owners" failed'}) |
0 | 123 |
|
124 |
def test_html_tidy_hook(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
125 |
req = self.request() |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
126 |
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
|
127 |
description=u'yo') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
128 |
self.assertEqual(entity.description, u'yo') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
129 |
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
|
130 |
description=u'<b>yo') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
131 |
self.assertEqual(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
132 |
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
|
133 |
description=u'<b>yo</b>') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
134 |
self.assertEqual(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
135 |
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
|
136 |
description=u'<b>R&D</b>') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
137 |
self.assertEqual(entity.description, u'<b>R&D</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
138 |
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
|
139 |
description=u"<div>c'est <b>l'été") |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
140 |
self.assertEqual(entity.description, u"<div>c'est <b>l'été</b></div>") |
0 | 141 |
|
142 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
143 |
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
|
144 |
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(name=u'wf2') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
146 |
self.assertEqual(entity.description, u'yo') |
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
|
147 |
entity.set_attributes(description=u'R&D<p>yo') |
6142
8bc6eac1fac1
[session] cleanup hook / operation / entity edition api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
148 |
entity.cw_attr_cache.pop('description') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
149 |
self.assertEqual(entity.description, u'R&D<p>yo</p>') |
1787 | 150 |
|
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
151 |
def test_metadata_cwuri(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
152 |
entity = self.request().create_entity('Workflow', name=u'wf1') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
153 |
self.assertEqual(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
|
154 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
155 |
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
|
156 |
_now = datetime.now() |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
157 |
entity = self.request().create_entity('Workflow', name=u'wf1') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
158 |
self.assertEqual((entity.creation_date - _now).seconds, 0) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
159 |
self.assertEqual((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
|
160 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
161 |
def test_metadata_created_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
162 |
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
|
163 |
self.commit() # fire operations |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
164 |
self.assertEqual(len(entity.created_by), 1) # make sure we have only one creator |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
165 |
self.assertEqual(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
|
166 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
167 |
def test_metadata_owned_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
168 |
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
|
169 |
self.commit() # fire operations |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
170 |
self.assertEqual(len(entity.owned_by), 1) # make sure we have only one owner |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
171 |
self.assertEqual(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
|
172 |
|
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
173 |
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
|
174 |
u = self.create_user(' joe ') |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
175 |
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
|
176 |
{'e': u.eid})[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
177 |
self.assertEqual(tname, 'joe') |
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
{'e': u.eid})[0][0] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
181 |
self.assertEqual(tname, 'jijoe') |
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
182 |
|
0 | 183 |
|
184 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
185 |
class UserGroupHooksTC(CubicWebTC): |
1787 | 186 |
|
0 | 187 |
def test_user_synchronization(self): |
188 |
self.create_user('toto', password='hop', commit=False) |
|
189 |
self.assertRaises(AuthenticationError, |
|
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
190 |
self.repo.connect, u'toto', password='hop') |
0 | 191 |
self.commit() |
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 195 |
self.repo.execute(cnxid, 'State X') |
196 |
self.commit() |
|
197 |
self.assertRaises(BadConnectionId, |
|
198 |
self.repo.execute, cnxid, 'State X') |
|
199 |
||
200 |
def test_user_group_synchronization(self): |
|
201 |
user = self.session.user |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
202 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 203 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
204 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 205 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
206 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
0 | 207 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
208 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
0 | 209 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
210 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 211 |
|
212 |
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
|
213 |
ueid = self.create_user('toto').eid |
0 | 214 |
# composite of euser should be owned by the euser regardless of who created it |
215 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
216 |
'WHERE U login "toto"') |
|
217 |
self.commit() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
218 |
self.assertEqual(self.execute('Any A WHERE X owned_by U, U use_email X,' |
0 | 219 |
'U login "toto", X address A')[0][0], |
220 |
'toto@logilab.fr') |
|
221 |
||
222 |
def test_no_created_by_on_deleted_entity(self): |
|
223 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
224 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
225 |
self.commit() |
|
226 |
self.failIf(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
|
1787 | 227 |
|
2746 | 228 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
229 |
class CWPropertyHooksTC(CubicWebTC): |
1787 | 230 |
|
0 | 231 |
def test_unexistant_eproperty(self): |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
232 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
233 |
self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
234 |
self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'}) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
235 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
236 |
self.execute('INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
237 |
self.assertEqual(cm.exception.errors, {'pkey-subject': 'unknown property key bla.bla'}) |
1787 | 238 |
|
0 | 239 |
def test_site_wide_eproperty(self): |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
240 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
241 |
self.execute('INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
242 |
self.assertEqual(cm.exception.errors, {'for_user-subject': "site-wide property can't be set for user"}) |
1787 | 243 |
|
0 | 244 |
def test_bad_type_eproperty(self): |
6796
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
245 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
246 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
247 |
self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'}) |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
248 |
with self.assertRaises(ValidationError) as cm: |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
249 |
self.execute('INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
e70ca9abfc51
[unittest2] update to unittest2 assertRaises api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6638
diff
changeset
|
250 |
self.assertEqual(cm.exception.errors, {'value-subject': u'unauthorized value'}) |
1787 | 251 |
|
252 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
253 |
class SchemaHooksTC(CubicWebTC): |
1787 | 254 |
|
0 | 255 |
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
|
256 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 257 |
# 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
|
258 |
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
|
259 |
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
|
260 |
self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
261 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 262 |
|
0 | 263 |
def test_validation_unique_constraint(self): |
264 |
self.assertRaises(ValidationError, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
265 |
self.execute, 'INSERT CWUser X: X login "admin"') |
0 | 266 |
try: |
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 |
except ValidationError, ex: |
269 |
self.assertIsInstance(ex.entity, int) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5895
diff
changeset
|
270 |
self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 271 |
|
272 |
||
273 |
if __name__ == '__main__': |
|
274 |
unittest_main() |