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