server/test/unittest_multisources.py
author sylvain.thenault@logilab.fr
Thu, 29 Jan 2009 16:26:33 +0100
changeset 519 06390418cd9a
parent 342 6becc066fc00
child 520 29342c0cf55f
permissions -rw-r--r--
pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     1
from os.path import dirname, join, abspath
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     2
from logilab.common.decorators import cached
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     3
from mx.DateTime import now
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     4
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     5
from cubicweb.devtools import TestServerConfiguration, init_test_database
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     6
from cubicweb.devtools.apptest import RepositoryBasedTC
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     7
from cubicweb.devtools.repotest import do_monkey_patch, undo_monkey_patch
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     8
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
     9
class TwoSourcesConfiguration(TestServerConfiguration):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    10
    sourcefile = 'sources_multi'
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    11
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    12
        
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    13
class ExternalSource1Configuration(TestServerConfiguration):
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    14
    sourcefile = 'sources_extern'
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    15
        
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    16
class ExternalSource2Configuration(TestServerConfiguration):
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    17
    sourcefile = 'sources_multi2'
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    19
repo2, cnx2 = init_test_database('sqlite', config=ExternalSource1Configuration('data'))
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
cu = cnx2.cursor()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
ec1 = cu.execute('INSERT Card X: X title "C3: An external card", X wikiid "aaa"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
cu.execute('INSERT Card X: X title "C4: Ze external card", X wikiid "zzz"')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
aff1 = cu.execute('INSERT Affaire X: X ref "AFFREF", X in_state S WHERE S name "pitetre"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    25
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
MTIME = now() - 0.1
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    28
repo3, cnx3 = init_test_database('sqlite', config=ExternalSource2Configuration('data'))
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    29
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
# XXX, access existing connection, no pyro connection
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
from cubicweb.server.sources.pyrorql import PyroRQLSource
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    32
PyroRQLSource.get_connection = lambda x: x.uri == 'extern-multi' and cnx3 or cnx2
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
# necessary since the repository is closing its initial connections pool though
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
# we want to keep cnx2 valid
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
from cubicweb.dbapi import Connection
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
Connection.close = lambda x: None
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    37
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    38
class TwoSourcesTC(RepositoryBasedTC):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    39
    repo_config = TwoSourcesConfiguration('data')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    40
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
    def setUp(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    42
        RepositoryBasedTC.setUp(self)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    43
        # trigger discovery
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    44
        self.execute('Card X')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
        self.execute('Affaire X')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
        self.execute('State X')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
        self.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
        # don't delete external entities!
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
        self.maxeid = self.session.system_sql('SELECT MAX(eid) FROM entities').fetchone()[0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
        # add some entities
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    51
        self.ic1 = self.execute('INSERT Card X: X title "C1: An internal card", X wikiid "aaai"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
        self.ic2 = self.execute('INSERT Card X: X title "C2: Ze internal card", X wikiid "zzzi"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
        self.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
        do_monkey_patch()
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    55
        print 'main repo', self.repo
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    56
        print 'external simple repo', repo2
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    57
        print 'external multi repo', repo3
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    58
        print 'ic1', self.ic1
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    59
        print 'ic2', self.ic2
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
    def tearDown(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
        RepositoryBasedTC.tearDown(self)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
        undo_monkey_patch()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    65
    def test_eid_comp(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
        rset = self.execute('Card X WHERE X eid > 1')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
        self.assertEquals(len(rset), 4)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    68
        rset = self.execute('Any X,T WHERE X title T, X eid > 1')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
        self.assertEquals(len(rset), 4)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    70
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    71
    def test_metainformation(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    72
        rset = self.execute('Card X ORDERBY T WHERE X title T')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
        # 2 added to the system source, 2 added to the external source
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
        self.assertEquals(len(rset), 4)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
        # since they are orderd by eid, we know the 3 first one is coming from the system source
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
        # and the others from external source
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
        self.assertEquals(rset.get_entity(0, 0).metainformation(), 
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
                          {'source': {'adapter': 'native', 'uri': 'system'}, 
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
                           'type': u'Card', 'extid': None})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
        externent = rset.get_entity(3, 0)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
        metainf = externent.metainformation()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
        self.assertEquals(metainf['source'], {'adapter': 'pyrorql', 'uri': 'extern'})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    83
        self.assertEquals(metainf['type'], 'Card')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    84
        self.assert_(metainf['extid'])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    85
        etype = self.execute('Any ETN WHERE X is ET, ET name ETN, X eid %(x)s',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    86
                             {'x': externent.eid}, 'x')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    87
        self.assertEquals(etype, 'Card')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    88
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    89
    def test_order_limit_offset(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    90
        rsetbase = self.execute('Any W,X ORDERBY W,X WHERE X wikiid W')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
        self.assertEquals(len(rsetbase), 4)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    92
        self.assertEquals(sorted(rsetbase.rows), rsetbase.rows)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    93
        rset = self.execute('Any W,X ORDERBY W,X LIMIT 2 OFFSET 2 WHERE X wikiid W')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    94
        self.assertEquals(rset.rows, rsetbase.rows[2:4])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    95
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    96
    def test_has_text(self):
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
    97
        self.repo.sources_by_uri['extern'].synchronize(MTIME) # in case fti_update has been run before
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    98
        self.failUnless(self.execute('Any X WHERE X has_text "affref"'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    99
        self.failUnless(self.execute('Affaire X WHERE X has_text "affref"'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   100
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   101
    def test_anon_has_text(self):
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   102
        self.repo.sources_by_uri['extern'].synchronize(MTIME) # in case fti_update has been run before
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
        self.execute('INSERT Affaire X: X ref "no readable card"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   104
        aff1 = self.execute('INSERT Affaire X: X ref "card"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   105
        # grant read access
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   106
        self.execute('SET X owned_by U WHERE X eid %(x)s, U login "anon"', {'x': aff1}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   107
        self.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   108
        cnx = self.login('anon')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   109
        cu = cnx.cursor()
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   110
        print '*'*80
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   111
        rset = cu.execute('Any X WHERE X has_text "card"')
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   112
        self.assertEquals(len(rset), 5, zip(rset.rows, rset.description))
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   113
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   114
    def test_synchronization(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   115
        cu = cnx2.cursor()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   116
        cu.execute('SET X ref "BLAH" WHERE X eid %(x)s', {'x': aff1}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   117
        aff2 = cu.execute('INSERT Affaire X: X ref "AFFREUX", X in_state S WHERE S name "pitetre"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   118
        cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   119
        try:
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   120
            # force sync
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   121
            self.repo.sources_by_uri['extern'].synchronize(MTIME)
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   122
            self.failUnless(self.execute('Any X WHERE X has_text "blah"'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
            self.failUnless(self.execute('Any X WHERE X has_text "affreux"'))
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   124
            print 'delete', aff2
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
            cu.execute('DELETE Affaire X WHERE X eid %(x)s', {'x': aff2})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   126
            cnx2.commit()
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   127
            print 'sync'
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   128
            self.repo.sources_by_uri['extern'].synchronize(MTIME)
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   129
            print 'query'
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   130
            rset = self.execute('Any X WHERE X has_text "affreux"')
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   131
            print zip(rset.rows, rset.description)
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   132
            self.failIf(rset)
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   133
        finally:
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   134
            # restore state
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
            cu.execute('SET X ref "AFFREF" WHERE X eid %(x)s', {'x': aff1}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
            cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    def test_simplifiable_var(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
        affeid = self.execute('Affaire X WHERE X ref "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   140
        rset = self.execute('Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
                            {'x': affeid}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
        self.assertEquals(len(rset), 1)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   143
        self.assertEquals(rset[0][1], "pitetre")
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   145
    def test_simplifiable_var_2(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
        affeid = self.execute('Affaire X WHERE X ref "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
        rset = self.execute('Any E WHERE E eid %(x)s, E in_state S, NOT S name "moved"',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
                            {'x': affeid, 'u': self.session.user.eid}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
        self.assertEquals(len(rset), 1)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
    def test_sort_func(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
        self.execute('Affaire X ORDERBY DUMB_SORT(RF) WHERE X ref RF')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   153
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   154
    def test_sort_func_ambigous(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   155
        self.execute('Any X ORDERBY DUMB_SORT(RF) WHERE X title RF')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   156
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   157
    def test_in_eid(self):
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   158
        iec1 = self.repo.extid2eid(self.repo.sources_by_uri['extern'], ec1,
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   159
                                   'Card', self.session)
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   160
        rset = self.execute('Any X WHERE X eid IN (%s, %s)' % (iec1, self.ic1))
519
06390418cd9a pyrorql source now ignore external eids which are themselves coming from another external source already in use by the repository (should have the same uri)
sylvain.thenault@logilab.fr
parents: 342
diff changeset
   161
        print 'hop', iec1, self.ic1
342
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   162
        self.assertEquals(sorted(r[0] for r in rset.rows), sorted([iec1, self.ic1]))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   163
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   164
    def test_greater_eid(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   165
        rset = self.execute('Any X WHERE X eid > %s' % self.maxeid)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   166
        self.assertEquals(len(rset.rows), 2) # self.ic1 and self.ic2
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   167
        ec2 = cu.execute('INSERT Card X: X title "glup"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   168
        cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   169
        # 'X eid > something' should not trigger discovery
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   170
        rset = self.execute('Any X WHERE X eid > %s' % self.maxeid)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   171
        self.assertEquals(len(rset.rows), 2)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   172
        # trigger discovery using another query
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   173
        crset = self.execute('Card X WHERE X title "glup"')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   174
        self.assertEquals(len(crset.rows), 1) 
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   175
        rset = self.execute('Any X WHERE X eid > %s' % self.maxeid)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   176
        self.assertEquals(len(rset.rows), 3)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   177
        rset = self.execute('Any MAX(X)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   178
        self.assertEquals(len(rset.rows), 1)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   179
        self.assertEquals(rset.rows[0][0], crset[0][0])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   180
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   181
    def test_attr_unification_1(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
        n1 = self.execute('INSERT Note X: X type "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   183
        n2 = self.execute('INSERT Note X: X type "AFFREU"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   184
        rset = self.execute('Any X,Y WHERE X is Note, Y is Affaire, X type T, Y ref T')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   185
        self.assertEquals(len(rset), 1, rset.rows)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   186
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   187
    def test_attr_unification_2(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
        ec2 = cu.execute('INSERT Card X: X title "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   189
        cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   190
        try:
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   191
            c1 = self.execute('INSERT Card C: C title "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   192
            rset = self.execute('Any X,Y WHERE X is Card, Y is Affaire, X title T, Y ref T')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   193
            self.assertEquals(len(rset), 2, rset.rows)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
        finally:
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
            cu.execute('DELETE Card X WHERE X eid %(x)s', {'x': ec2}, 'x')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   196
            cnx2.commit()
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   197
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   198
    def test_attr_unification_neq_1(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   199
        # XXX complete
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
        self.execute('Any X,Y WHERE X is Note, Y is Affaire, X creation_date D, Y creation_date > D')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   201
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
    def test_attr_unification_neq_2(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   203
        # XXX complete
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
        self.execute('Any X,Y WHERE X is Card, Y is Affaire, X creation_date D, Y creation_date > D')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
    def test_union(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
        afeids = self.execute('Affaire X')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
        ueids = self.execute('EUser X')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
        rset = self.execute('(Any X WHERE X is Affaire) UNION (Any X WHERE X is EUser)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
        self.assertEquals(sorted(r[0] for r in rset.rows),
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
                          sorted(r[0] for r in afeids + ueids))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
    def test_subquery1(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
        rsetbase = self.execute('Any W,X WITH W,X BEING (Any W,X ORDERBY W,X WHERE X wikiid W)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
        self.assertEquals(len(rsetbase), 4)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   216
        self.assertEquals(sorted(rsetbase.rows), rsetbase.rows)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   217
        rset = self.execute('Any W,X LIMIT 2 OFFSET 2 WITH W,X BEING (Any W,X ORDERBY W,X WHERE X wikiid W)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
        self.assertEquals(rset.rows, rsetbase.rows[2:4])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
        rset = self.execute('Any W,X ORDERBY W,X LIMIT 2 OFFSET 2 WITH W,X BEING (Any W,X WHERE X wikiid W)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
        self.assertEquals(rset.rows, rsetbase.rows[2:4])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   221
        rset = self.execute('Any W,X WITH W,X BEING (Any W,X ORDERBY W,X LIMIT 2 OFFSET 2 WHERE X wikiid W)')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   222
        self.assertEquals(rset.rows, rsetbase.rows[2:4])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
    def test_subquery2(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
        affeid = self.execute('Affaire X WHERE X ref "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   226
        rset =self.execute('Any X,AA,AB WITH X,AA,AB BEING (Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB)',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   227
                           {'x': affeid})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   228
        self.assertEquals(len(rset), 1)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   229
        self.assertEquals(rset[0][1], "pitetre")
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   230
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   231
    def test_not_relation(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   232
        states = set(tuple(x) for x in self.execute('Any S,SN WHERE S is State, S name SN'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   233
        userstate = self.session.user.in_state[0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   234
        states.remove((userstate.eid, userstate.name))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   235
        notstates = set(tuple(x) for x in self.execute('Any S,SN WHERE S is State, S name SN, NOT X in_state S, X eid %(x)s',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   236
                                                       {'x': self.session.user.eid}, 'x'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   237
        self.assertEquals(notstates, states)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   238
        aff1 = self.execute('Any X WHERE X is Affaire, X ref "AFFREF"')[0][0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   239
        aff1stateeid, aff1statename = self.execute('Any S,SN WHERE X eid %(x)s, X in_state S, S name SN', {'x': aff1}, 'x')[0]
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   240
        self.assertEquals(aff1statename, 'pitetre')
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   241
        states.add((userstate.eid, userstate.name))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   242
        states.remove((aff1stateeid, aff1statename))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   243
        notstates = set(tuple(x) for x in self.execute('Any S,SN WHERE S is State, S name SN, NOT X in_state S, X eid %(x)s',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   244
                                                       {'x': aff1}, 'x'))
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   245
        self.set_debug(False)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   246
        self.assertSetEquals(notstates, states)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   247
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   248
    def test_nonregr1(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   249
        ueid = self.session.user.eid
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   250
        affaire = self.execute('Affaire X WHERE X ref "AFFREF"').get_entity(0, 0)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   251
        self.execute('Any U WHERE U in_group G, (G name IN ("managers", "logilab") OR (X require_permission P?, P name "bla", P require_group G)), X eid %(x)s, U eid %(u)s',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   252
                     {'x': affaire.eid, 'u': ueid})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   253
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   254
    def test_nonregr2(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   255
        treid = self.session.user.latest_trinfo().eid
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   256
        rset = self.execute('Any X ORDERBY D DESC WHERE E eid %(x)s, E wf_info_for X, X modification_date D',
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   257
                            {'x': treid})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   258
        self.assertEquals(len(rset), 1)
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   259
        self.assertEquals(rset.rows[0], [self.session.user.eid])
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   260
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   261
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   262
    def test_nonregr3(self):
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   263
        self.execute('DELETE Card X WHERE X eid %(x)s, NOT X multisource_inlined_rel Y', {'x': self.ic1})
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   264
        
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   265
if __name__ == '__main__':
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   266
    from logilab.common.testlib import unittest_main
6becc066fc00 backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   267
    unittest_main()