author | sylvain.thenault@logilab.fr |
Wed, 11 Feb 2009 14:57:24 +0100 | |
changeset 580 | b453a6a1c3d1 |
parent 520 | 29342c0cf55f |
child 1016 | 26387b836099 |
permissions | -rw-r--r-- |
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() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
55 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
56 |
def tearDown(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
57 |
RepositoryBasedTC.tearDown(self) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
58 |
undo_monkey_patch() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
59 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
60 |
def test_eid_comp(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
61 |
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
|
62 |
self.assertEquals(len(rset), 4) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
63 |
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
|
64 |
self.assertEquals(len(rset), 4) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
65 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
66 |
def test_metainformation(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
67 |
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
|
68 |
# 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
|
69 |
self.assertEquals(len(rset), 4) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
70 |
# 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
|
71 |
# and the others from external source |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
72 |
self.assertEquals(rset.get_entity(0, 0).metainformation(), |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
73 |
{'source': {'adapter': 'native', 'uri': 'system'}, |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
74 |
'type': u'Card', 'extid': None}) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
75 |
externent = rset.get_entity(3, 0) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
76 |
metainf = externent.metainformation() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
77 |
self.assertEquals(metainf['source'], {'adapter': 'pyrorql', 'uri': 'extern'}) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
78 |
self.assertEquals(metainf['type'], 'Card') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
79 |
self.assert_(metainf['extid']) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
80 |
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
|
81 |
{'x': externent.eid}, 'x')[0][0] |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
82 |
self.assertEquals(etype, 'Card') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
83 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
84 |
def test_order_limit_offset(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
85 |
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
|
86 |
self.assertEquals(len(rsetbase), 4) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
87 |
self.assertEquals(sorted(rsetbase.rows), rsetbase.rows) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
88 |
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
|
89 |
self.assertEquals(rset.rows, rsetbase.rows[2:4]) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
90 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
96 |
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
|
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.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
|
99 |
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
|
100 |
# grant read access |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
101 |
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
|
102 |
self.commit() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
103 |
cnx = self.login('anon') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
104 |
cu = cnx.cursor() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
108 |
def test_synchronization(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
109 |
cu = cnx2.cursor() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
cnx2.commit() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
113 |
try: |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
114 |
# 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
|
115 |
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
|
116 |
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
|
117 |
self.failUnless(self.execute('Any X WHERE X has_text "affreux"')) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
self.failIf(rset) |
342
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
123 |
finally: |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
124 |
# restore state |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
125 |
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
|
126 |
cnx2.commit() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
127 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
128 |
def test_simplifiable_var(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
{'x': affeid}, 'x') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
132 |
self.assertEquals(len(rset), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
133 |
self.assertEquals(rset[0][1], "pitetre") |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
134 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
135 |
def test_simplifiable_var_2(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
{'x': affeid, 'u': self.session.user.eid}, 'x') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
139 |
self.assertEquals(len(rset), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
140 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
141 |
def test_sort_func(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
142 |
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
|
143 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
144 |
def test_sort_func_ambigous(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
145 |
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
|
146 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
147 |
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
|
148 |
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
|
149 |
'Card', self.session) |
342
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
150 |
rset = self.execute('Any X WHERE X eid IN (%s, %s)' % (iec1, self.ic1)) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
151 |
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
|
152 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
153 |
def test_greater_eid(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
cnx2.commit() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
158 |
# 'X eid > something' should not trigger discovery |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
159 |
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
|
160 |
self.assertEquals(len(rset.rows), 2) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
161 |
# trigger discovery using another query |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
162 |
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
|
163 |
self.assertEquals(len(crset.rows), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
164 |
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
|
165 |
self.assertEquals(len(rset.rows), 3) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
166 |
rset = self.execute('Any MAX(X)') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
167 |
self.assertEquals(len(rset.rows), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
168 |
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
|
169 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
170 |
def test_attr_unification_1(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
self.assertEquals(len(rset), 1, rset.rows) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
175 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
176 |
def test_attr_unification_2(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
177 |
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
|
178 |
cnx2.commit() |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
179 |
try: |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
self.assertEquals(len(rset), 2, rset.rows) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
183 |
finally: |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
184 |
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
|
185 |
cnx2.commit() |
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_neq_1(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
188 |
# XXX complete |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
189 |
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
|
190 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
191 |
def test_attr_unification_neq_2(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
192 |
# XXX complete |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
193 |
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
|
194 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
195 |
def test_union(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
196 |
afeids = self.execute('Affaire X') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
197 |
ueids = self.execute('EUser X') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
198 |
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
|
199 |
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
|
200 |
sorted(r[0] for r in afeids + ueids)) |
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_subquery1(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
203 |
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
|
204 |
self.assertEquals(len(rsetbase), 4) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
205 |
self.assertEquals(sorted(rsetbase.rows), rsetbase.rows) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
206 |
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
|
207 |
self.assertEquals(rset.rows, rsetbase.rows[2:4]) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
208 |
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
|
209 |
self.assertEquals(rset.rows, rsetbase.rows[2:4]) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
210 |
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
|
211 |
self.assertEquals(rset.rows, rsetbase.rows[2:4]) |
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_subquery2(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
214 |
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
|
215 |
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
|
216 |
{'x': affeid}) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
217 |
self.assertEquals(len(rset), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
218 |
self.assertEquals(rset[0][1], "pitetre") |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
219 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
220 |
def test_not_relation(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
221 |
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
|
222 |
userstate = self.session.user.in_state[0] |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
223 |
states.remove((userstate.eid, userstate.name)) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
224 |
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
|
225 |
{'x': self.session.user.eid}, 'x')) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
226 |
self.assertEquals(notstates, states) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
227 |
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
|
228 |
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
|
229 |
self.assertEquals(aff1statename, 'pitetre') |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
230 |
states.add((userstate.eid, userstate.name)) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
231 |
states.remove((aff1stateeid, aff1statename)) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
232 |
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
|
233 |
{'x': aff1}, 'x')) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
234 |
self.set_debug(False) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
235 |
self.assertSetEquals(notstates, states) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
236 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
237 |
def test_nonregr1(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
238 |
ueid = self.session.user.eid |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
239 |
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
|
240 |
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
|
241 |
{'x': affaire.eid, 'u': ueid}) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
242 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
243 |
def test_nonregr2(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
244 |
treid = self.session.user.latest_trinfo().eid |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
245 |
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
|
246 |
{'x': treid}) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
247 |
self.assertEquals(len(rset), 1) |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
248 |
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
|
249 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
250 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
251 |
def test_nonregr3(self): |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
252 |
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
|
253 |
|
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
254 |
if __name__ == '__main__': |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
255 |
from logilab.common.testlib import unittest_main |
6becc066fc00
backport unittest_multisources from cubicweb-multisources
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
256 |
unittest_main() |