diff options
author | Pjotr Prins | 2020-11-07 10:31:27 +0000 |
---|---|---|
committer | Pjotr Prins | 2020-11-07 10:31:27 +0000 |
commit | f9c64353ac87b1fe05e0cad68e358a7f69b3bcdc (patch) | |
tree | 8bf0abedd0b127d504c7b8598cb97849e73f6d6f /test/test_sparql.py | |
parent | 8a02280c4bd05a7f8df598a75a1ea2d3caaddd7d (diff) | |
download | bh20-seq-resource-f9c64353ac87b1fe05e0cad68e358a7f69b3bcdc.tar.gz bh20-seq-resource-f9c64353ac87b1fe05e0cad68e358a7f69b3bcdc.tar.lz bh20-seq-resource-f9c64353ac87b1fe05e0cad68e358a7f69b3bcdc.zip |
Tests: added SPARQL test
Diffstat (limited to 'test/test_sparql.py')
-rw-r--r-- | test/test_sparql.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/test/test_sparql.py b/test/test_sparql.py index 00bb3ed..41cf717 100644 --- a/test/test_sparql.py +++ b/test/test_sparql.py @@ -1,11 +1,39 @@ # Run with python3 test/test_sparql.py import unittest +import requests +import logging + + class TestSPARQL(unittest.TestCase): def test_sparql(self): - pass + sparqlURL='http://sparql.genenetwork.org/sparql/' + id = "http://collections.lugli.arvadosapi.com/c=0002e93b86ad77824620bf938b97e134+126/sequence.fasta" + id = "MT800005.1" + query=f""" +PREFIX pubseq: <http://biohackathon.org/bh20-seq-schema#MainSchema/> +PREFIX sio: <http://semanticscience.org/resource/> +select distinct ?sample ?geoname ?date ?source ?geo ?sampletype ?institute ?sequenceuri +{{ + ?sample sio:SIO_000115 "{id}" . + ?sequenceuri pubseq:sample ?sample . + ?sample <http://purl.obolibrary.org/obo/GAZ_00000448> ?geo . + ?geo rdfs:label ?geoname . + ?sample <http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C25164> ?date . + OPTIONAL {{ ?sample <http://edamontology.org/data_2091> ?source }} + OPTIONAL {{ ?sample <http://purl.obolibrary.org/obo/OBI_0001479> ?sampletype }} + OPTIONAL {{ ?sample <http://purl.obolibrary.org/obo/NCIT_C41206> ?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() |