Esempio n. 1
0
 def testQuerySparqlEndpointAsk(self):
     # This test assumes a SPARQL endpoint running at http://localhost:3030/ds/query 
     # containing the contents of files test1.rdf and test2.rdf.
     # (I use Jena Fuseki with default settings for testing.)
     class testOptions(object):
         verbose  = False
         endpoint = "http://localhost:3030/ds/query"
         prefix   = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     query    = "ASK { ex:s1 ?p ?o }"
     (status,result) = asqc.querySparqlEndpoint("test", options, prefixes, query, None)
     assert status == 0, "Ask success status"
     assert result == {'head': {}, 'boolean': True}
     query    = "ASK { ex:notfound ?p ?o }"
     (status,result) = asqc.querySparqlEndpoint("test", options, prefixes, query, None)
     assert status == 1, "Ask not found status"
     assert result == {'head': {}, 'boolean': False}
     return
Esempio n. 2
0
 def testQuerySparqlEndpointConstruct(self):
     # This test assumes a SPARQL endpoint running at http://localhost:3030/ds/query 
     # containing the contents of files test1.rdf and test2.rdf.
     # (I use Jena Fuseki with default settings for testing.)
     class testOptions(object):
         verbose  = False
         endpoint = "http://localhost:3030/ds/query"
         prefix   = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     query    = "CONSTRUCT { ex:s1 ?p ?o } WHERE { ex:s1 ?p ?o }"
     (status,result) = asqc.querySparqlEndpoint("test", options, prefixes, query, None)
     assert status == 0, "Construct success status"
     assert len(result) == 2
     assert ( rdflib.URIRef("http://example.org/test#s1"),
              rdflib.URIRef("http://example.org/test#p1"),
              rdflib.URIRef("http://example.org/test#o1") ) in result
     query    = "CONSTRUCT { ex:notfound ?p ?o } WHERE { ex:notfound ?p ?o }"
     (status,result) = asqc.querySparqlEndpoint("test", options, prefixes, query, None)
     assert status == 1, "Construct not found status"
     return
Esempio n. 3
0
 def testQuerySparqlEndpointSelect(self):
     # This test assumes a SPARQL endpoint running at http://localhost:3030/ds/query 
     # containing the contents of files test1.rdf and test2.rdf.
     # (I use Jena Fuseki with default settings for testing.)
     class testOptions(object):
         verbose  = False
         endpoint = "http://localhost:3030/ds/query"
         prefix   = None
     options  = testOptions()
     prefixes = asqc.getPrefixes(options)+"PREFIX ex: <http://example.org/test#>\n"
     query    = "SELECT * WHERE { ?s ?p ?o }"
     bindings = (
             { "head":    { "vars": ["s", "p", "o"] }
             , "results": 
               { "bindings": 
                 [ { 's': rdflib.URIRef("http://example.org/test#s1")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s2")
                   , 'o': rdflib.URIRef("http://example.org/test#o4")
                   }
                 , { 's': rdflib.URIRef("http://example.org/test#s3")
                   , 'p': rdflib.URIRef("http://example.org/test#p5")
                   }
                 ]
               }
             })
     (status,result) = asqc.querySparqlEndpoint("test", options, prefixes, query, bindings)
     assert len(result["results"]["bindings"]) == 4, "querySparqlEndpoint result count"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s1" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p1" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o1" }
            } in result["results"]["bindings"], "querySparqlEndpoint result 1"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s1" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p2" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o2" }
            } in result["results"]["bindings"], "querySparqlEndpoint result 2"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s2" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p4" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o4" }
            } in result["results"]["bindings"], "querySparqlEndpoint result 3"
     assert { 's': { 'type': "uri", 'value': "http://example.org/test#s3" }
            , 'p': { 'type': "uri", 'value': "http://example.org/test#p5" }
            , 'o': { 'type': "uri", 'value': "http://example.org/test#o5" }
            } in result["results"]["bindings"], "querySparqlEndpoint result 4"
     return