1# -*- coding: utf-8 -*- 2#!/usr/bin/python 3 4import inspect 5import os 6import sys 7import unittest 8 9# prefer local copy to the one which is installed 10# hack from http://stackoverflow.com/a/6098238/280539 11_top_level_path = os.path.realpath(os.path.abspath(os.path.join( 12 os.path.split(inspect.getfile(inspect.currentframe()))[0], 13 ".." 14))) 15if _top_level_path not in sys.path: 16 sys.path.insert(0, _top_level_path) 17# end of hack 18 19import warnings 20warnings.simplefilter("always") 21 22try: 23 from rdflib.graph import ConjunctiveGraph 24except ImportError: 25 from rdflib import ConjunctiveGraph 26 27from SPARQLWrapper import SPARQLWrapper, XML, RDFXML, RDF, N3, TURTLE, JSONLD, JSON, CSV, TSV, POST, GET 28from SPARQLWrapper.Wrapper import _SPARQL_XML, _SPARQL_JSON, _XML, _RDF_XML, _RDF_N3, _RDF_TURTLE, _RDF_JSONLD, _CSV, _TSV 29from SPARQLWrapper.SPARQLExceptions import QueryBadFormed 30 31_SPARQL_SELECT_ASK_POSSIBLE = _SPARQL_XML + _SPARQL_JSON + _CSV + _TSV + _XML # only used in test 32_SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE = _RDF_XML + _RDF_N3 + _XML + _RDF_JSONLD # only used in test. Same as Wrapper._RDF_POSSIBLE 33 34try: 35 from urllib.error import HTTPError # Python 3 36except ImportError: 37 from urllib2 import HTTPError # Python 2 38 39try: 40 bytes # Python 2.6 and above 41except NameError: 42 bytes = str 43 44import logging 45logging.basicConfig() 46 47#http://factforge.net/ 48 49# human UI http://rs.ontotext.com/sparql 50endpoint = "http://rs.ontotext.com/repositories/ff-news" 51 52#406 The Accept header does not include any available content types. 53# In the event that the specified representation format is not supported, a 406 Not Acceptable response code SHOULD be returned. 54# The server always looks at the Accept header of a request, and tries to generate a response in the format that the client asks for. If this fails, a 406 response is returned. 55 56prefixes = """ 57PREFIX pubo: <http://ontology.ontotext.com/publishing#> 58PREFIX pub: <http://ontology.ontotext.com/taxonomy/> 59PREFIX dbr: <http://dbpedia.org/resource/> 60PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 61PREFIX ff-map: <http://factforge.net/ff2016-mapping/> 62""" 63 64selectQuery = """ 65SELECT DISTINCT ?news ?title ?date 66{ 67 ?news ff-map:mentionsEntity dbr:IBM . # one can change the entity here 68 ?news pubo:creationDate ?date ; pubo:title ?title . 69 FILTER ( (?date > "2017-09-01"^^xsd:dateTime) && (?date < "2017-09-15"^^xsd:dateTime)) 70} limit 100 71""" 72 73selectQueryCSV_TSV = """ 74SELECT DISTINCT ?news ?title ?date 75{ 76 ?news ff-map:mentionsEntity dbr:IBM . # one can change the entity here 77 ?news pubo:creationDate ?date ; pubo:title ?title . 78 FILTER ( (?date > "2017-09-01"^^xsd:dateTime) && (?date < "2017-09-15"^^xsd:dateTime)) 79} limit 100 80""" 81 82askQuery = """ 83 ASK { <https://weather.com/storms/typhoon/news/typhoon-talim-taiwan-japan-preps-impacts> a ?type } 84""" 85 86constructQuery = """ 87 CONSTRUCT { 88 _:v rdfs:label ?label . 89 _:v rdfs:comment "this is only a mock node to test library" 90 } 91 WHERE { 92 <http://dbpedia.org/resource/Asturias> rdfs:label ?label . 93 } 94""" 95 96describeQuery = """ 97 DESCRIBE <https://weather.com/storms/typhoon/news/typhoon-talim-taiwan-japan-preps-impacts> 98""" 99 100queryBadFormed = """ 101 PREFIX prop: <http://dbpedia.org/property/> 102 PREFIX res: <http://dbpedia.org/resource/> 103 FROM <http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&should-sponge=&query=%0D%0ACONSTRUCT+%7B%0D%0A++++%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FBudapest%3E+%3Fp+%3Fo.%0D%0A%7D%0D%0AWHERE+%7B%0D%0A++++%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FBudapest%3E+%3Fp+%3Fo.%0D%0A%7D%0D%0A&format=application%2Frdf%2Bxml> 104 SELECT ?lat ?long 105 WHERE { 106 res:Budapest prop:latitude ?lat; 107 prop:longitude ?long. 108 } 109""" 110 111queryManyPrefixes = """ 112 PREFIX conf: <http://richard.cyganiak.de/2007/pubby/config.rdf#> 113 PREFIX meta: <http://example.org/metadata#> 114 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 115 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 116 PREFIX owl: <http://www.w3.org/2002/07/owl#> 117 PREFIX dc: <http://purl.org/dc/elements/1.1/> 118 PREFIX dcterms: <http://purl.org/dc/terms/> 119 PREFIX foaf: <http://xmlns.com/foaf/0.1/> 120 PREFIX skos: <http://www.w3.org/2004/02/skos/core#> 121 PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 122 PREFIX dbpedia: <http://dbpedia.org/resource/> 123 PREFIX o: <http://dbpedia.org/ontology/> 124 PREFIX p: <http://dbpedia.org/property/> 125 PREFIX yago: <http://dbpedia.org/class/yago/> 126 PREFIX units: <http://dbpedia.org/units/> 127 PREFIX geonames: <http://www.geonames.org/ontology#> 128 PREFIX prv: <http://purl.org/net/provenance/ns#> 129 PREFIX prvTypes: <http://purl.org/net/provenance/types#> 130 PREFIX foo: <http://purl.org/foo> 131 132 SELECT ?label 133 WHERE { 134 <http://dbpedia.org/resource/Asturias> rdfs:label ?label . 135 } 136""" 137 138queryDuplicatedPrefix = """ 139 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 140 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 141 142 SELECT ?s ?p ?o WHERE { 143 ?s ?p ?o . 144 } LIMIT 10 145""" 146 147queryWithCommaInCurie_1 = """ 148 PREFIX dbpedia: <http://dbpedia.org/resource/> 149 SELECT ?article ?title WHERE { 150 ?article ?relation dbpedia:Victoria\\,\\_British\\_Columbia . 151 ?article <http://xmlns.com/foaf/0.1/isPrimaryTopicOf> ?title 152 } 153""" 154 155queryWithCommaInCurie_2 = """ 156 PREFIX dbpedia: <http://dbpedia.org/resource/> 157 SELECT ?article ?title WHERE { 158 ?article ?relation dbpedia:Category\:Victoria\,\_British\_Columbia . 159 ?article <http://xmlns.com/foaf/0.1/isPrimaryTopicOf> ?title 160 } 161""" 162 163queryWithCommaInUri = """ 164 SELECT ?article ?title WHERE { 165 ?article ?relation <http://dbpedia.org/resource/Category:Victoria,_British_Columbia> . 166 ?article <http://xmlns.com/foaf/0.1/isPrimaryTopicOf> ?title 167 } 168""" 169 170class SPARQLWrapperTests(unittest.TestCase): 171 172 def __generic(self, query, returnFormat, method, onlyConneg=False): # graphDB uses ONLY content negotiation. 173 sparql = SPARQLWrapper(endpoint) 174 sparql.setQuery(prefixes + query) 175 sparql.setReturnFormat(returnFormat) 176 sparql.setMethod(method) 177 sparql.setOnlyConneg(onlyConneg) 178 179 try: 180 result = sparql.query() 181 except HTTPError: 182 # An ugly way to get the exception, but the only one that works 183 # both on Python 2.5 and Python 3. 184 e = sys.exc_info()[1] 185 if e.code == 400: 186 sys.stdout.write("400 Bad Request, probably query is not well formed") 187 elif e.code == 406: 188 sys.stdout.write("406 Not Acceptable, maybe query is not well formed") 189 else: 190 sys.stdout.write(str(e)) 191 sys.stdout.write("\n") 192 return False 193 else: 194 return result 195 196################################################################################ 197################################################################################ 198 199################ 200#### SELECT #### 201################ 202 203 @unittest.skip("graphDB supports only Content Negotiation") 204 def testSelectByGETinXML(self): 205 result = self.__generic(selectQuery, XML, GET) 206 ct = result.info()["content-type"] 207 assert True in [one in ct for one in _SPARQL_XML], ct 208 results = result.convert() 209 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 210 self.assertEqual(results.__class__.__name__, "Document") 211 212 def testSelectByGETinXML_Conneg(self): 213 result = self.__generic(selectQuery, XML, GET, onlyConneg=True) 214 ct = result.info()["content-type"] 215 assert True in [one in ct for one in _SPARQL_XML], ct 216 results = result.convert() 217 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 218 self.assertEqual(results.__class__.__name__, "Document") 219 220 @unittest.skip("graphDB supports only Content Negotiation") 221 def testSelectByPOSTinXML(self): 222 result = self.__generic(selectQuery, XML, POST) 223 ct = result.info()["content-type"] 224 assert True in [one in ct for one in _SPARQL_XML], ct 225 results = result.convert() 226 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 227 self.assertEqual(results.__class__.__name__, "Document") 228 229 def testSelectByPOSTinXML_Conneg(self): 230 result = self.__generic(selectQuery, XML, POST, onlyConneg=True) 231 ct = result.info()["content-type"] 232 assert True in [one in ct for one in _SPARQL_XML], ct 233 results = result.convert() 234 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 235 self.assertEqual(results.__class__.__name__, "Document") 236 237 @unittest.skip("graphDB supports only Content Negotiation") 238 def testSelectByGETinCSV(self): 239 result = self.__generic(selectQueryCSV_TSV, CSV, GET) 240 ct = result.info()["content-type"] 241 assert True in [one in ct for one in _CSV], ct 242 results = result.convert() 243 self.assertEqual(type(results), bytes) 244 245 def testSelectByGETinCSV_Conneg(self): 246 result = self.__generic(selectQueryCSV_TSV, CSV, GET, onlyConneg=True) 247 ct = result.info()["content-type"] 248 assert True in [one in ct for one in _CSV], ct 249 results = result.convert() 250 self.assertEqual(type(results), bytes) 251 252 @unittest.skip("graphDB supports only Content Negotiation") 253 def testSelectByPOSTinCSV(self): 254 result = self.__generic(selectQueryCSV_TSV, CSV, POST) 255 ct = result.info()["content-type"] 256 assert True in [one in ct for one in _CSV], ct 257 results = result.convert() 258 self.assertEqual(type(results), bytes) 259 260 def testSelectByPOSTinCSV_Conneg(self): 261 result = self.__generic(selectQueryCSV_TSV, CSV, POST, onlyConneg=True) 262 ct = result.info()["content-type"] 263 assert True in [one in ct for one in _CSV], ct 264 results = result.convert() 265 self.assertEqual(type(results), bytes) 266 267 @unittest.skip("graphDB supports only Content Negotiation") 268 def testSelectByGETinTSV(self): 269 result = self.__generic(selectQueryCSV_TSV, TSV, GET) 270 ct = result.info()["content-type"] 271 assert True in [one in ct for one in _TSV], ct 272 results = result.convert() 273 self.assertEqual(type(results), bytes) 274 275 def testSelectByGETinTSV_Conneg(self): 276 result = self.__generic(selectQueryCSV_TSV, TSV, GET, onlyConneg=True) 277 ct = result.info()["content-type"] 278 assert True in [one in ct for one in _TSV], ct 279 results = result.convert() 280 self.assertEqual(type(results), bytes) 281 282 @unittest.skip("graphDB supports only Content Negotiation") 283 def testSelectByPOSTinTSV(self): 284 result = self.__generic(selectQueryCSV_TSV, TSV, POST) 285 ct = result.info()["content-type"] 286 assert True in [one in ct for one in _TSV], ct 287 results = result.convert() 288 self.assertEqual(type(results), bytes) 289 290 def testSelectByPOSTinTSV_Conneg(self): 291 result = self.__generic(selectQueryCSV_TSV, TSV, POST, onlyConneg=True) 292 ct = result.info()["content-type"] 293 assert True in [one in ct for one in _TSV], ct 294 results = result.convert() 295 self.assertEqual(type(results), bytes) 296 297 @unittest.skip("graphDB supports only Content Negotiation") 298 def testSelectByGETinJSON(self): 299 result = self.__generic(selectQuery, JSON, GET) 300 ct = result.info()["content-type"] 301 assert True in [one in ct for one in _SPARQL_JSON], ct 302 results = result.convert() 303 self.assertEqual(type(results), dict) 304 305 def testSelectByGETinJSON_Conneg(self): 306 result = self.__generic(selectQuery, JSON, GET, onlyConneg=True) 307 ct = result.info()["content-type"] 308 assert True in [one in ct for one in _SPARQL_JSON], ct 309 results = result.convert() 310 self.assertEqual(type(results), dict) 311 312 @unittest.skip("graphDB supports only Content Negotiation") 313 def testSelectByPOSTinJSON(self): 314 result = self.__generic(selectQuery, JSON, POST) 315 ct = result.info()["content-type"] 316 assert True in [one in ct for one in _SPARQL_JSON], ct 317 results = result.convert() 318 self.assertEqual(type(results), dict) 319 320 def testSelectByPOSTinJSON_Conneg(self): 321 result = self.__generic(selectQuery, JSON, POST, onlyConneg=True) 322 ct = result.info()["content-type"] 323 assert True in [one in ct for one in _SPARQL_JSON], ct 324 results = result.convert() 325 self.assertEqual(type(results), dict) 326 327 # Asking for an unexpected return format for SELECT queryType 328 # Set by default None (and sending */*). 329 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 330 @unittest.skip("graphDB supports only Content Negotiation") 331 def testSelectByGETinN3_Unexpected(self): 332 result = self.__generic(selectQuery, N3, GET) 333 ct = result.info()["content-type"] 334 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 335 results = result.convert() 336 self.assertEqual(type(results), bytes) # text/csv 337 338 # Asking for an unexpected return format for SELECT queryType 339 # Set by default None (and sending */*). 340 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 341 def testSelectByGETinN3_Unexpected_Conneg(self): 342 result = self.__generic(selectQuery, N3, GET, onlyConneg=True) 343 ct = result.info()["content-type"] 344 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 345 results = result.convert() 346 self.assertEqual(type(results), bytes) # text/csv 347 348 # Asking for an unexpected return format for SELECT queryType 349 # Set by default None (and sending */*). 350 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 351 @unittest.skip("graphDB supports only Content Negotiation") 352 def testSelectByPOSTinN3_Unexpected(self): 353 result = self.__generic(selectQuery, N3, POST) 354 ct = result.info()["content-type"] 355 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 356 results = result.convert() 357 self.assertEqual(type(results), bytes) # text/csv 358 359 # Asking for an unexpected return format for SELECT queryType 360 # Set by default None (and sending */*). 361 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 362 def testSelectByPOSTinN3_Unexpected_Conneg(self): 363 result = self.__generic(selectQuery, N3, POST, onlyConneg=True) 364 ct = result.info()["content-type"] 365 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 366 results = result.convert() 367 self.assertEqual(type(results), bytes) # text/csv 368 369 # Asking for an unexpected return format for SELECT queryType 370 # Set by default None (and sending */*). 371 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 372 @unittest.skip("graphDB supports only Content Negotiation") 373 def testSelectByGETinJSONLD_Unexpected(self): 374 result = self.__generic(selectQuery, JSONLD, GET) 375 ct = result.info()["content-type"] 376 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 377 results = result.convert() 378 self.assertEqual(type(results), bytes) # text/csv 379 380 # Asking for an unexpected return format for SELECT queryType 381 # Set by default None (and sending */*). 382 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 383 def testSelectByGETinJSONLD_Unexpected_Conneg(self): 384 result = self.__generic(selectQuery, JSONLD, GET, onlyConneg=True) 385 ct = result.info()["content-type"] 386 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 387 results = result.convert() 388 self.assertEqual(type(results), bytes) # text/csv 389 390 # Asking for an unexpected return format for SELECT queryType 391 # Set by default None (and sending */*). 392 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 393 @unittest.skip("graphDB supports only Content Negotiation") 394 def testSelectByPOSTinJSONLD_Unexpected(self): 395 result = self.__generic(selectQuery, JSONLD, POST) 396 ct = result.info()["content-type"] 397 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 398 results = result.convert() 399 self.assertEqual(type(results), bytes) # text/csv 400 401 # Asking for an unexpected return format for SELECT queryType 402 # Set by default None (and sending */*). 403 # For a SELECT query type, the default return mimetype (if Accept: */* is sent) is text/csv 404 def testSelectByPOSTinJSONLD_Unexpected_Conneg(self): 405 result = self.__generic(selectQuery, JSONLD, POST, onlyConneg=True) 406 ct = result.info()["content-type"] 407 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 408 results = result.convert() 409 self.assertEqual(type(results), bytes) # text/csv 410 411 # Asking for an unknown return format for SELECT queryType (XML is sent) 412 @unittest.skip("graphDB supports only Content Negotiation") 413 def testSelectByGETinUnknow(self): 414 result = self.__generic(selectQuery, "foo", GET) 415 ct = result.info()["content-type"] 416 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 417 results = result.convert() 418 self.assertEqual(type(results), bytes) # text/csv 419 420 # Asking for an unknown return format for SELECT queryType (XML is sent) 421 def testSelectByGETinUnknow_Conneg(self): 422 result = self.__generic(selectQuery, "foo", GET, onlyConneg=True) 423 ct = result.info()["content-type"] 424 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 425 results = result.convert() 426 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 427 self.assertEqual(results.__class__.__name__, "Document") 428 429 # Asking for an unknown return format for SELECT queryType (XML is sent) 430 @unittest.skip("graphDB supports only Content Negotiation") 431 def testSelectByPOSTinUnknow(self): 432 result = self.__generic(selectQuery, "bar", POST) 433 ct = result.info()["content-type"] 434 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 435 results = result.convert() 436 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 437 self.assertEqual(results.__class__.__name__, "Document") 438 439 # Asking for an unknown return format for SELECT queryType (XML is sent) 440 def testSelectByPOSTinUnknow_Conneg(self): 441 result = self.__generic(selectQuery, "bar", POST, onlyConneg=True) 442 ct = result.info()["content-type"] 443 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 444 results = result.convert() 445 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 446 self.assertEqual(results.__class__.__name__, "Document") 447 448################################################################################ 449################################################################################ 450 451############# 452#### ASK #### 453############# 454 455 456 @unittest.skip("graphDB supports only Content Negotiation") 457 def testAskByGETinXML(self): 458 result = self.__generic(askQuery, XML, GET) 459 ct = result.info()["content-type"] 460 assert True in [one in ct for one in _SPARQL_XML], ct 461 results = result.convert() 462 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 463 self.assertEqual(results.__class__.__name__, "Document") 464 465 def testAskByGETinXML_Conneg(self): 466 result = self.__generic(askQuery, XML, GET, onlyConneg=True) 467 ct = result.info()["content-type"] 468 assert True in [one in ct for one in _SPARQL_XML], ct 469 results = result.convert() 470 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 471 self.assertEqual(results.__class__.__name__, "Document") 472 473 @unittest.skip("graphDB supports only Content Negotiation") 474 def testAskByPOSTinXML(self): 475 result = self.__generic(askQuery, XML, POST) 476 ct = result.info()["content-type"] 477 assert True in [one in ct for one in _SPARQL_XML], ct 478 results = result.convert() 479 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 480 self.assertEqual(results.__class__.__name__, "Document") 481 482 def testAskByPOSTinXML_Conneg(self): 483 result = self.__generic(askQuery, XML, POST, onlyConneg=True) 484 ct = result.info()["content-type"] 485 assert True in [one in ct for one in _SPARQL_XML], ct 486 results = result.convert() 487 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 488 self.assertEqual(results.__class__.__name__, "Document") 489 490 @unittest.skip("graphDB supports only Content Negotiation") 491 def testAskByGETinCSV(self): 492 result = self.__generic(askQuery, CSV, GET) 493 ct = result.info()["content-type"] 494 assert True in [one in ct for one in _CSV], ct 495 results = result.convert() 496 self.assertEqual(type(results), bytes) 497 498 @unittest.skip("graphDB not supports CSV for ASK queryType") 499 def testAskByGETinCSV_Conneg(self): 500 result = self.__generic(askQuery, CSV, GET, onlyConneg=True) 501 ct = result.info()["content-type"] 502 assert True in [one in ct for one in _CSV], ct 503 results = result.convert() 504 self.assertEqual(type(results), bytes) 505 506 @unittest.skip("graphDB supports only Content Negotiation") 507 def testAskByPOSTinCSV(self): 508 result = self.__generic(askQuery, CSV, POST) 509 ct = result.info()["content-type"] 510 assert True in [one in ct for one in _CSV], ct 511 results = result.convert() 512 self.assertEqual(type(results), bytes) 513 514 @unittest.skip("graphDB not supports CSV for ASK queryType") 515 def testAskByPOSTinCSV_Conneg(self): 516 result = self.__generic(askQuery, CSV, POST, onlyConneg=True) 517 ct = result.info()["content-type"] 518 assert True in [one in ct for one in _CSV], ct 519 results = result.convert() 520 self.assertEqual(type(results), bytes) 521 522 @unittest.skip("graphDB supports only Content Negotiation") 523 def testAskByGETinTSV(self): 524 result = self.__generic(askQuery, TSV, GET) 525 ct = result.info()["content-type"] 526 assert True in [one in ct for one in _TSV], ct 527 results = result.convert() 528 self.assertEqual(type(results), bytes) 529 530 @unittest.skip("graphDB not supports TSV for ASK queryType") 531 def testAskByGETinTSV_Conneg(self): 532 result = self.__generic(askQuery, TSV, GET, onlyConneg=True) 533 ct = result.info()["content-type"] 534 assert True in [one in ct for one in _TSV], ct 535 results = result.convert() 536 self.assertEqual(type(results), bytes) 537 538 @unittest.skip("graphDB supports only Content Negotiation") 539 def testAskByPOSTinTSV(self): 540 result = self.__generic(askQuery, TSV, POST) 541 ct = result.info()["content-type"] 542 assert True in [one in ct for one in _TSV], ct 543 results = result.convert() 544 self.assertEqual(type(results), bytes) 545 546 @unittest.skip("graphDB not supports TSV for ASK queryType") 547 def testAskByPOSTinTSV_Conneg(self): 548 result = self.__generic(askQuery, TSV, POST, onlyConneg=True) 549 ct = result.info()["content-type"] 550 assert True in [one in ct for one in _TSV], ct 551 results = result.convert() 552 self.assertEqual(type(results), bytes) 553 554 @unittest.skip("graphDB supports only Content Negotiation") 555 def testAskByGETinJSON(self): 556 result = self.__generic(askQuery, JSON, GET) 557 ct = result.info()["content-type"] 558 assert True in [one in ct for one in _SPARQL_JSON], ct 559 results = result.convert() 560 self.assertEqual(type(results), dict) 561 562 def testAskByGETinJSON_Conneg(self): 563 result = self.__generic(askQuery, JSON, GET, onlyConneg=True) 564 ct = result.info()["content-type"] 565 assert True in [one in ct for one in _SPARQL_JSON], ct 566 results = result.convert() 567 self.assertEqual(type(results), dict) 568 569 @unittest.skip("graphDB supports only Content Negotiation") 570 def testAskByPOSTinJSON(self): 571 result = self.__generic(askQuery, JSON, POST) 572 ct = result.info()["content-type"] 573 assert True in [one in ct for one in _SPARQL_JSON], ct 574 results = result.convert() 575 self.assertEqual(type(results), dict) 576 577 def testAskByPOSTinJSON_Conneg(self): 578 result = self.__generic(askQuery, JSON, POST, onlyConneg=True) 579 ct = result.info()["content-type"] 580 assert True in [one in ct for one in _SPARQL_JSON], ct 581 results = result.convert() 582 self.assertEqual(type(results), dict) 583 584 # Asking for an unexpected return format for ASK queryType 585 # Set by default None (and sending */*). 586 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 587 @unittest.skip("graphDB supports only Content Negotiation") 588 def testAskByGETinN3_Unexpected(self): 589 result = self.__generic(askQuery, N3, GET) 590 ct = result.info()["content-type"] 591 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 592 results = result.convert() 593 self.assertEqual(type(results), dict) # application/sparql-results+json 594 595 # Asking for an unexpected return format for ASK queryType 596 # Set by default None (and sending */*). 597 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 598 def testAskByGETinN3_Unexpected_Conneg(self): 599 result = self.__generic(askQuery, N3, GET, onlyConneg=True) 600 ct = result.info()["content-type"] 601 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 602 results = result.convert() 603 self.assertEqual(type(results), dict) # application/sparql-results+json 604 605 # Asking for an unexpected return format for ASK queryType 606 # Set by default None (and sending */*). 607 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 608 @unittest.skip("graphDB supports only Content Negotiation") 609 def testAskByPOSTinN3_Unexpected(self): 610 result = self.__generic(askQuery, N3, POST) 611 ct = result.info()["content-type"] 612 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 613 results = result.convert() 614 self.assertEqual(type(results), dict) # application/sparql-results+json 615 616 # Asking for an unexpected return format for ASK queryType 617 # Set by default None (and sending */*). 618 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 619 def testAskByPOSTinN3_Unexpected_Conneg(self): 620 result = self.__generic(askQuery, N3, POST, onlyConneg=True) 621 ct = result.info()["content-type"] 622 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 623 results = result.convert() 624 self.assertEqual(type(results), dict) # application/sparql-results+json 625 626 # Asking for an unexpected return format for ASK queryType 627 # Set by default None (and sending */*). 628 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 629 @unittest.skip("graphDB supports only Content Negotiation") 630 def testAskByGETinJSONLD_Unexpected(self): 631 result = self.__generic(askQuery, JSONLD, GET) 632 ct = result.info()["content-type"] 633 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 634 results = result.convert() 635 self.assertEqual(type(results), dict) # application/sparql-results+json 636 637 # Asking for an unexpected return format for ASK queryType 638 # Set by default None (and sending */*). 639 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 640 def testAskByGETinJSONLD_Unexpected_Conneg(self): 641 result = self.__generic(askQuery, JSONLD, GET, onlyConneg=True) 642 ct = result.info()["content-type"] 643 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 644 results = result.convert() 645 self.assertEqual(type(results), dict) # application/sparql-results+json 646 647 # Asking for an unexpected return format for ASK queryType 648 # Set by default None (and sending */*). 649 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 650 @unittest.skip("graphDB supports only Content Negotiation") 651 def testAskByPOSTinJSONLD_Unexpected(self): 652 result = self.__generic(askQuery, JSONLD, POST) 653 ct = result.info()["content-type"] 654 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 655 results = result.convert() 656 self.assertEqual(type(results), dict) # application/sparql-results+json 657 658 # Asking for an unexpected return format for ASK queryType 659 # Set by default None (and sending */*). 660 # For an ASK query type, the default return mimetype (if Accept: */* is sent) is application/sparql-results+json 661 def testAskByPOSTinJSONLD_Unexpected_Conneg(self): 662 result = self.__generic(askQuery, JSONLD, POST, onlyConneg=True) 663 ct = result.info()["content-type"] 664 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 665 results = result.convert() 666 self.assertEqual(type(results), dict) # application/sparql-results+json 667 668 # Asking for an unknown return format for ASK queryType (XML is sent) 669 @unittest.skip("graphDB supports only Content Negotiation") 670 def testAskByGETinUnknow(self): 671 result = self.__generic(askQuery, "foo", GET) 672 ct = result.info()["content-type"] 673 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 674 results = result.convert() 675 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 676 self.assertEqual(results.__class__.__name__, "Document") 677 678 # Asking for an unknown return format for ASK queryType (XML is sent) 679 def testAskByGETinUnknow_Conneg(self): 680 result = self.__generic(askQuery, "foo", GET, onlyConneg=True) 681 ct = result.info()["content-type"] 682 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 683 results = result.convert() 684 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 685 self.assertEqual(results.__class__.__name__, "Document") 686 687 # Asking for an unknown return format for ASK queryType (XML is sent) 688 @unittest.skip("graphDB supports only Content Negotiation") 689 def testAskByPOSTinUnknow(self): 690 result = self.__generic(askQuery, "bar", POST) 691 ct = result.info()["content-type"] 692 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 693 results = result.convert() 694 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 695 self.assertEqual(results.__class__.__name__, "Document") 696 697 # Asking for an unknown return format for ASK queryType (XML is sent) 698 def testAskByPOSTinUnknow_Conneg(self): 699 result = self.__generic(askQuery, "bar", POST, onlyConneg=True) 700 ct = result.info()["content-type"] 701 assert True in [one in ct for one in _SPARQL_SELECT_ASK_POSSIBLE], ct 702 results = result.convert() 703 self.assertEqual(results.__class__.__module__, "xml.dom.minidom") 704 self.assertEqual(results.__class__.__name__, "Document") 705 706############################################################################### 707############################################################################### 708 709################## 710### CONSTRUCT #### 711################## 712 713 @unittest.skip("graphDB supports only Content Negotiation") 714 def testConstructByGETinXML(self): 715 result = self.__generic(constructQuery, XML, GET) 716 ct = result.info()["content-type"] 717 assert True in [one in ct for one in _RDF_XML], ct 718 results = result.convert() 719 self.assertEqual(type(results), ConjunctiveGraph) 720 721 def testConstructByGETinXML_Conneg(self): 722 result = self.__generic(constructQuery, XML, GET, onlyConneg=True) 723 ct = result.info()["content-type"] 724 assert True in [one in ct for one in _RDF_XML], ct 725 results = result.convert() 726 self.assertEqual(type(results), ConjunctiveGraph) 727 728 @unittest.skip("graphDB supports only Content Negotiation") 729 def testConstructByPOSTinXML(self): 730 result = self.__generic(constructQuery, XML, POST) 731 ct = result.info()["content-type"] 732 assert True in [one in ct for one in _RDF_XML], ct 733 results = result.convert() 734 self.assertEqual(type(results), ConjunctiveGraph) 735 736 def testConstructByPOSTinXML_Conneg(self): 737 result = self.__generic(constructQuery, XML, POST, onlyConneg=True) 738 ct = result.info()["content-type"] 739 assert True in [one in ct for one in _RDF_XML], ct 740 results = result.convert() 741 self.assertEqual(type(results), ConjunctiveGraph) 742 743 @unittest.skip("graphDB supports only Content Negotiation") 744 def testConstructByGETinRDFXML(self): 745 result = self.__generic(constructQuery, RDFXML, GET) 746 ct = result.info()["content-type"] 747 assert True in [one in ct for one in _RDF_XML], ct 748 results = result.convert() 749 self.assertEqual(type(results), ConjunctiveGraph) 750 751 def testConstructByGETinRDFXML_Conneg(self): 752 result = self.__generic(constructQuery, RDFXML, GET, onlyConneg=True) 753 ct = result.info()["content-type"] 754 assert True in [one in ct for one in _RDF_XML], ct 755 results = result.convert() 756 self.assertEqual(type(results), ConjunctiveGraph) 757 758 @unittest.skip("graphDB supports only Content Negotiation") 759 def testConstructByPOSTinRDFXML(self): 760 result = self.__generic(constructQuery, RDFXML, POST) 761 ct = result.info()["content-type"] 762 assert True in [one in ct for one in _RDF_XML], ct 763 results = result.convert() 764 self.assertEqual(type(results), ConjunctiveGraph) 765 766 def testConstructByPOSTinRDFXML_Conneg(self): 767 result = self.__generic(constructQuery, RDFXML, POST, onlyConneg=True) 768 ct = result.info()["content-type"] 769 assert True in [one in ct for one in _RDF_XML], ct 770 results = result.convert() 771 self.assertEqual(type(results), ConjunctiveGraph) 772 773 @unittest.skip("graphDB supports only Content Negotiation") 774 def testConstructByGETinTURTLE(self): 775 result = self.__generic(constructQuery, TURTLE, GET) 776 ct = result.info()["content-type"] 777 assert True in [one in ct for one in _RDF_TURTLE], ct 778 results = result.convert() 779 self.assertEqual(type(results), bytes) 780 781 def testConstructByGETinTURTLE_Conneg(self): 782 result = self.__generic(constructQuery, TURTLE, GET, onlyConneg=True) 783 ct = result.info()["content-type"] 784 assert True in [one in ct for one in _RDF_TURTLE], ct 785 results = result.convert() 786 self.assertEqual(type(results), bytes) 787 788 @unittest.skip("graphDB supports only Content Negotiation") 789 def testConstructByPOSTinTURTLE(self): 790 result = self.__generic(constructQuery, TURTLE, POST) 791 ct = result.info()["content-type"] 792 assert True in [one in ct for one in _RDF_TURTLE], ct 793 results = result.convert() 794 self.assertEqual(type(results), bytes) 795 796 def testConstructByPOSTinTURTLE_Conneg(self): 797 result = self.__generic(constructQuery, TURTLE, POST, onlyConneg=True) 798 ct = result.info()["content-type"] 799 assert True in [one in ct for one in _RDF_TURTLE], ct 800 results = result.convert() 801 self.assertEqual(type(results), bytes) 802 803 @unittest.skip("graphDB supports only Content Negotiation") 804 def testConstructByGETinN3(self): 805 result = self.__generic(constructQuery, N3, GET) 806 ct = result.info()["content-type"] 807 assert True in [one in ct for one in _RDF_N3], ct 808 results = result.convert() 809 self.assertEqual(type(results), bytes) 810 811 def testConstructByGETinN3_Conneg(self): 812 result = self.__generic(constructQuery, N3, GET, onlyConneg=True) 813 ct = result.info()["content-type"] 814 assert True in [one in ct for one in _RDF_N3], ct 815 results = result.convert() 816 self.assertEqual(type(results), bytes) 817 818 @unittest.skip("graphDB supports only Content Negotiation") 819 def testConstructByPOSTinN3(self): 820 result = self.__generic(constructQuery, N3, POST) 821 ct = result.info()["content-type"] 822 assert True in [one in ct for one in _RDF_N3], ct 823 results = result.convert() 824 self.assertEqual(type(results), bytes) 825 826 def testConstructByPOSTinN3_Conneg(self): 827 result = self.__generic(constructQuery, N3, POST, onlyConneg=True) 828 ct = result.info()["content-type"] 829 assert True in [one in ct for one in _RDF_N3], ct 830 results = result.convert() 831 self.assertEqual(type(results), bytes) 832 833 @unittest.skip("graphDB supports only Content Negotiation") 834 def testConstructByGETinJSONLD(self): 835 result = self.__generic(constructQuery, JSONLD, GET) 836 ct = result.info()["content-type"] 837 assert True in [one in ct for one in _RDF_JSONLD], ct 838 results = result.convert() 839 self.assertEqual(type(results), ConjunctiveGraph) 840 841 def testConstructByGETinJSONLD_Conneg(self): 842 result = self.__generic(constructQuery, JSONLD, GET, onlyConneg=True) 843 ct = result.info()["content-type"] 844 assert True in [one in ct for one in _RDF_JSONLD], ct 845 results = result.convert() 846 self.assertEqual(type(results), ConjunctiveGraph) 847 848 @unittest.skip("graphDB supports only Content Negotiation") 849 def testConstructByPOSTinJSONLD(self): 850 result = self.__generic(constructQuery, JSONLD, POST) 851 ct = result.info()["content-type"] 852 assert True in [one in ct for one in _RDF_JSONLD], ct 853 results = result.convert() 854 self.assertEqual(type(results), ConjunctiveGraph) 855 856 def testConstructByPOSTinJSONLD_Conneg(self): 857 result = self.__generic(constructQuery, JSONLD, POST, onlyConneg=True) 858 ct = result.info()["content-type"] 859 assert True in [one in ct for one in _RDF_JSONLD], ct 860 results = result.convert() 861 self.assertEqual(type(results), ConjunctiveGraph) 862 863 # Asking for an unexpected return format for CONSTRUCT queryType. 864 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 865 @unittest.skip("graphDB supports only Content Negotiation") 866 def testConstructByGETinCSV_Unexpected(self): 867 result = self.__generic(constructQuery, CSV, GET) 868 ct = result.info()["content-type"] 869 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 870 results = result.convert() 871 self.assertEqual(type(results), bytes) # application/n-triples 872 873 # Asking for an unexpected return format for CONSTRUCT queryType. 874 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 875 def testConstructByGETinCSV_Unexpected_Conneg(self): 876 result = self.__generic(constructQuery, CSV, GET, onlyConneg=True) 877 ct = result.info()["content-type"] 878 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 879 results = result.convert() 880 self.assertEqual(type(results), bytes) # application/n-triples 881 882 # Asking for an unexpected return format for CONSTRUCT queryType. 883 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 884 @unittest.skip("graphDB supports only Content Negotiation") 885 def testConstructByPOSTinCSV_Unexpected(self): 886 result = self.__generic(constructQuery, CSV, POST) 887 ct = result.info()["content-type"] 888 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 889 results = result.convert() 890 self.assertEqual(type(results), bytes) # application/n-triples 891 892 # Asking for an unexpected return format for CONSTRUCT queryType. 893 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 894 def testConstructByPOSTinCSV_Unexpected_Conneg(self): 895 result = self.__generic(constructQuery, CSV, POST, onlyConneg=True) 896 ct = result.info()["content-type"] 897 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 898 results = result.convert() 899 self.assertEqual(type(results), bytes) # application/n-triples 900 901 # Asking for an unexpected return format for CONSTRUCT queryType. 902 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 903 @unittest.skip("graphDB supports only Content Negotiation") 904 def testConstructByGETinJSON_Unexpected(self): 905 result = self.__generic(constructQuery, JSON, GET) 906 ct = result.info()["content-type"] 907 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 908 results = result.convert() 909 self.assertEqual(type(results), bytes) # application/n-triples 910 911 # Asking for an unexpected return format for CONSTRUCT queryType. 912 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 913 def testConstructByGETinJSON_Unexpected_Conneg(self): 914 result = self.__generic(constructQuery, JSON, GET , onlyConneg=True) 915 ct = result.info()["content-type"] 916 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 917 results = result.convert() 918 self.assertEqual(type(results), bytes) # application/n-triples 919 920 # Asking for an unexpected return format for CONSTRUCT queryType. 921 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 922 @unittest.skip("graphDB supports only Content Negotiation") 923 def testConstructByPOSTinJSON_Unexpected(self): 924 result = self.__generic(constructQuery, JSON, POST) 925 ct = result.info()["content-type"] 926 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 927 results = result.convert() 928 self.assertEqual(type(results), bytes) # application/n-triples 929 930 # Asking for an unexpected return format for CONSTRUCT queryType. 931 # For a CONSTRUCT query type, the default return mimetype (if Accept: */* is sent) is application/n-triples 932 def testConstructByPOSTinJSON_Unexpected_Conneg(self): 933 result = self.__generic(constructQuery, JSON, POST, onlyConneg=True) 934 ct = result.info()["content-type"] 935 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 936 results = result.convert() 937 self.assertEqual(type(results), bytes) # application/n-triples 938 939 # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) 940 @unittest.skip("graphDB supports only Content Negotiation") 941 def testConstructByGETinUnknow(self): 942 result = self.__generic(constructQuery, "foo", GET) 943 ct = result.info()["content-type"] 944 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 945 results = result.convert() 946 self.assertEqual(type(results), ConjunctiveGraph) 947 948 # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) 949 def testConstructByGETinUnknow_Conneg(self): 950 result = self.__generic(constructQuery, "foo", GET, onlyConneg=True) 951 ct = result.info()["content-type"] 952 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 953 results = result.convert() 954 self.assertEqual(type(results), ConjunctiveGraph) 955 956 # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) 957 @unittest.skip("graphDB supports only Content Negotiation") 958 def testConstructByPOSTinUnknow(self): 959 result = self.__generic(constructQuery, "bar", POST) 960 ct = result.info()["content-type"] 961 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 962 results = result.convert() 963 self.assertEqual(type(results), ConjunctiveGraph) 964 965 # Asking for an unknown return format for CONSTRUCT queryType (XML is sent) 966 def testConstructByPOSTinUnknow_Conneg(self): 967 result = self.__generic(constructQuery, "bar", POST, onlyConneg=True) 968 ct = result.info()["content-type"] 969 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 970 results = result.convert() 971 self.assertEqual(type(results), ConjunctiveGraph) 972 973############################################################################### 974############################################################################### 975 976################# 977### DESCRIBE #### 978################# 979 980 @unittest.skip("graphDB supports only Content Negotiation") 981 def testDescribeByGETinXML(self): 982 result = self.__generic(describeQuery, XML, GET) 983 print result.geturl() 984 ct = result.info()["content-type"] 985 assert True in [one in ct for one in _RDF_XML], ct 986 results = result.convert() 987 self.assertEqual(type(results), ConjunctiveGraph) 988 989 def testDescribeByGETinXML_Conneg(self): 990 result = self.__generic(describeQuery, XML, GET, onlyConneg=True) 991 ct = result.info()["content-type"] 992 assert True in [one in ct for one in _RDF_XML], ct 993 results = result.convert() 994 self.assertEqual(type(results), ConjunctiveGraph) 995 996 @unittest.skip("graphDB supports only Content Negotiation") 997 def testDescribeByPOSTinXML(self): 998 result = self.__generic(describeQuery, XML, POST) 999 ct = result.info()["content-type"] 1000 assert True in [one in ct for one in _RDF_XML], ct 1001 results = result.convert() 1002 self.assertEqual(type(results), ConjunctiveGraph) 1003 1004 def testDescribeByPOSTinXML_Conneg(self): 1005 result = self.__generic(describeQuery, XML, POST, onlyConneg=True) 1006 ct = result.info()["content-type"] 1007 assert True in [one in ct for one in _RDF_XML], ct 1008 results = result.convert() 1009 self.assertEqual(type(results), ConjunctiveGraph) 1010 1011 @unittest.skip("graphDB supports only Content Negotiation") 1012 def testDescribeByGETinRDFXML(self): 1013 result = self.__generic(describeQuery, RDFXML, GET) 1014 ct = result.info()["content-type"] 1015 assert True in [one in ct for one in _RDF_XML], ct 1016 results = result.convert() 1017 self.assertEqual(type(results), ConjunctiveGraph) 1018 1019 def testDescribeByGETinRDFXML_Conneg(self): 1020 result = self.__generic(describeQuery, RDFXML, GET, onlyConneg=True) 1021 ct = result.info()["content-type"] 1022 assert True in [one in ct for one in _RDF_XML], ct 1023 results = result.convert() 1024 self.assertEqual(type(results), ConjunctiveGraph) 1025 1026 @unittest.skip("graphDB supports only Content Negotiation") 1027 def testDescribeByPOSTinRDFXML(self): 1028 result = self.__generic(describeQuery, RDFXML, POST) 1029 ct = result.info()["content-type"] 1030 assert True in [one in ct for one in _RDF_XML], ct 1031 results = result.convert() 1032 self.assertEqual(type(results), ConjunctiveGraph) 1033 1034 def testDescribeByPOSTinRDFXML_Conneg(self): 1035 result = self.__generic(describeQuery, RDFXML, POST, onlyConneg=True) 1036 ct = result.info()["content-type"] 1037 assert True in [one in ct for one in _RDF_XML], ct 1038 results = result.convert() 1039 self.assertEqual(type(results), ConjunctiveGraph) 1040 1041 @unittest.skip("graphDB supports only Content Negotiation") 1042 def testDescribeByGETinTURTLE(self): 1043 result = self.__generic(describeQuery, TURTLE, GET) 1044 ct = result.info()["content-type"] 1045 assert True in [one in ct for one in _RDF_TURTLE], ct 1046 results = result.convert() 1047 self.assertEqual(type(results), bytes) 1048 1049 def testDescribeByGETinTURTLE_Conneg(self): 1050 result = self.__generic(describeQuery, TURTLE, GET, onlyConneg=True) 1051 ct = result.info()["content-type"] 1052 assert True in [one in ct for one in _RDF_TURTLE], ct 1053 results = result.convert() 1054 self.assertEqual(type(results), bytes) 1055 1056 @unittest.skip("graphDB supports only Content Negotiation") 1057 def testDescribeByPOSTinTURTLE(self): 1058 result = self.__generic(describeQuery, TURTLE, POST) 1059 ct = result.info()["content-type"] 1060 assert True in [one in ct for one in _RDF_TURTLE], ct 1061 results = result.convert() 1062 self.assertEqual(type(results), bytes) 1063 1064 def testDescribeByPOSTinTURTLE_Conneg(self): 1065 result = self.__generic(describeQuery, TURTLE, POST, onlyConneg=True) 1066 ct = result.info()["content-type"] 1067 assert True in [one in ct for one in _RDF_TURTLE], ct 1068 results = result.convert() 1069 self.assertEqual(type(results), bytes) 1070 1071 @unittest.skip("graphDB supports only Content Negotiation") 1072 def testDescribeByGETinN3(self): 1073 result = self.__generic(describeQuery, N3, GET) 1074 ct = result.info()["content-type"] 1075 assert True in [one in ct for one in _RDF_N3], ct 1076 results = result.convert() 1077 self.assertEqual(type(results), bytes) 1078 1079 def testDescribeByGETinN3_Conneg(self): 1080 result = self.__generic(describeQuery, N3, GET, onlyConneg=True) 1081 ct = result.info()["content-type"] 1082 assert True in [one in ct for one in _RDF_N3], ct 1083 results = result.convert() 1084 self.assertEqual(type(results), bytes) 1085 1086 @unittest.skip("graphDB supports only Content Negotiation") 1087 def testDescribeByPOSTinN3(self): 1088 result = self.__generic(describeQuery, N3, POST) 1089 ct = result.info()["content-type"] 1090 assert True in [one in ct for one in _RDF_N3], ct 1091 results = result.convert() 1092 self.assertEqual(type(results), bytes) 1093 1094 def testDescribeByPOSTinN3_Conneg(self): 1095 result = self.__generic(describeQuery, N3, POST, onlyConneg=True) 1096 ct = result.info()["content-type"] 1097 assert True in [one in ct for one in _RDF_N3], ct 1098 results = result.convert() 1099 self.assertEqual(type(results), bytes) 1100 1101 @unittest.skip("graphDB supports only Content Negotiation") 1102 def testDescribeByGETinJSONLD(self): 1103 result = self.__generic(describeQuery, JSONLD, GET) 1104 ct = result.info()["content-type"] 1105 assert True in [one in ct for one in _RDF_JSONLD], ct 1106 results = result.convert() 1107 self.assertEqual(type(results), ConjunctiveGraph) 1108 1109 def testDescribeByGETinJSONLD_Conneg(self): 1110 result = self.__generic(describeQuery, JSONLD, GET, onlyConneg=True) 1111 ct = result.info()["content-type"] 1112 assert True in [one in ct for one in _RDF_JSONLD], ct 1113 results = result.convert() 1114 self.assertEqual(type(results), ConjunctiveGraph) 1115 1116 @unittest.skip("graphDB supports only Content Negotiation") 1117 def testDescribeByPOSTinJSONLD(self): 1118 result = self.__generic(describeQuery, JSONLD, POST) 1119 ct = result.info()["content-type"] 1120 assert True in [one in ct for one in _RDF_JSONLD], ct 1121 results = result.convert() 1122 self.assertEqual(type(results), ConjunctiveGraph) 1123 1124 def testDescribeByPOSTinJSONLD_Conneg(self): 1125 result = self.__generic(describeQuery, JSONLD, POST, onlyConneg=True) 1126 ct = result.info()["content-type"] 1127 assert True in [one in ct for one in _RDF_JSONLD], ct 1128 results = result.convert() 1129 self.assertEqual(type(results), ConjunctiveGraph) 1130 1131 # Asking for an unexpected return format for DESCRIBE queryType. 1132 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1133 @unittest.skip("graphDB supports only Content Negotiation") 1134 def testDescribeByGETinCSV_Unexpected(self): 1135 result = self.__generic(describeQuery, CSV, GET) 1136 ct = result.info()["content-type"] 1137 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1138 results = result.convert() 1139 self.assertEqual(type(results), bytes) # application/n-triples 1140 1141 # Asking for an unexpected return format for DESCRIBE queryType. 1142 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1143 def testDescribeByGETinCSV_Unexpected_Conneg(self): 1144 result = self.__generic(describeQuery, CSV, GET, onlyConneg=True) 1145 ct = result.info()["content-type"] 1146 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1147 results = result.convert() 1148 self.assertEqual(type(results), bytes) # application/n-triples 1149 1150 # Asking for an unexpected return format for DESCRIBE queryType. 1151 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1152 @unittest.skip("graphDB supports only Content Negotiation") 1153 def testDescribeByPOSTinCSV_Unexpected(self): 1154 result = self.__generic(describeQuery, CSV, POST) 1155 ct = result.info()["content-type"] 1156 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1157 results = result.convert() 1158 self.assertEqual(type(results), bytes) # application/n-triples 1159 1160 # Asking for an unexpected return format for DESCRIBE queryType. 1161 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1162 def testDescribeByPOSTinCSV_Unexpected_Conneg(self): 1163 result = self.__generic(describeQuery, CSV, POST, onlyConneg=True) 1164 ct = result.info()["content-type"] 1165 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1166 results = result.convert() 1167 self.assertEqual(type(results), bytes) # application/n-triples 1168 1169 # Asking for an unexpected return format for DESCRIBE queryType. 1170 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1171 @unittest.skip("graphDB supports only Content Negotiation") 1172 def testDescribeByGETinJSON_Unexpected(self): 1173 result = self.__generic(describeQuery, JSON, GET) 1174 ct = result.info()["content-type"] 1175 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1176 results = result.convert() 1177 self.assertEqual(type(results), bytes) # application/n-triples 1178 1179 # Asking for an unexpected return format for DESCRIBE queryType. 1180 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1181 def testDescribeByGETinJSON_Unexpected_Conneg(self): 1182 result = self.__generic(describeQuery, JSON, GET, onlyConneg=True) 1183 ct = result.info()["content-type"] 1184 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1185 results = result.convert() 1186 self.assertEqual(type(results), bytes) # application/n-triples 1187 1188 # Asking for an unexpected return format for DESCRIBE queryType. 1189 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1190 @unittest.skip("graphDB supports only Content Negotiation") 1191 def testDescribeByPOSTinJSON_Unexpected(self): 1192 result = self.__generic(describeQuery, JSON, POST) 1193 ct = result.info()["content-type"] 1194 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1195 results = result.convert() 1196 self.assertEqual(type(results), bytes) # application/n-triples 1197 1198 # Asking for an unexpected return format for DESCRIBE queryType. 1199 # For a DESCRIBE query type, the default return mimetype (if Accept: */* is sent) application/n-triples 1200 def testDescribeByPOSTinJSON_Unexpected_Conneg(self): 1201 result = self.__generic(describeQuery, JSON, POST, onlyConneg=True) 1202 ct = result.info()["content-type"] 1203 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE] 1204 results = result.convert() 1205 self.assertEqual(type(results), bytes) # application/n-triples 1206 1207 # Asking for an unknown return format for DESCRIBE queryType (XML is sent) 1208 @unittest.skip("graphDB supports only Content Negotiation") 1209 def testDescribeByGETinUnknow(self): 1210 result = self.__generic(describeQuery, "foo", GET) 1211 ct = result.info()["content-type"] 1212 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 1213 results = result.convert() 1214 self.assertEqual(type(results), ConjunctiveGraph) 1215 1216 # Asking for an unknown return format for DESCRIBE queryType (XML is sent) 1217 def testDescribeByGETinUnknow_Conneg(self): 1218 result = self.__generic(describeQuery, "foo", GET, onlyConneg=True) 1219 ct = result.info()["content-type"] 1220 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 1221 results = result.convert() 1222 self.assertEqual(type(results), ConjunctiveGraph) 1223 1224 # Asking for an unknown return format for DESCRIBE queryType (XML is sent) 1225 @unittest.skip("graphDB supports only Content Negotiation") 1226 def testDescribeByPOSTinUnknow(self): 1227 result = self.__generic(describeQuery, "bar", POST) 1228 ct = result.info()["content-type"] 1229 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 1230 results = result.convert() 1231 self.assertEqual(type(results), ConjunctiveGraph) 1232 1233 # Asking for an unknown return format for DESCRIBE queryType (XML is sent) 1234 def testDescribeByPOSTinUnknow_Conneg(self): 1235 result = self.__generic(describeQuery, "bar", POST, onlyConneg=True) 1236 ct = result.info()["content-type"] 1237 assert True in [one in ct for one in _SPARQL_DESCRIBE_CONSTRUCT_POSSIBLE], ct 1238 results = result.convert() 1239 self.assertEqual(type(results), ConjunctiveGraph) 1240 1241 ################################################################################ 1242 ################################################################################ 1243 ################################################################################ 1244 1245 def testQueryBadFormed(self): 1246 self.assertRaises(QueryBadFormed, self.__generic, queryBadFormed, XML, GET) 1247 1248 def testQueryManyPrefixes(self): 1249 result = self.__generic(queryManyPrefixes, XML, GET) 1250 1251 # https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#iriRefs 1252 # A prefix declared with the PREFIX keyword may not be re-declared in the same query. 1253 @unittest.skip("GraphDB returns a QueryBadFormed Error.") 1254 def testQueryDuplicatedPrefix(self): 1255 result = self.__generic(queryDuplicatedPrefix, XML, GET) 1256 1257 def testKeepAlive(self): 1258 sparql = SPARQLWrapper(endpoint) 1259 sparql.setQuery('SELECT * WHERE {?s ?p ?o} LIMIT 10') 1260 sparql.setReturnFormat(JSON) 1261 sparql.setMethod(GET) 1262 sparql.setUseKeepAlive() 1263 1264 sparql.query() 1265 sparql.query() 1266 1267 def testQueryWithComma_1(self): 1268 result = self.__generic(queryWithCommaInCurie_1, XML, GET) 1269 1270 #MALFORMED QUERY: Lexical error at line 10, column 44. Encountered: "\\" (92), after : "" 1271 @unittest.skip("graphDB returns a QueryBadFormed Error.") 1272 def testQueryWithComma_2(self): 1273 result = self.__generic(queryWithCommaInCurie_2, XML, GET) 1274 1275 def testQueryWithComma_3(self): 1276 result = self.__generic(queryWithCommaInUri, XML, GET) 1277 1278if __name__ == "__main__": 1279 unittest.main() 1280