test/unittest_spa2rql.py
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Sun, 30 May 2010 01:54:12 +0200
branchstable
changeset 5609 d247e2e06db2
parent 5424 8ecbcbff9777
child 5610 91b0f118328a
permissions -rw-r--r--
[sparql] adding test for "rdf:type -> is"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
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/>.
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    18
from logilab.common.testlib import TestCase, unittest_main
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
from cubicweb.devtools import TestServerConfiguration
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    20
from cubicweb.xy import xy
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    21
from cubicweb.spa2rql import Sparql2rqlTranslator
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    22
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    23
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
    24
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
    25
xy.add_equivalence('Project name', 'doap:Project doap:name')
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    26
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    28
config = TestServerConfiguration('data')
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
config.bootstrap_cubes()
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    30
schema = config.load_schema()
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    32
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
class XYTC(TestCase):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
    def setUp(self):
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    35
        self.tr = Sparql2rqlTranslator(schema)
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    36
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
    37
    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
    38
        qi = self.tr.translate(sparql)
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
    39
        self.assertEquals(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
    40
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    41
    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
    42
        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
    43
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    44
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    45
    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
    46
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    47
    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
    48
    SELECT ?project
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    49
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    50
      ?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
    51
    }''', '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
    52
5609
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    53
    def test_base_rdftype(self):
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    54
        self._test('''
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    55
    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
    56
    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
    57
    SELECT ?project
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    58
    WHERE  {
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    59
      ?project rdf:type doap:Project.
d247e2e06db2 [sparql] adding test for "rdf:type -> is"
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 5424
diff changeset
    60
    }''', '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
    61
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    62
    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
    63
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    64
    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
    65
    SELECT ?created
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    66
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    67
      ?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
    68
              doap:created ?created.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    69
    }''', '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
    70
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    71
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    72
    def test_base_attr_sel_distinct(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    73
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    74
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    75
    SELECT DISTINCT ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    76
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    77
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    78
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    79
    }''', '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
    80
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    81
2427
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    82
    def test_base_attr_sel_reduced(self):
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    83
        self._test('''
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    84
    PREFIX doap: <http://usefulinc.com/ns/doap#>
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    85
    SELECT REDUCED ?name
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    86
    WHERE  {
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    87
      ?project a doap:Project;
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    88
              doap:name ?name.
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    89
    }''', 'Any NAME WHERE PROJECT name NAME, PROJECT is Project')
3e0ef847a546 distinct / reduced support
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2422
diff changeset
    90
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    91
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    92
    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
    93
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    94
    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
    95
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    96
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    97
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    98
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
    99
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   100
    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
   101
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   102
    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
   103
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   104
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   105
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   106
              doap:name ?name.
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   107
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   108
    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
   109
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   110
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   111
    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
   112
        self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   113
    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
   114
    SELECT ?name
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   115
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   116
      ?project a doap:Project;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   117
              doap:name ?name;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   118
              doap:created ?created.
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
    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
   121
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   122
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   123
    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
   124
        self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   125
    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
   126
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   127
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   128
      ?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
   129
    }''', '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
   130
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   131
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   132
    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
   133
        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
   134
        try:
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   135
            self._test('''
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   136
    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
   137
    SELECT ?x ?cd
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
    WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
      ?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
   140
    }''', '(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
   141
        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
   142
            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
   143
2431
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   144
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   145
    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
   146
        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
   147
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   148
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   149
    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
   150
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   151
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   152
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   153
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   154
    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
   155
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   156
            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
   157
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   158
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   159
    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
   160
        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
   161
        try:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   162
            self._test('''
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   163
    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
   164
    SELECT ?x ?cd
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   165
    WHERE  {
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   166
      ?x dc:date ?cd;
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   167
    }
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   168
    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
   169
        finally:
93c061eac647 sparql support for limit/offset/orderby
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2428
diff changeset
   170
            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
   171
2435
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   172
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   173
    def test_restr_attr(self):
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   174
        self._test('''
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   175
    PREFIX doap: <http://usefulinc.com/ns/doap#>
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   176
    SELECT ?project
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   177
    WHERE  {
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   178
      ?project a doap:Project;
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   179
              doap:name "cubicweb".
85be7a811afe sparql: support for literal restriction
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2431
diff changeset
   180
    }''', '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
   181
2422
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   182
# # 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
   183
# 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
   184
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   185
# { :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
   186
#   :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
   187
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   188
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   189
# 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
   190
# SELECT *
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   191
# {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   192
#   { ?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
   193
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   194
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   195
# 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
   196
# 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
   197
# 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
   198
# SELECT ?desc
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   199
# WHERE  {
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   200
#   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
   201
#          dc:description ?desc.
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   202
# }
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   203
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   204
if __name__ == '__main__':
96da7dc42eb5 quick and dirty support from simple sparql queries + base ui
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   205
    unittest_main()