# Run with python3 test/test_sparql.py import unittest import requests import logging class TestSPARQL(unittest.TestCase): def test_sparql(self): # sparqlURL='http://sparql.genenetwork.org/sparql/' sparqlURL='http://127.0.0.1:8890//sparql/' id = "http://collections.lugli.arvadosapi.com/c=0002e93b86ad77824620bf938b97e134+126/sequence.fasta" id = "MT800005.1" query=f""" PREFIX pubseq: PREFIX sio: select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequenceuri {{ ?sample sio:SIO_000115 "{id}" . ?sequenceuri pubseq:sample ?sample . ?sample ?geo . ?geo rdfs:label ?geoname . ?sample ?date . OPTIONAL {{ ?sample ?source }} OPTIONAL {{ ?sample ?sampletype }} OPTIONAL {{ ?sample ?institute }} }} """ print(query) payload = {'query': query, 'format': 'json'} r = requests.get(sparqlURL, params=payload) result = r.json()['results']['bindings'] # for now we just take the first one print(result) self.assertEqual(result[0]['geoname']['value'],'Mahuva') if __name__ == '__main__': unittest.main()