author | sylvain.thenault@logilab.fr |
Fri, 17 Apr 2009 16:55:37 +0200 | |
branch | tls-sprint |
changeset 1398 | 5fe84a5f7035 |
parent 1122 | 9f37de24251f |
child 1802 | d628defebc17 |
permissions | -rw-r--r-- |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
1 |
"""cubicweb.server.sources.ldapusers unit and functional tests""" |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
2 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
3 |
from logilab.common.testlib import TestCase, unittest_main, mock_object |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
4 |
from cubicweb.devtools import init_test_database, TestServerConfiguration |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
5 |
from cubicweb.devtools.apptest import RepositoryBasedTC |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
6 |
from cubicweb.devtools.repotest import RQLGeneratorTC |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
7 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
8 |
from cubicweb.server.sources.ldapuser import * |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
9 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
10 |
def nopwd_authenticate(self, session, login, upassword): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
11 |
"""used to monkey patch the source to get successful authentication without |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
12 |
upassword checking |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
13 |
""" |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
14 |
assert login, 'no login!' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
15 |
searchfilter = [filter_format('(%s=%s)', (self.user_login_attr, login))] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
16 |
searchfilter.extend([filter_format('(%s=%s)', ('objectClass', o)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
17 |
for o in self.user_classes]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
18 |
searchstr = '(&%s)' % ''.join(searchfilter) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
19 |
# first search the user |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
20 |
try: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
21 |
user = self._search(session, self.user_base_dn, self.user_base_scope, |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
22 |
searchstr)[0] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
23 |
except IndexError: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
24 |
# no such user |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
25 |
raise AuthenticationError() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
26 |
# don't check upassword ! |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
27 |
return self.extid2eid(user['dn'], 'CWUser', session) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
28 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
29 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
30 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
31 |
config = TestServerConfiguration('data') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
32 |
config.sources_file = lambda : 'data/sourcesldap' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
33 |
repo, cnx = init_test_database('sqlite', config=config) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
34 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
35 |
class LDAPUserSourceTC(RepositoryBasedTC): |
975
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
36 |
repo, cnx = repo, cnx |
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
37 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
38 |
def patch_authenticate(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
39 |
self._orig_authenticate = LDAPUserSource.authenticate |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
40 |
LDAPUserSource.authenticate = nopwd_authenticate |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
41 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
42 |
def setUp(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
43 |
self._prepare() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
44 |
# XXX: need this first query else we get 'database is locked' from |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
45 |
# sqlite since it doesn't support multiple connections on the same |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
46 |
# database |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
47 |
# so doing, ldap inserted users don't get removed between each test |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
48 |
rset = self.execute('CWUser X') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
49 |
self.commit() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
50 |
# check we get some users from ldap |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
51 |
self.assert_(len(rset) > 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
52 |
self.maxeid = self.execute('Any MAX(X)')[0][0] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
53 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
54 |
def tearDown(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
55 |
if hasattr(self, '_orig_authenticate'): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
56 |
LDAPUserSource.authenticate = self._orig_authenticate |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
57 |
RepositoryBasedTC.tearDown(self) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
58 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
def test_authenticate(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
60 |
source = self.repo.sources_by_uri['ldapuser'] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
61 |
self.assertRaises(AuthenticationError, |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
62 |
source.authenticate, self.session, 'toto', 'toto') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
63 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
64 |
def test_synchronize(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
65 |
source = self.repo.sources_by_uri['ldapuser'] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
66 |
source.synchronize() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
67 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
68 |
def test_base(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
69 |
# check a known one |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
70 |
e = self.execute('CWUser X WHERE X login "syt"').get_entity(0, 0) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
71 |
self.assertEquals(e.login, 'syt') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
72 |
e.complete() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
73 |
self.assertEquals(e.creation_date, None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
74 |
self.assertEquals(e.modification_date, None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
75 |
self.assertEquals(e.firstname, None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
76 |
self.assertEquals(e.surname, None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
77 |
self.assertEquals(e.in_group[0].name, 'users') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
78 |
self.assertEquals(e.owned_by[0].login, 'syt') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
79 |
self.assertEquals(e.created_by, []) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
80 |
self.assertEquals(e.primary_email[0].address, 'Sylvain Thenault') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
81 |
# email content should be indexed on the user |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
82 |
rset = self.execute('CWUser X WHERE X has_text "thenault"') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
83 |
self.assertEquals(rset.rows, [[e.eid]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
84 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
85 |
def test_not(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
86 |
eid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
87 |
rset = self.execute('CWUser X WHERE NOT X eid %s' % eid) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
88 |
self.assert_(rset) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
89 |
self.assert_(not eid in (r[0] for r in rset)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
90 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
91 |
def test_multiple(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
92 |
seid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
93 |
aeid = self.execute('CWUser X WHERE X login "adim"')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
94 |
rset = self.execute('CWUser X, Y WHERE X login "syt", Y login "adim"') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
95 |
self.assertEquals(rset.rows, [[seid, aeid]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
96 |
rset = self.execute('Any X,Y,L WHERE X login L, X login "syt", Y login "adim"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
97 |
self.assertEquals(rset.rows, [[seid, aeid, 'syt']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
98 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
99 |
def test_in(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
100 |
seid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
101 |
aeid = self.execute('CWUser X WHERE X login "adim"')[0][0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
102 |
rset = self.execute('Any X,L ORDERBY L WHERE X login IN("syt", "adim"), X login L') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
self.assertEquals(rset.rows, [[aeid, 'adim'], [seid, 'syt']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
104 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
105 |
def test_relations(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
106 |
eid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
107 |
rset = self.execute('Any X,E WHERE X is CWUser, X login L, X primary_email E') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
108 |
self.assert_(eid in (r[0] for r in rset)) |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
109 |
rset = self.execute('Any X,L,E WHERE X is CWUser, X login L, X primary_email E') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
110 |
self.assert_('syt' in (r[1] for r in rset)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
111 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
112 |
def test_count(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
113 |
nbusers = self.execute('Any COUNT(X) WHERE X is CWUser')[0][0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
114 |
# just check this is a possible number |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
115 |
self.assert_(nbusers > 1, nbusers) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
116 |
self.assert_(nbusers < 30, nbusers) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
117 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
118 |
def test_upper(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
119 |
eid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
120 |
rset = self.execute('Any UPPER(L) WHERE X eid %s, X login L' % eid) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
121 |
self.assertEquals(rset[0][0], 'SYT') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
122 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
123 |
def test_unknown_attr(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
124 |
eid = self.execute('CWUser X WHERE X login "syt"')[0][0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
125 |
rset = self.execute('Any L,C,M WHERE X eid %s, X login L, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
126 |
'X creation_date C, X modification_date M' % eid) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
127 |
self.assertEquals(rset[0][0], 'syt') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
128 |
self.assertEquals(rset[0][1], None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
self.assertEquals(rset[0][2], None) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
130 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
131 |
def test_sort(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
logins = [l for l, in self.execute('Any L ORDERBY L WHERE X login L')] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
self.assertEquals(logins, sorted(logins)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
def test_lower_sort(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
logins = [l for l, in self.execute('Any L ORDERBY lower(L) WHERE X login L')] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
137 |
self.assertEquals(logins, sorted(logins)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
138 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
def test_or(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
140 |
rset = self.execute('DISTINCT Any X WHERE X login "syt" OR (X in_group G, G name "managers")') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
141 |
self.assertEquals(len(rset), 2, rset.rows) # syt + admin |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
142 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
143 |
def test_nonregr_set_owned_by(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
144 |
# test that when a user coming from ldap is triggering a transition |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
145 |
# the related TrInfo has correct owner information |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
146 |
self.execute('SET X in_group G WHERE X login "syt", G name "managers"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
self.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
148 |
syt = self.execute('CWUser X WHERE X login "syt"').get_entity(0, 0) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
149 |
self.assertEquals([g.name for g in syt.in_group], ['managers', 'users']) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
self.patch_authenticate() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
151 |
cnx = self.login('syt', 'dummypassword') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
152 |
cu = cnx.cursor() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
153 |
cu.execute('SET X in_state S WHERE X login "alf", S name "deactivated"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
154 |
try: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
155 |
cnx.commit() |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
156 |
alf = self.execute('CWUser X WHERE X login "alf"').get_entity(0, 0) |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
157 |
self.assertEquals(alf.in_state[0].name, 'deactivated') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
158 |
trinfo = alf.latest_trinfo() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
159 |
self.assertEquals(trinfo.owned_by[0].login, 'syt') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
160 |
# select from_state to skip the user's creation TrInfo |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
161 |
rset = self.execute('Any U ORDERBY D DESC WHERE WF wf_info_for X,' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
162 |
'WF creation_date D, WF from_state FS,' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
163 |
'WF owned_by U?, X eid %(x)s', |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
{'x': alf.eid}, 'x') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
165 |
self.assertEquals(rset.rows, [[syt.eid]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
166 |
finally: |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
167 |
# restore db state |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
168 |
self.restore_connection() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
169 |
self.execute('SET X in_state S WHERE X login "alf", S name "activated"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
170 |
self.execute('DELETE X in_group G WHERE X login "syt", G name "managers"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
171 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
172 |
def test_same_column_names(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
173 |
self.execute('Any X, Y WHERE X copain Y, X login "comme", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
174 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
def test_multiple_entities_from_different_sources(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
176 |
self.create_user('cochon') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
177 |
self.failUnless(self.execute('Any X,Y WHERE X login "syt", Y login "cochon"')) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
178 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
179 |
def test_exists1(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
180 |
self.add_entity('CWGroup', name=u'bougloup1') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
181 |
self.add_entity('CWGroup', name=u'bougloup2') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
182 |
self.execute('SET U in_group G WHERE G name ~= "bougloup%", U login "admin"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
183 |
self.execute('SET U in_group G WHERE G name = "bougloup1", U login "syt"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
184 |
rset = self.execute('Any L,SN ORDERBY L WHERE X in_state S, S name SN, X login L, EXISTS(X in_group G, G name ~= "bougloup%")') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
185 |
self.assertEquals(rset.rows, [['admin', 'activated'], ['syt', 'activated']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
186 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
187 |
def test_exists2(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
188 |
self.create_user('comme') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
189 |
self.create_user('cochon') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
190 |
self.execute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
191 |
rset = self.execute('Any GN ORDERBY GN WHERE X in_group G, G name GN, (G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon")))') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
192 |
self.assertEquals(rset.rows, [['managers'], ['users']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
193 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
194 |
def test_exists3(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
195 |
self.create_user('comme') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
196 |
self.create_user('cochon') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
197 |
self.execute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
198 |
self.failUnless(self.execute('Any X, Y WHERE X copain Y, X login "comme", Y login "cochon"')) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
199 |
self.execute('SET X copain Y WHERE X login "syt", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
200 |
self.failUnless(self.execute('Any X, Y WHERE X copain Y, X login "syt", Y login "cochon"')) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
201 |
rset = self.execute('Any GN,L WHERE X in_group G, X login L, G name GN, G name "managers" OR EXISTS(X copain T, T login in ("comme", "cochon"))') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
202 |
self.assertEquals(sorted(rset.rows), [['managers', 'admin'], ['users', 'comme'], ['users', 'syt']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
203 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
204 |
def test_exists4(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
205 |
self.create_user('comme') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
206 |
self.create_user('cochon', groups=('users', 'guests')) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
207 |
self.create_user('billy') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
208 |
self.execute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
209 |
self.execute('SET X copain Y WHERE X login "cochon", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
210 |
self.execute('SET X copain Y WHERE X login "comme", Y login "billy"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
211 |
self.execute('SET X copain Y WHERE X login "syt", Y login "billy"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
212 |
# search for group name, login where |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
213 |
# CWUser copain with "comme" or "cochon" AND same login as the copain |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
214 |
# OR |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
215 |
# CWUser in_state activated AND not copain with billy |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
216 |
# |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
217 |
# SO we expect everybody but "comme" and "syt" |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
218 |
rset= self.execute('Any GN,L WHERE X in_group G, X login L, G name GN, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
219 |
'EXISTS(X copain T, T login L, T login in ("comme", "cochon")) OR ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
220 |
'EXISTS(X in_state S, S name "activated", NOT X copain T2, T2 login "billy")') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
221 |
all = self.execute('Any GN, L WHERE X in_group G, X login L, G name GN') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
222 |
all.rows.remove(['users', 'comme']) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
223 |
all.rows.remove(['users', 'syt']) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
224 |
self.assertEquals(sorted(rset.rows), sorted(all.rows)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
225 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
226 |
def test_exists5(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
227 |
self.create_user('comme') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
228 |
self.create_user('cochon', groups=('users', 'guests')) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
229 |
self.create_user('billy') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
230 |
self.execute('SET X copain Y WHERE X login "comme", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
231 |
self.execute('SET X copain Y WHERE X login "cochon", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
232 |
self.execute('SET X copain Y WHERE X login "comme", Y login "billy"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
233 |
self.execute('SET X copain Y WHERE X login "syt", Y login "cochon"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
234 |
rset= self.execute('Any L WHERE X login L, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
235 |
'EXISTS(X copain T, T login in ("comme", "cochon")) AND ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
236 |
'NOT EXISTS(X copain T2, T2 login "billy")') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
237 |
self.assertEquals(sorted(rset.rows), [['cochon'], ['syt']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
238 |
rset= self.execute('Any GN,L WHERE X in_group G, X login L, G name GN, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
239 |
'EXISTS(X copain T, T login in ("comme", "cochon")) AND ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
240 |
'NOT EXISTS(X copain T2, T2 login "billy")') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
241 |
self.assertEquals(sorted(rset.rows), [['guests', 'cochon'], |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
242 |
['users', 'cochon'], |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
243 |
['users', 'syt']]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
244 |
|
975
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
245 |
def test_cd_restriction(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
246 |
rset = self.execute('CWUser X WHERE X creation_date > "2009-02-01"') |
975
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
247 |
self.assertEquals(len(rset), 2) # admin/anon but no ldap user since it doesn't support creation_date |
0928daea04e9
fix ldapsource w/ restriction on unsupported relation (return no results in that case)
sylvain.thenault@logilab.fr
parents:
360
diff
changeset
|
248 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
249 |
def test_union(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
250 |
afeids = self.execute('State X') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
251 |
ueids = self.execute('CWUser X') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
252 |
rset = self.execute('(Any X WHERE X is State) UNION (Any X WHERE X is CWUser)') |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
253 |
self.assertEquals(sorted(r[0] for r in rset.rows), |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
254 |
sorted(r[0] for r in afeids + ueids)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
255 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
256 |
def _init_security_test(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
257 |
self.create_user('iaminguestsgrouponly', groups=('guests',)) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
258 |
cnx = self.login('iaminguestsgrouponly') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
259 |
return cnx.cursor() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
260 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
261 |
def test_security1(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
262 |
cu = self._init_security_test() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
263 |
rset = cu.execute('Any X WHERE X login "syt"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
264 |
self.assertEquals(rset.rows, []) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
265 |
rset = cu.execute('Any X WHERE X login "iaminguestsgrouponly"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
266 |
self.assertEquals(len(rset.rows), 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
267 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
268 |
def test_security2(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
269 |
cu = self._init_security_test() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
270 |
rset = cu.execute('Any X WHERE X has_text "syt"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
271 |
self.assertEquals(rset.rows, []) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
272 |
rset = cu.execute('Any X WHERE X has_text "iaminguestsgrouponly"') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
273 |
self.assertEquals(len(rset.rows), 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
274 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
275 |
def test_security3(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
276 |
cu = self._init_security_test() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
277 |
rset = cu.execute('Any F WHERE X has_text "syt", X firstname F') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
278 |
self.assertEquals(rset.rows, []) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
279 |
rset = cu.execute('Any F WHERE X has_text "iaminguestsgrouponly", X firstname F') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
280 |
self.assertEquals(rset.rows, [[None]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
281 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
282 |
def test_nonregr1(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
283 |
self.execute('Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, E owned_by X, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
284 |
'X modification_date AA', |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
285 |
{'x': cnx.user(self.session).eid}) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
286 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
287 |
def test_nonregr2(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
288 |
self.execute('Any X,L,AA WHERE E eid %(x)s, E owned_by X, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
289 |
'X login L, X modification_date AA', |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
290 |
{'x': cnx.user(self.session).eid}) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
291 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
292 |
def test_nonregr3(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
293 |
self.execute('Any X,AA ORDERBY AA DESC WHERE E eid %(x)s, ' |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
294 |
'X modification_date AA', |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
295 |
{'x': cnx.user(self.session).eid}) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
296 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
297 |
def test_nonregr4(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
298 |
emaileid = self.execute('INSERT EmailAddress X: X address "toto@logilab.org"')[0][0] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
299 |
self.execute('Any X,AA WHERE X use_email Y, Y eid %(x)s, X modification_date AA', |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
300 |
{'x': emaileid}) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
301 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
302 |
def test_nonregr5(self): |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
303 |
# original jpl query: |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
304 |
# Any X, NOW - CD, P WHERE P is Project, U interested_in P, U is CWUser, U login "sthenault", X concerns P, X creation_date CD ORDERBY CD DESC LIMIT 5 |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
305 |
rql = 'Any X, NOW - CD, P ORDERBY CD DESC LIMIT 5 WHERE P bookmarked_by U, U login "%s", P is X, X creation_date CD' % self.session.user.login |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
306 |
self.execute(rql, )#{'x': }) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
307 |
|
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
308 |
def test_nonregr6(self): |
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
309 |
self.execute('Any B,U,UL GROUPBY B,U,UL WHERE B created_by U?, B is File ' |
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
310 |
'WITH U,UL BEING (Any U,UL WHERE ME eid %(x)s, (EXISTS(U identity ME) ' |
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
311 |
'OR (EXISTS(U in_group G, G name IN("managers", "staff")))) ' |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
312 |
'OR (EXISTS(U in_group H, ME in_group H, NOT H name "users")), U login UL, U is CWUser)', |
1122
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
313 |
{'x': self.session.user.eid}) |
9f37de24251f
fix rql2sq w/ outer join on subquery result
sylvain.thenault@logilab.fr
parents:
975
diff
changeset
|
314 |
|
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
315 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
316 |
class GlobTrFuncTC(TestCase): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
317 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
318 |
def test_count(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
319 |
trfunc = GlobTrFunc('count', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
320 |
res = trfunc.apply([[1], [2], [3], [4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
321 |
self.assertEquals(res, [[4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
322 |
trfunc = GlobTrFunc('count', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
323 |
res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
324 |
self.assertEquals(res, [[1, 2], [2, 1], [3, 1]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
325 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
326 |
def test_sum(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
327 |
trfunc = GlobTrFunc('sum', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
328 |
res = trfunc.apply([[1], [2], [3], [4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
329 |
self.assertEquals(res, [[10]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
330 |
trfunc = GlobTrFunc('sum', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
331 |
res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
332 |
self.assertEquals(res, [[1, 7], [2, 4], [3, 6]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
333 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
334 |
def test_min(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
335 |
trfunc = GlobTrFunc('min', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
336 |
res = trfunc.apply([[1], [2], [3], [4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
337 |
self.assertEquals(res, [[1]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
338 |
trfunc = GlobTrFunc('min', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
339 |
res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
340 |
self.assertEquals(res, [[1, 2], [2, 4], [3, 6]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
341 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
342 |
def test_max(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
343 |
trfunc = GlobTrFunc('max', 0) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
344 |
res = trfunc.apply([[1], [2], [3], [4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
345 |
self.assertEquals(res, [[4]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
346 |
trfunc = GlobTrFunc('max', 1) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
347 |
res = trfunc.apply([[1, 2], [2, 4], [3, 6], [1, 5]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
348 |
self.assertEquals(res, [[1, 5], [2, 4], [3, 6]]) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
349 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
350 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
351 |
class RQL2LDAPFilterTC(RQLGeneratorTC): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
352 |
schema = repo.schema |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
353 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
354 |
def setUp(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
355 |
RQLGeneratorTC.setUp(self) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
356 |
ldapsource = repo.sources[-1] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
357 |
self.pool = repo._get_pool() |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
358 |
session = mock_object(pool=self.pool) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
359 |
self.o = RQL2LDAPFilter(ldapsource, session) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
360 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
361 |
def tearDown(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
362 |
repo._free_pool(self.pool) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
363 |
RQLGeneratorTC.tearDown(self) |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
364 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
365 |
def test_base(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
366 |
rqlst = self._prepare('CWUser X WHERE X login "toto"').children[0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
367 |
self.assertEquals(self.o.generate(rqlst, 'X')[1], |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
368 |
'(&(objectClass=top)(objectClass=posixAccount)(uid=toto))') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
369 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
370 |
def test_kwargs(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1122
diff
changeset
|
371 |
rqlst = self._prepare('CWUser X WHERE X login %(x)s').children[0] |
360
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
372 |
self.o._args = {'x': "toto"} |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
373 |
self.assertEquals(self.o.generate(rqlst, 'X')[1], |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
374 |
'(&(objectClass=top)(objectClass=posixAccount)(uid=toto))') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
375 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
376 |
def test_get_attr(self): |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
377 |
rqlst = self._prepare('Any X WHERE E firstname X, E eid 12').children[0] |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
378 |
self.assertRaises(UnknownEid, self.o.generate, rqlst, 'E') |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
379 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
380 |
|
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
381 |
if __name__ == '__main__': |
600dd2fe8b40
backport unittest_ldapuser
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
382 |
unittest_main() |