cubicweb/test/unittest_spa2rql.py
author Laurent Peuch <cortex@worlddomination.be>
Thu, 21 Feb 2019 18:54:23 +0100
changeset 12397 c5eb647b7046
parent 11769 f5b815f67ce2
permissions -rw-r--r--
[doc] style, switch to bullet points list to make things easier to read
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11767
432f87a63057 flake8 and all
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11447
diff changeset
     1
# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2435
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    18
import unittest
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    19
11768
b8b71dd09a2c [test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
    20
from cubicweb import devtools
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.xy import xy
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    22
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    23
SKIPCAUSE = None
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    24
try:
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    25
    from cubicweb.spa2rql import Sparql2rqlTranslator
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    26
except ImportError as exc:
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    27
    SKIPCAUSE = str(exc)
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
xy.add_equivalence('Project', 'doap:Project')
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
    30
xy.add_equivalence('Project creation_date', 'doap:Project doap:created')
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
    31
xy.add_equivalence('Project name', 'doap:Project doap:name')
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
    32
xy.add_equivalence('Project name', 'doap:Project dc:title')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
10452
f3dec653a27d [test] Skip spa2rql tests when fyzz is not available
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 6340
diff changeset
    35
@unittest.skipIf(SKIPCAUSE, SKIPCAUSE)
11769
f5b815f67ce2 [test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11768
diff changeset
    36
class XYTC(unittest.TestCase):
11447
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    37
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    38
    schema = None
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    39
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    40
    @classmethod
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    41
    def setUpClass(cls):
11768
b8b71dd09a2c [test] Avoid pytest discovery warnings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11767
diff changeset
    42
        config = devtools.TestServerConfiguration('data', __file__)
11447
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    43
        config.bootstrap_cubes()
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    44
        cls.schema = config.load_schema()
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    45
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    46
    def setUp(self):
11447
ced4de539d66 [test] Move setup of spa2rql tests into setUpClass method
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11269
diff changeset
    47
        self.tr = Sparql2rqlTranslator(self.schema)
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    48
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
    49
    def _test(self, sparql, rql, args={}):
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
        qi = self.tr.translate(sparql)
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5613
diff changeset
    51
        self.assertEqual(qi.finalize(), (rql, args))
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    52
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
    def XXX_test_base_01(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    54
        self._test('SELECT * WHERE { }', 'Any X')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    55
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    56
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    57
    def test_base_is(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    58
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    59
    PREFIX doap: <http://usefulinc.com/ns/doap#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    60
    SELECT ?project
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    61
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
      ?project a doap:Project;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    63
    }''', 'Any PROJECT WHERE PROJECT is Project')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
5609
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    65
    def test_base_rdftype(self):
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    66
        self._test('''
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    67
    PREFIX doap: <http://usefulinc.com/ns/doap#>
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    68
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    69
    SELECT ?project
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    70
    WHERE  {
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    71
      ?project rdf:type doap:Project.
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    72
    }''', 'Any PROJECT WHERE PROJECT is Project')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    73
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    74
    def test_base_attr_sel(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    75
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    76
    PREFIX doap: <http://usefulinc.com/ns/doap#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    77
    SELECT ?created
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    78
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    79
      ?project a doap:Project;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    80
              doap:created ?created.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    81
    }''', 'Any CREATED WHERE PROJECT creation_date CREATED, PROJECT is Project')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    82
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    83
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    84
    def test_base_attr_sel_distinct(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    85
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    86
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    87
    SELECT DISTINCT ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    88
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    89
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    90
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    91
    }''', 'DISTINCT Any NAME WHERE PROJECT name NAME, PROJECT is Project')
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    92
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    93
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    94
    def test_base_attr_sel_reduced(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    95
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    96
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    97
    SELECT REDUCED ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    98
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    99
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
   100
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
   101
    }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
   102
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   103
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   104
    def test_base_attr_sel_limit_offset(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   105
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   106
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   107
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   108
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   109
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   110
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   111
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   112
    LIMIT 20''', 'Any NAME LIMIT 20 WHERE PROJECT name NAME, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   113
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   114
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   115
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   116
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   117
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   118
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   119
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   120
    LIMIT 20 OFFSET 10''', 'Any NAME LIMIT 20 OFFSET 10 WHERE PROJECT name NAME, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   121
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   122
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   123
    def test_base_attr_sel_orderby(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   124
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   125
    PREFIX doap: <http://usefulinc.com/ns/doap#>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   126
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   127
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   128
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   129
              doap:name ?name;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   130
              doap:created ?created.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   131
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   132
    ORDER BY ?name DESC(?created)''', 'Any NAME ORDERBY NAME ASC, CREATED DESC WHERE PROJECT name NAME, PROJECT creation_date CREATED, PROJECT is Project')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   133
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   134
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
    def test_base_any_attr_sel(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   137
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   140
      ?x dc:date ?cd;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   141
    }''', 'Any X, CD WHERE X creation_date CD')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   142
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   143
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   144
    def test_base_any_attr_sel_amb(self):
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
   145
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   146
        try:
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   147
            self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   148
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   149
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   150
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   151
      ?x dc:date ?cd;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   152
    }''', '(Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version)')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   153
        finally:
