Commit a87e5221 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Add check to test if the generated urls return valid exit codes

parent 8eda5c8f
import unittest
from dbxref import resolver
valid_ids = [
'GO:0097281',
'EC:1.1.1.1',
'UniProtKB/Swiss-Prot:P12345',
'UniProtKB/TrEMBL:A2VB99',
'taxon:452271',
'pubmed:19037750',
'PDB:4AJY',
'http://www.google.de',
'https://www.google.de',
'GeneID:956582',
'GI:731497',
'PFAM:PF00002',
'RFAM:RF00360',
'InterPro:IPR002928',
'SO:0000704',
]
invalid_ids = [
'GO:123',
'EC:hoho',
'UniProtKB/Swiss-Prot:45',
'UniProtKB/TrEMBL:99',
'taxon:hoho',
'pubmed:hoho',
'PDB:hoho',
'http://wurst',
'https://wurst',
#'InterPro:hoho',
#'GI:hoho',
#'GeneID:hoho',
#'PFAM:hoho',
#'RFAM:hoho',
#'SO:123',
]
class TestDbxrefResolve(unittest.TestCase):
def test_conversion_of_string_to_dbxref(self):
......@@ -69,10 +105,17 @@ class TestDbxrefResolve(unittest.TestCase):
self.assertEqual(resolver.check_dbxref_exists(resolver.convert_string_to_dbxref(d[0])), d[1] )
def test_check_urls(self):
import json
data = '[]'
data3 = '[{"locations": [{"type": "xml", "url": "http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:1234&format=oboxml"}, {"type": "html", "url": "http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:1234"}], "dbxref": "GO:1234"},{"dbxref": "UniProtKB/Swiss-Prot:P12345", "locations": [{"url": "http://www.uniprot.org/uniprot/P12345.xml", "type": "xml"}, {"url": "http://www.uniprot.org/uniprot/P12345", "type": "html"}]}, {"dbxref": "UniProtKB/TrEMBL:A2VB99", "locations": [{"url": "http://www.uniprot.org/uniprot/A2VB99.xml", "type": "xml"}, {"url": "http://www.uniprot.org/uniprot/A2VB99", "type": "html"}]}, {"dbxref": "taxon:452271", "locations": [{"url": "http://www.uniprot.org/taxonomy/452271.rdf", "type": "xml"}, {"url": "http://www.uniprot.org/taxonomy/452271", "type": "html"}]}, {"dbxref": "SO:0000704", "locations": [{"url": "http://www.sequenceontology.org/browser/current_svn/term/SO:0000704", "type": "html"}]}, {"dbxref": "RFAM:RF00360", "locations": [{"url": "http://rfam.xfam.org/family/RF00360?content-type=text%2Fxml", "type": "xml"}, {"url": "http://rfam.xfam.org/family/RF00360", "type": "html"}]}, {"dbxref": "pubmed:19037750", "locations": [{"url": "http://www.ncbi.nlm.nih.gov/pubmed/19037750", "type": "html"}]}, {"dbxref": "PFAM:PF00002", "locations": [{"url": "http://pfam.xfam.org/family/PF00002", "type": "html"}]}, {"dbxref": "PDB:4AJY", "locations": [{"url": "http://www.rcsb.org/pdb/download/downloadFile.do?fileFormat=xml&compression=NO&structureId=4AJY", "type": "xml"}, {"url": "http://www.rcsb.org/pdb/explore/explore.do?structureId=4AJY", "type": "html"}]}, {"dbxref": "InterPro:IPR002928", "locations": [{"url": "http://www.ebi.ac.uk/interpro/entry/IPR002928", "type": "html"}]}, {"dbxref": "http://www.google.de", "locations": [{"url": "http://www.google.de", "type": "html"}]}, {"dbxref": "https://www.google.de", "locations": [{"url": "https://www.google.de", "type": "html"}]}, {"dbxref": "GeneID:956582", "locations": [{"url": "http://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?tool=portal&db=gene&dopt=xml&sort=&val=956582&retmode=file", "type": "xml"}, {"url": "http://www.ncbi.nlm.nih.gov/gene/956582", "type": "html"}]}, {"dbxref": "GO:0097281", "locations": [{"url": "http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0097281&format=oboxml", "type": "xml"}, {"url": "http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0097281", "type": "html"}]}, {"dbxref": "GI:731497", "locations": [{"url": "http://www.ncbi.nlm.nih.gov/sviewer/viewer.cgi?tool=portal&db=protein&dopt=xml&sort=&val=731497&retmode=file", "type": "xml"}, {"url": "http://www.ncbi.nlm.nih.gov/protein/GI:731497", "type": "html"}]}, {"dbxref": "EC:1.1.1.1", "locations": [{"url": "http://enzyme.expasy.org/EC/1.1.1.1", "type": "html"}]}]'
data = json.loads(data3)
#resolver.check_urls(data)
import requests
dbxrefs = resolver.convert_to_dbxrefs(valid_ids)
resolved = resolver.resolve(dbxrefs, check_existence=False)
for r in resolved:
for k in r['locations']:
for url in r['locations'][k]:
with self.subTest(url=url):
try:
with requests.get(url, allow_redirects=True, timeout=3) as req:
self.assertLess(req.status_code, 400)
except:
self.assertTrue(False)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment