author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 24 Feb 2010 10:56:47 +0100 | |
branch | stable |
changeset 4680 | 8a6bee838464 |
parent 4667 | 6c8eccb1b695 |
child 4689 | 4eb1f4490538 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""functional tests for core hooks |
|
3 |
||
4 |
note: most schemahooks.py hooks are actually tested in unittest_migrations.py |
|
1981
e6eed4324357
fix #327301: synchronize_schema doesn't update not-null constraint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1787
diff
changeset
|
5 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 6 |
""" |
7 |
||
8 |
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
|
9 |
|
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
10 |
from datetime import datetime |
3648b718a0d3
add simple tests for standard metadata hooks
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2453
diff
changeset
|
11 |
|
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
|
12 |
from cubicweb import (ConnectionError, ValidationError, AuthenticationError, |
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
|
13 |
BadConnectionId) |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
14 |
from cubicweb.devtools.testlib import CubicWebTC, get_versions |
0 | 15 |
|
1251
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
16 |
from cubicweb.server.sqlutils import SQL_PREFIX |
af40e615dc89
introduce a 'cw_' prefix on entity table and column names so we don't conflict with sql or DBMS specific keywords
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
17 |
from cubicweb.server.repository import Repository |
0 | 18 |
|
19 |
orig_get_versions = Repository.get_versions |
|
20 |
||
21 |
def setup_module(*args): |
|
22 |
Repository.get_versions = get_versions |
|
23 |
||
24 |
def teardown_module(*args): |
|
25 |
Repository.get_versions = orig_get_versions |
|
26 |
||
27 |
||
1787 | 28 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
29 |
class CoreHooksTC(CubicWebTC): |
1787 | 30 |
|
0 | 31 |
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
|
32 |
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
|
33 |
'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
|
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 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
|
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 CWGroup X WHERE X name "owners"') |
0 | 38 |
|
39 |
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
|
40 |
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
|
41 |
'WHERE Y name "users"') |
0 | 42 |
self.commit() |
43 |
self.execute('DELETE X in_group Y WHERE X login "toto", Y name "users"') |
|
44 |
self.assertRaises(ValidationError, self.commit) |
|
45 |
self.execute('DELETE X in_group Y WHERE X login "toto"') |
|
46 |
self.execute('SET X in_group Y WHERE X login "toto", Y name "guests"') |
|
47 |
self.commit() |
|
1787 | 48 |
|
0 | 49 |
def test_delete_required_relations_object(self): |
50 |
self.skip('no sample in the schema ! YAGNI ? Kermaat ?') |
|
1787 | 51 |
|
0 | 52 |
def test_static_vocabulary_check(self): |
53 |
self.assertRaises(ValidationError, |
|
54 |
self.execute, |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
55 |
'SET X composite "whatever" WHERE X from_entity FE, FE name "CWUser", X relation_type RT, RT name "in_group"') |
1787 | 56 |
|
0 | 57 |
def test_missing_required_relations_subject_inline(self): |
1787 | 58 |
# 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
|
59 |
self.execute('INSERT CWUser X: X login "toto", X upassword "hop"') |
0 | 60 |
self.assertRaises(ValidationError, |
61 |
self.commit) |
|
62 |
||
63 |
def test_inlined(self): |
|
64 |
self.assertEquals(self.repo.schema['sender'].inlined, True) |
|
65 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
66 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
67 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
68 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
69 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
70 |
rset = self.execute('Any S WHERE X sender S, X eid %s' % eeid) |
|
71 |
self.assertEquals(len(rset), 1) |
|
1787 | 72 |
|
0 | 73 |
def test_composite_1(self): |
74 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
75 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
76 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
77 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
78 |
self.failUnless(self.execute('Email X WHERE X sender Y')) |
|
79 |
self.commit() |
|
80 |
self.execute('DELETE Email X') |
|
81 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
82 |
self.assertEquals(len(rset), 1) |
|
83 |
self.commit() |
|
84 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
85 |
self.assertEquals(len(rset), 0) |
|
1787 | 86 |
|
0 | 87 |
def test_composite_2(self): |
88 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
89 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
90 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
91 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
92 |
self.commit() |
|
93 |
self.execute('DELETE Email X') |
|
94 |
self.execute('DELETE EmailPart X') |
|
95 |
self.commit() |
|
96 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
97 |
self.assertEquals(len(rset), 0) |
|
1787 | 98 |
|
0 | 99 |
def test_composite_redirection(self): |
100 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
|
101 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
102 |
self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
103 |
'WHERE Y is EmailAddress, P is EmailPart') |
|
104 |
self.execute('INSERT Email X: X messageid "<2345>", X subject "test2", X sender Y, X recipients Y ' |
|
105 |
'WHERE Y is EmailAddress') |
|
106 |
self.commit() |
|
107 |
self.execute('DELETE X parts Y WHERE X messageid "<1234>"') |
|
108 |
self.execute('SET X parts Y WHERE X messageid "<2345>"') |
|
109 |
self.commit() |
|
110 |
rset = self.execute('Any X WHERE X is EmailPart') |
|
111 |
self.assertEquals(len(rset), 1) |
|
112 |
self.assertEquals(rset.get_entity(0, 0).reverse_parts[0].messageid, '<2345>') |
|
113 |
||
114 |
def test_unsatisfied_constraints(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
115 |
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
|
116 |
'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
|
117 |
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
|
118 |
{'x': releid}, 'x') |
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
|
119 |
ex = 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
|
120 |
self.commit) |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
121 |
self.assertEquals(ex.errors, {'to_entity': 'RQLConstraint O final FALSE failed'}) |
0 | 122 |
|
123 |
def test_html_tidy_hook(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
124 |
req = self.request() |
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
125 |
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
|
126 |
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
|
127 |
self.assertEquals(entity.description, u'yo') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
self.assertEquals(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
self.assertEquals(entity.description, u'<b>yo</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
134 |
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
|
135 |
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
|
136 |
self.assertEquals(entity.description, u'<b>R&D</b>') |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
self.assertEquals(entity.description, u"<div>c'est <b>l'été</b></div>") |
0 | 140 |
|
141 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
142 |
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
|
143 |
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
|
144 |
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
|
145 |
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
|
146 |
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
|
147 |
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
|
148 |
self.assertEquals(entity.description, u'R&D<p>yo</p>') |
1787 | 149 |
|
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') |
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
|
153 |
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
|
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') |
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
|
158 |
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
|
159 |
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
|
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 |
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
|
164 |
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
|
165 |
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
|
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 |
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
|
170 |
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
|
171 |
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
|
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] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
177 |
self.assertEquals(tname, 'joe') |
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] |
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
181 |
self.assertEquals(tname, 'jijoe') |
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 |
|
202 |
self.assertEquals(user.groups, set(('managers',))) |
|
203 |
self.execute('SET X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
204 |
self.assertEquals(user.groups, set(('managers',))) |
|
205 |
self.commit() |
|
206 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
207 |
self.execute('DELETE X in_group G WHERE X eid %s, G name "guests"' % user.eid) |
|
208 |
self.assertEquals(user.groups, set(('managers', 'guests'))) |
|
209 |
self.commit() |
|
210 |
self.assertEquals(user.groups, set(('managers',))) |
|
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() |
|
218 |
self.assertEquals(self.execute('Any A WHERE X owned_by U, U use_email X,' |
|
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): |
232 |
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
|
233 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop", X for_user U') |
0 | 234 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
235 |
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
|
236 |
self.execute, 'INSERT CWProperty X: X pkey "bla.bla", X value "hop"') |
0 | 237 |
self.assertEquals(ex.errors, {'pkey': 'unknown property key'}) |
1787 | 238 |
|
0 | 239 |
def test_site_wide_eproperty(self): |
240 |
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
|
241 |
self.execute, 'INSERT CWProperty X: X pkey "ui.site-title", X value "hop", X for_user U') |
0 | 242 |
self.assertEquals(ex.errors, {'for_user': "site-wide property can't be set for user"}) |
1787 | 243 |
|
0 | 244 |
def test_bad_type_eproperty(self): |
245 |
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
|
246 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop", X for_user U') |
0 | 247 |
self.assertEquals(ex.errors, {'value': u'unauthorized value'}) |
248 |
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
|
249 |
self.execute, 'INSERT CWProperty X: X pkey "ui.language", X value "hop"') |
0 | 250 |
self.assertEquals(ex.errors, {'value': 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) |
|
270 |
self.assertEquals(ex.errors, {'login': 'the value "admin" is already used, use another one'}) |
|
271 |
||
272 |
||
273 |
if __name__ == '__main__': |
|
274 |
unittest_main() |