Skip to content

Commit 9987e2b

Browse files
author
Will Trimble
committedFeb 15, 2018
Switch to use mglib for http; swtich to mg-rast.org
1 parent 971f767 commit 9987e2b

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed
 

‎API-testing.py

+12-21
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from time import time
88
import subprocess
99
import json
10+
from mglib.mglib import obj_from_url, async_rest_api
1011

1112

12-
13-
API_URL = "http://api.metagenomics.anl.gov/1"
13+
API_URL = "https://api.mg-rast.org/1"
1414

1515
SKIP = ["48f15d5aae95892edb9bae03988573fa",
1616
'3bfa44d3dad4e2af12bab2601cfa8138',
@@ -34,21 +34,6 @@ def sanitize(c):
3434
clist = clist[:i] + ["".join(clist[i:j+1])[1:-1]] + clist[j+1:]
3535
return " ".join(clist)
3636

37-
def getmeajsonobject(url):
38-
'''places HTTP request for url and parses the returned JSON object'''
39-
if VERBOSE:
40-
sys.stderr.write("Retrieving %s\n" % url)
41-
try:
42-
opener = urllib2.urlopen(url)
43-
except urllib2.HTTPError, e:
44-
print "Error with HTTP request: %d %s\n%s" % (e.code, e.reason, e.read())
45-
return None
46-
opener.addheaders = [('User-agent', 'API-testing.py')]
47-
48-
jsonobject = opener.read()
49-
jsonstructure = json.loads(jsonobject)
50-
return jsonstructure
51-
5237
def print_tests(testlist):
5338
for test in testlist:
5439
callhash, call, name, name2, description = test
@@ -77,8 +62,14 @@ def check_ok(stem, dir1, blesseddir):
7762
elif len(f2) == 0:
7863
return False, "emptyreference"
7964
elif len(f1) > 0 and len(f2) > 0 and f1[0] == "{" and f2[0] == "{":
80-
j1 = json.loads(f1)
81-
j2 = json.loads(f2)
65+
try:
66+
j1 = json.loads(f1)
67+
except UnicodeDecodeError:
68+
j1 = json.loads(f1.decode('latin-1'))
69+
try:
70+
j2 = json.loads(f2)
71+
except UnicodeDecodeError:
72+
j2 = json.loads(f2.decode('latin-1'))
8273
if "date" in j1.keys():
8374
j1["date"] = ""
8475
if "date" in j2.keys():
@@ -166,12 +157,12 @@ def run_tests(testlist):
166157
def get_example_calls(base_url):
167158
topleveljsonobjects = {}
168159
requestlist = []
169-
json_api_calls = getmeajsonobject(base_url)
160+
json_api_calls = obj_from_url(base_url)
170161
listofapiurls = [resources["url"] for resources in json_api_calls["resources"]]
171162
for resourceurl in listofapiurls:
172163
if VERBOSE:
173164
sys.stderr.write("resourceurl: "+resourceurl+"\n")
174-
topleveljsonobjects[resourceurl] = getmeajsonobject(resourceurl)
165+
topleveljsonobjects[resourceurl] = obj_from_url(resourceurl)
175166
if VERBOSE:
176167
print "listofapiurls: ", listofapiurls
177168
for resource in listofapiurls:

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
test script and data for MG-RAST API tests
33

44
This script harvests example API calls from the MG-RAST
5-
API at http://api.metagenomics.anl.gov/1,
5+
API at http://api.mg-rast.org/1,
66
invokes them with curl, and compares the outputs to
77
previously saved outputs in the data directory.
88

0 commit comments

Comments
 (0)