2428
a3e10e6a2461 use space as separator, dot may be found in xml ns
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2427
diff changeset
   154
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   155
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   156
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   157
    def test_base_any_attr_sel_amb_limit_offset(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   158
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   159
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   160
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   161
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   162
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   163
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   164
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   165
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   166
    LIMIT 20 OFFSET 10''', 'Any X, CD LIMIT 20 OFFSET 10 WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   167
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   168
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   169
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   170
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   171
    def test_base_any_attr_sel_amb_orderby(self):
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   172
        xy.add_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   173
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   174
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   175
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   176
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   177
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   178
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   179
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   180
    ORDER BY DESC(?cd)''', 'Any X, CD ORDERBY CD DESC WITH X, CD BEING ((Any X, CD WHERE , X creation_date CD) UNION (Any X, CD WHERE , X publication_date CD, X is Version))')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   181
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   182
            xy.remove_equivalence('Version publication_date', 'doap:Version dc:date')
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   183
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   184
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   185
    def test_restr_attr(self):
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   186
        self._test('''
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   187
    PREFIX doap: <http://usefulinc.com/ns/doap#>
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   188
    SELECT ?project
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   189
    WHERE  {
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   190
      ?project a doap:Project;
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   191
              doap:name "cubicweb".
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   192
    }''', 'Any PROJECT WHERE PROJECT name %(a)s, PROJECT is Project', {'a': 'cubicweb'})
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   193
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   194
    def test_dctitle_both_project_cwuser(self):
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   195
        self._test('''
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   196
    PREFIX doap: <http://usefulinc.com/ns/doap#>
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   197
    PREFIX dc: <http://purl.org/dc/elements/1.1/>
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   198
    SELECT ?project ?title
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   199
    WHERE  {
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   200
      ?project a doap:Project;
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   201
              dc:title ?title.
5613
bc0ebfbf5c5d [sparql] fix type inference (test_dctitle_both_project_cwuser) and support for <http://www.w3.org/1999/02/22-rdf-syntax-ns#type tag (test_base_rdftype)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5610
diff changeset
   202
    }''', 'Any PROJECT, TITLE WHERE PROJECT name TITLE, PROJECT is Project')
5610
91b0f118328a [sparql] add failing test for two entities with dc:title
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5609
diff changeset
   203
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
# # Two elements in the group
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
# PREFIX :  <http://example.org/ns#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   206
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   207
# { :p :q :r  OPTIONAL { :a :b :c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   208
#   :p :q :r  OPTIONAL { :a :b :c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   209
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   210
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   211
# PREFIX : <http://example.org/ns#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   212
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   213
# {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   214
#   { ?s ?p ?o } UNION { ?a ?b ?c }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   215
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   216
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   217
# PREFIX dob: <http://placetime.com/interval/gregorian/1977-01-18T04:00:00Z/P>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   218
# PREFIX time: <http://www.ai.sri.com/daml/ontologies/time/Time.daml#>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   219
# PREFIX dc: <http://purl.org/dc/elements/1.1/>
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   220
# SELECT ?desc
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   221
# WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   222
#   dob:1D a time:ProperInterval;
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   223
#          dc:description ?desc.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   224
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   225
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   226
if __name__ == '__main__':
11769
f5b815f67ce2 [test] Remove some usages of lgc.testlib
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 11768
diff changeset
   227
    unittest.main()