author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 14 Feb 2013 15:29:20 +0100 | |
changeset 8693 | a6ca96ec8693 |
parent 8594 | 001159e2e4f3 |
child 8694 | d901c36bcfce |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
8495
0bc63e46bdb5
[test] remove no more necessary attribute cache manipulation to repair test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8483
diff
changeset
|
2 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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
|
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 |
||
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6798
diff
changeset
|
21 |
Note: |
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6798
diff
changeset
|
22 |
syncschema.py hooks are mostly tested in server/test/unittest_migrations.py |
0 | 23 |
""" |
6798
c3d5c0a215b7
missing future import
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6796
diff
changeset
|
24 |
from __future__ import with_statement |
0 | 25 |
|
2454
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_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
|
34 |
self.assertEqual(self.repo.schema['sender'].inlined, True) |
0 | 35 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", X alias "hop"') |
36 |
self.execute('INSERT EmailPart X: X content_format "text/plain", X ordernum 1, X content "this is a test"') |
|
37 |
eeid = self.execute('INSERT Email X: X messageid "<1234>", X subject "test", X sender Y, X recipients Y, X parts P ' |
|
38 |
'WHERE Y is EmailAddress, P is EmailPart')[0][0] |
|
39 |
self.execute('SET X sender Y WHERE X is Email, Y is EmailAddress') |
|
40 |
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
|
41 |
self.assertEqual(len(rset), 1) |
1787 | 42 |
|
0 | 43 |
def test_html_tidy_hook(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
44 |
req = self.request() |
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
45 |
entity = req.create_entity('Workflow', name=u'wf1', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
46 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
47 |
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
|
48 |
self.assertEqual(entity.description, u'yo') |
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
49 |
entity = req.create_entity('Workflow', name=u'wf2', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
50 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
51 |
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
|
52 |
self.assertEqual(entity.description, u'<b>yo</b>') |
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
53 |
entity = req.create_entity('Workflow', name=u'wf3', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
54 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
55 |
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
|
56 |
self.assertEqual(entity.description, u'<b>yo</b>') |
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
57 |
entity = req.create_entity('Workflow', name=u'wf4', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
58 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
59 |
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
|
60 |
self.assertEqual(entity.description, u'<b>R&D</b>') |
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
61 |
entity = req.create_entity('Workflow', name=u'wf5', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
62 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
63 |
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
|
64 |
self.assertEqual(entity.description, u"<div>c'est <b>l'été</b></div>") |
0 | 65 |
|
66 |
def test_nonregr_html_tidy_hook_no_update(self): |
|
7245
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
67 |
entity = self.request().create_entity('Workflow', name=u'wf1', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
68 |
description_format=u'text/html', |
2f72b958ae22
small reformatting (but test still fails)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7244
diff
changeset
|
69 |
description=u'yo') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
70 |
entity.cw_set(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
|
71 |
self.assertEqual(entity.description, u'yo') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
72 |
entity.cw_set(description=u'R&D<p>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
|
73 |
self.assertEqual(entity.description, u'R&D<p>yo</p>') |
1787 | 74 |
|
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
75 |
def test_metadata_cwuri(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
76 |
entity = self.request().create_entity('Workflow', name=u'wf1') |
6965
343c79c3f04a
[test] update cwuri test
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6798
diff
changeset
|
77 |
self.assertEqual(entity.cwuri, self.repo.config['base-url'] + str(entity.eid)) |
2921
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
78 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
79 |
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
|
80 |
_now = datetime.now() |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
85 |
def test_metadata_created_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
|
8e2544e78a5e
test and fix rset returned by SET query
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
91 |
def test_metadata_owned_by(self): |
4055
03443dfb6fa4
test update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4051
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
97 |
def test_user_login_stripped(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
98 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
99 |
u = self.create_user(req, ' joe ') |
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
100 |
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
|
101 |
{'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
|
102 |
self.assertEqual(tname, 'joe') |
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
{'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
|
106 |
self.assertEqual(tname, 'jijoe') |
4051
eec34250a645
move hook tests to hooks package tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3536
diff
changeset
|
107 |
|
0 | 108 |
|
109 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
110 |
class UserGroupHooksTC(CubicWebTC): |
1787 | 111 |
|
0 | 112 |
def test_user_synchronization(self): |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
113 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
114 |
self.create_user(req, 'toto', password='hop', commit=False) |
0 | 115 |
self.assertRaises(AuthenticationError, |
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
116 |
self.repo.connect, u'toto', password='hop') |
0 | 117 |
self.commit() |
4067
c49fba955a9c
password should now be named
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4055
diff
changeset
|
118 |
cnxid = self.repo.connect(u'toto', password='hop') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7245
diff
changeset
|
119 |
self.assertNotEqual(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
|
120 |
self.execute('DELETE CWUser X WHERE X login "toto"') |
0 | 121 |
self.repo.execute(cnxid, 'State X') |
122 |
self.commit() |
|
123 |
self.assertRaises(BadConnectionId, |
|
124 |
self.repo.execute, cnxid, 'State X') |
|
125 |
||
126 |
def test_user_group_synchronization(self): |
|
127 |
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
|
128 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 129 |
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
|
130 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 131 |
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
|
132 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
0 | 133 |
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
|
134 |
self.assertEqual(user.groups, set(('managers', 'guests'))) |
0 | 135 |
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
|
136 |
self.assertEqual(user.groups, set(('managers',))) |
0 | 137 |
|
138 |
def test_user_composite_owner(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
139 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7192
diff
changeset
|
140 |
ueid = self.create_user(req, 'toto').eid |
0 | 141 |
# composite of euser should be owned by the euser regardless of who created it |
142 |
self.execute('INSERT EmailAddress X: X address "toto@logilab.fr", U use_email X ' |
|
143 |
'WHERE U login "toto"') |
|
144 |
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
|
145 |
self.assertEqual(self.execute('Any A WHERE X owned_by U, U use_email X,' |
0 | 146 |
'U login "toto", X address A')[0][0], |
147 |
'toto@logilab.fr') |
|
148 |
||
149 |
def test_no_created_by_on_deleted_entity(self): |
|
150 |
eid = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"')[0][0] |
|
151 |
self.execute('DELETE EmailAddress X WHERE X eid %s' % eid) |
|
152 |
self.commit() |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7245
diff
changeset
|
153 |
self.assertFalse(self.execute('Any X WHERE X created_by Y, X eid >= %(x)s', {'x': eid})) |
1787 | 154 |
|
2746 | 155 |
|
1787 | 156 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2746
diff
changeset
|
157 |
class SchemaHooksTC(CubicWebTC): |
1787 | 158 |
|
0 | 159 |
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
|
160 |
# check we can't add a CWEType or CWRType entity if it already exists one |
0 | 161 |
# 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
|
162 |
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
|
163 |
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
|
164 |
self.assertRaises(ValidationError, |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
165 |
self.execute, 'INSERT CWRType X: X name "in_group"') |
1787 | 166 |
|
0 | 167 |
def test_validation_unique_constraint(self): |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
168 |
with self.assertRaises(ValidationError) as cm: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1251
diff
changeset
|
169 |
self.execute('INSERT CWUser X: X login "admin"') |
8594
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
170 |
ex = cm.exception |
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
171 |
ex.translate(unicode) |
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
172 |
self.assertIsInstance(ex.entity, int) |
001159e2e4f3
[validation api] properly use yams 0.36 validation error api and update message catalog. Follows bbe0d6985e59
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8556
diff
changeset
|
173 |
self.assertEqual(ex.errors, {'login-subject': 'the value "admin" is already used, use another one'}) |
0 | 174 |
|
175 |
||
176 |
if __name__ == '__main__': |
|
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6798
diff
changeset
|
177 |
from logilab.common.testlib import unittest_main |
0 | 178 |
unittest_main() |