Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_paginate_query(self):
rq, _ = self.loader.getTextForName('test-sparql')
rq_pag = gquery.paginate_query(rq, 100, {})
self.assertNotIn(
'LIMIT', rq, 'Original query should not contain LIMIT keyword')
self.assertIn('LIMIT', rq_pag,
'Paginated query should contain LIMIT keyword')
self.assertNotIn(
'OFFSET', rq, 'Original query should not contain OFFSET keyword')
self.assertIn('OFFSET', rq_pag,
'Paginated query should contain OFFSET keyword')
glogger.debug("=====================================================")
query_metadata = gquery.get_metadata(raw_sparql_query, endpoint)
acceptHeader = 'application/json' if isinstance(raw_sparql_query, dict) else acceptHeader
pagination = query_metadata['pagination'] if 'pagination' in query_metadata else ""
rewritten_query = query_metadata['query']
# Rewrite query using parameter values
if query_metadata['type'] == 'SelectQuery' or query_metadata['type'] == 'ConstructQuery':
rewritten_query = gquery.rewrite_query(query_metadata['original_query'], query_metadata['parameters'], requestArgs)
# Rewrite query using pagination
if query_metadata['type'] == 'SelectQuery' and 'pagination' in query_metadata:
rewritten_query = gquery.paginate_query(rewritten_query, query_metadata['pagination'], requestArgs)
resp = None
headers = {}
# If we have a mime field, we load the remote dump and query it locally
if 'mime' in query_metadata and query_metadata['mime']:
glogger.debug(
"Detected {} MIME type, proceeding with locally loading remote dump".format(query_metadata['mime']))
g = Graph()
try:
query_metadata = gquery.get_metadata(raw_sparql_query, endpoint)
g.parse(endpoint, format=query_metadata['mime'])
glogger.debug("Local RDF graph loaded successfully with {} triples".format(len(g)))
except Exception as e:
glogger.error(e)
results = g.query(rewritten_query, result='sparql')