Ejemplo n.º 1
0
def simple_test(path, input, check=None, expected_status=200, is_right=(lambda x:True)):
    DOMAIN = config('host', 'apihost')
    url = DOMAIN + path
    try:
        # print 'checking', url
        (win, output) = test_http_json_method(url, verb='POST', data=input,
                                              expected_status=expected_status,
                                              return_bool_data=True)
        if not win:
            # Error message already printed
            print '** http lose'
            return 1
        if isinstance(output, dict) and 'error' in output:
            # Should be 400, not 200
            print '** error', output
            return 1
        elif check == None:
            return 0
        elif check(output, ''):
            if is_right(output):
                return 0
            else:
                print '** result is not right', output
                return 1
        else:
            return 1
    except Exception, e:
        print '** exception', e
        traceback.print_exc()
        return 1
Ejemplo n.º 2
0
def check_node_info(parameters):
    DOMAIN = config('host', 'apihost')
    SUBMIT_URI = DOMAIN + '/v3/tree_of_life/node_info'
    test, result, _ = test_http_json_method(SUBMIT_URI, "POST",
                                            data=parameters,
                                            expected_status=200,
                                            return_bool_data=True)
    if not test: sys.exit(1)
    node_id_key = u'node_id'
    check_node_result(result, node_id_key)
    # check_node_expectation(parameters, result, node_id_key, ...name...)
    valid_keys = [node_id_key, u'taxon', u'nearest_taxon', u'synth_id']
    check_result_keys(result, valid_keys)
    sys.exit(exit_status[0])
Ejemplo n.º 3
0
def check_node_info(parameters):
    DOMAIN = config('host', 'apihost')
    SUBMIT_URI = DOMAIN + '/v3/tree_of_life/node_info'
    test, result, _ = test_http_json_method(SUBMIT_URI,
                                            "POST",
                                            data=parameters,
                                            expected_status=200,
                                            return_bool_data=True)
    if not test: sys.exit(1)
    node_id_key = u'node_id'
    check_node_result(result, node_id_key)
    # check_node_expectation(parameters, result, node_id_key, ...name...)
    valid_keys = [node_id_key, u'taxon', u'nearest_taxon', u'synth_id']
    check_result_keys(result, valid_keys)
    sys.exit(exit_status[0])
Ejemplo n.º 4
0
def simple_test(path, input, check, is_right=(lambda x:True)):
    DOMAIN = config('host', 'apihost')
    url = DOMAIN + path
    try:
        # print 'checking', url
        output = get_obj_from_http(url, verb='POST', data=input)
        if isinstance(output, dict) and 'error' in output:
            # Should be 400, not 200
            print '** error', output
            return 1
        elif check(output, ''):
            if is_right(output):
                return 0
            else:
                print '** result is not right', output
                return 1
        else:
            return 1
    except Exception, e:
        print '** exception', e
        traceback.print_exc()
        return 1
Ejemplo n.º 5
0
def simple_test(path, input, check, is_right=(lambda x: True)):
    DOMAIN = config('host', 'apihost')
    url = DOMAIN + path
    try:
        # print 'checking', url
        output = get_obj_from_http(url, verb='POST', data=input)
        if isinstance(output, dict) and 'error' in output:
            # Should be 400, not 200
            print '** error', output
            return 1
        elif check(output, ''):
            if is_right(output):
                return 0
            else:
                print '** result is not right', output
                return 1
        else:
            return 1
    except Exception, e:
        print '** exception', e
        traceback.print_exc()
        return 1
Ejemplo n.º 6
0
def simple_test(path,
                input,
                check=None,
                expected_status=200,
                is_right=(lambda x: True)):
    DOMAIN = config('host', 'apihost')
    url = DOMAIN + path
    try:
        # print 'checking', url
        (win, output) = test_http_json_method(url,
                                              verb='POST',
                                              data=input,
                                              expected_status=expected_status,
                                              return_bool_data=True)
        if not win:
            # Error message already printed
            print '** http lose'
            return 1
        if isinstance(output, dict) and 'error' in output:
            # Should be 400, not 200
            print '** error', output
            return 1
        elif check == None:
            return 0
        elif check(output, ''):
            if is_right(output):
                return 0
            else:
                print '** result is not right', output
                return 1
        else:
            return 1
    except Exception, e:
        print '** exception', e
        traceback.print_exc()
        return 1
Ejemplo n.º 7
0
#!/usr/bin/env python
import sys, os
from opentreetesting import test_http_json_method, config
DOMAIN = config('host', 'apihost')
SUBMIT_URI = DOMAIN + '/v3/amendments/list_all'
r = test_http_json_method(SUBMIT_URI,
                          'GET',
                          expected_status=200,
                          return_bool_data=True)
if not r[0]:
    sys.exit(1)
#print r[1]
Ejemplo n.º 8
0
#!/usr/bin/env python
import sys
import requests
import json
from opentreetesting import config, summarize_json_response
DOMAIN = config('host', 'golshost')
p = '/ext/GoLS/graphdb/getStudyIngestMessagesForNexSON'
if DOMAIN.startswith('http://127.0.0.1'):
    p = '/db/data' + p
SUBMIT_URI = DOMAIN + p
payload = {
    'nexsonBlob': open('data/359', 'rU').read()
}

headers = {
    'content-type' : 'application/json',
    'accept' : 'application/json',
}
d = json.dumps(payload)
resp = requests.post(SUBMIT_URI,
                     headers=headers,
                     data=d,
                     allow_redirects=True)
summarize_json_response(resp) or sys.exit(1)
#!/usr/bin/env python
import sys, os, re
from opentreetesting import test_http_json_method, config

DOMAIN = config("host", "apihost")
SUBMIT_URI = DOMAIN + "/v2/taxonomy/subtree"
test, result = test_http_json_method(
    SUBMIT_URI, "POST", data={"ott_id": 515698}, expected_status=200, return_bool_data=True
)
if not test:
    sys.exit(1)
tree = result[u"subtree"]
if tree is None or tree == "":
    sys.stderr.write("Expected result to have a tree, but found {}\n".format(result))
    sys.exit(1)
# trying to avoid dealing with a newick parser here...
ROOTTAXONSTR = "\)Barnadesia_ott515698;"
namecheck = re.compile(ROOTTAXONSTR)
if re.search(namecheck, tree) is None:
    errstr = "requested taxon {} does not appear at root of tree:\n {}"
    sys.stderr.write(errstr, ROOTTAXONSTR[1:], tree)
    sys.exit(1)
Ejemplo n.º 10
0
#!/usr/bin/env python

# export PYTHONPATH=~/a/ot/repo/germinator/ws-tests
# python ws-tests/test_v3_addition.py host:apihost="http://localhost:7476" host:translate=true

import sys, requests, opentreetesting, json

from check import *

opentreetesting.exit_if_api_is_readonly('test_v3_addition.py')

# Find an unused OTT id

id = 99000000

DOMAIN = opentreetesting.config('host', 'apihost')

while True:
    response = requests.request(
        'POST',
        opentreetesting.translate(DOMAIN + '/v3/taxonomy/taxon_info'),
        headers={'content-type': 'application/json'},
        data=json.dumps({'ott_id': id}),
        allow_redirects=True)
    if response.status_code != 200:
        print 'id %s is unused' % id
        break
    # print 'id %s is in use' % id
    id += 10

name1 = "Test taxon 1"
Ejemplo n.º 11
0
def check_about(parameters):

    DOMAIN = config('host', 'apihost')
    SUBMIT_URI = DOMAIN + '/v3/tree_of_life/about'
    test, result, _ = test_http_json_method(SUBMIT_URI, "POST",
                                              data=parameters,
                                              expected_status=200,
                                              return_bool_data=True)
    if not test:
        sys.exit(1)

    """ Doc says:
    "synth_id" : "opentree4.1",
      "root_node_id" : "ott93302",    # in v2 this was an integer
      "num_source_trees" : 484,
      "date_completed" : "2016-02-09 18:14:43",
      "taxonomy_version" : "2.9draft12",
      "num_tips" : 2424255,
      "num_source_studies" : 478,
      "filtered_flags" : [ "major_rank_conflict", "major_rank_conflict_inherited", "environmental", "unclassified_inherited", "unclassified", "viral", "barren", "not_otu", "incertae_sedis", "incertae_sedis_inherited", "extinct_inherited", "extinct", "hidden", "unplaced", "unplaced_inherited", "was_container", "inconsistent", "hybrid", "merged" ],

      "root_ott_id" : 93302
      "root_taxon_name" : "cellular organisms",

      maybe: "root_taxon" : { ... }

    """

    code = [0]
    def lose(): code[0] = 1
    def check_result_type(name, typo):
        value = result.get(name)
        if not isinstance(value, typo):
            if value == None:
                sys.stderr.write('{} missing\n'.format(name))
                print result.keys()
            else:
                sys.stderr.write('{} is not a {}\n'.format(name, typo))
                lose()
            return None
        return value

    check_result_type(u'root_node_id', unicode)

    num_source_trees = check_result_type(u'num_source_trees', int)
    if num_source_trees != None and num_source_trees < 2:
        sys.stderr.write('not very many source trees: {}\n'.format(num_source_trees))
        lose()

    check_result_type(u'date_completed', unicode)

    num_tips = check_result_type(u'num_tips', int)
    if num_tips != None and num_tips < 3:
        sys.stderr.write('not very many tips: {}\n'.format(num_tips))
        lose()

    check_result_type(u'taxonomy_version', unicode)

    num_source_trees = check_result_type(u'num_source_trees', int)
    if num_source_trees != None and num_source_trees < 2:
        sys.stderr.write('not very trees: {}\n'.format(num_source_trees))
        lose()

    num_source_studies = check_result_type(u'num_source_studies', int)
    if num_source_studies != None and num_source_studies < 2:
        sys.stderr.write('not very studies: {}\n'.format(num_source_studies))
        lose()

    check_result_type(u'filtered_flags', list)

    if u'root_ott_id' in result:
        check_result_type(u'root_ott_id', int)
        check_result_type(u'root_taxon_name', unicode)

    source_list = parameters.get(u'source_list')
    if source_list == None or not source_list:
        if u'sources' in result:
            sys.stderr.write('source_list false but there are sources in result: {}\n'.format(source_list))
            lose()
    else:
        sources = check_result_type(u'sources', list)
        metas = check_result_type(u'source_id_map', dict)
        if sources != None:
            for source in sources:
                if not isinstance(source, unicode):
                    sys.stderr.write('ill-formed source: {} should be a string\n'.format(source))
                    lose()
                    break
        if metas != None:
            for label in metas.keys():
                meta = metas[label]
                if label == u'taxonomy':
                    True
                elif (isinstance(meta, dict) and
                    u'study_id' in meta and
                    u'tree_id' in meta):
                    True
                else:
                    sys.stderr.write('ill-formed meta: {} should be {}"study_id": ..., "tree_id": ...{}\n'.format(meta, '{', '}'))
                    lose()
                    break
    sys.exit(code[0])
#!/usr/bin/env python
from opentreetesting import test_http_json_method, config
from peyotl import convert_nexson_format
import datetime
import codecs
import json
import sys
import os

# this makes it easier to test concurrent pushes to different branches
study_id = 12

DOMAIN = config('host', 'apihost')
starting_commit_SHA = config('host', 'parentsha')

SUBMIT_URI = DOMAIN + '/v1/study/%s' % study_id
fn = 'data/{s}.json'.format(s=study_id)
inpf = codecs.open(fn, 'rU', encoding='utf-8')
n = json.load(inpf)
# refresh a timestamp so that the test generates a commit
m = n['nexml']['meta']
short_list = [i for i in m if i.get('@property') == 'bogus_timestamp']
if short_list:
    el = short_list[0]
else:
    el = {'@property': 'bogus_timestamp', '@xsi:type': 'nex:LiteralMeta'}
    m.append(el)
el['$'] = datetime.datetime.utcnow().isoformat()
n = convert_nexson_format(n, '1.2')

data = { 'nexson' : n,
Ejemplo n.º 13
0
#!/usr/bin/env python

# export PYTHONPATH=~/a/ot/repo/germinator/ws-tests
# python ws-tests/test_v3_addition.py host:apihost="http://localhost:7476" host:translate=true

import sys, requests, opentreetesting, json

from check import *

opentreetesting.exit_if_api_is_readonly('test_v3_addition.py')

# Find an unused OTT id

id = 99000000

DOMAIN = opentreetesting.config('host', 'apihost')

while True:
    response = requests.request('POST',
                                opentreetesting.translate(DOMAIN + '/v3/taxonomy/taxon_info'),
                                headers={'content-type' : 'application/json'},
                                data=json.dumps({'ott_id': id}),
                                allow_redirects=True)
    if response.status_code != 200:
        print 'id %s is unused' % id
        break
    # print 'id %s is in use' % id
    id += 10

name1 = "Test taxon 1"
name2 = "Test taxon 2"
Ejemplo n.º 14
0
#!/usr/bin/env python
import sys
import requests
import json
#curl -X POST http://opentree-dev.bio.ku.edu:7474/ext/TNRS/graphdb/doTNRSForNames -H "Content-Type: Application/json" -d '{"queryString": "Pan trodlogytes, H**o sapphire, Plantago, Morpho peleides, Eleocharis"}'
from opentreetesting import config
DOMAIN = config('host', 'tnrshost')



SUBMIT_URI = DOMAIN + '/ext/TNRS/graphdb/doTNRSForNames'
payload = {
    "queryString": "Pan trodlogytes, H**o sapphire, Plantago, Morpho peleides, Eleocharis",
    "contextName": "All life"
}
if len(sys.argv) > 1:
    payload['queryString'] = ', '.join(sys.argv[1:])

headers = {
    'content-type' : 'application/json',
    'accept' : 'application/json',
}
resp = requests.post(SUBMIT_URI,
                     headers=headers,
                     data=json.dumps(payload),
                     allow_redirects=True)
sys.stderr.write('Sent POST to %s\n' %(resp.url))
resp.raise_for_status()
try:
    results = resp.json()
    print 'results =', str(results)
Ejemplo n.º 15
0
def check_about(parameters):

    DOMAIN = config('host', 'apihost')
    SUBMIT_URI = DOMAIN + '/v3/tree_of_life/about'
    test, result, _ = test_http_json_method(SUBMIT_URI,
                                            "POST",
                                            data=parameters,
                                            expected_status=200,
                                            return_bool_data=True)
    if not test:
        sys.exit(1)
    """ Doc says:
    "synth_id" : "opentree4.1",
      "root_node_id" : "ott93302",    # in v2 this was an integer
      "num_source_trees" : 484,
      "date_completed" : "2016-02-09 18:14:43",
      "taxonomy_version" : "2.9draft12",
      "num_tips" : 2424255,
      "num_source_studies" : 478,
      "filtered_flags" : [ "major_rank_conflict", "major_rank_conflict_inherited", "environmental", "unclassified_inherited", "unclassified", "viral", "barren", "not_otu", "incertae_sedis", "incertae_sedis_inherited", "extinct_inherited", "extinct", "hidden", "unplaced", "unplaced_inherited", "was_container", "inconsistent", "hybrid", "merged" ],

      "root_ott_id" : 93302
      "root_taxon_name" : "cellular organisms",

      maybe: "root_taxon" : { ... }

    """

    code = [0]

    def lose():
        code[0] = 1

    def check_result_type(name, typo):
        value = result.get(name)
        if not isinstance(value, typo):
            if value == None:
                sys.stderr.write('{} missing\n'.format(name))
                print result.keys()
            else:
                sys.stderr.write('{} is not a {}\n'.format(name, typo))
                lose()
            return None
        return value

    check_result_type(u'root_node_id', unicode)

    num_source_trees = check_result_type(u'num_source_trees', int)
    if num_source_trees != None and num_source_trees < 2:
        sys.stderr.write(
            'not very many source trees: {}\n'.format(num_source_trees))
        lose()

    check_result_type(u'date_completed', unicode)

    num_tips = check_result_type(u'num_tips', int)
    if num_tips != None and num_tips < 3:
        sys.stderr.write('not very many tips: {}\n'.format(num_tips))
        lose()

    check_result_type(u'taxonomy_version', unicode)

    num_source_trees = check_result_type(u'num_source_trees', int)
    if num_source_trees != None and num_source_trees < 2:
        sys.stderr.write('not very trees: {}\n'.format(num_source_trees))
        lose()

    num_source_studies = check_result_type(u'num_source_studies', int)
    if num_source_studies != None and num_source_studies < 2:
        sys.stderr.write('not very studies: {}\n'.format(num_source_studies))
        lose()

    check_result_type(u'filtered_flags', list)

    if u'root_ott_id' in result:
        check_result_type(u'root_ott_id', int)
        check_result_type(u'root_taxon_name', unicode)

    source_list = parameters.get(u'source_list')
    if source_list == None or not source_list:
        if u'sources' in result:
            sys.stderr.write(
                'source_list false but there are sources in result: {}\n'.
                format(source_list))
            lose()
    else:
        sources = check_result_type(u'sources', list)
        metas = check_result_type(u'source_id_map', dict)
        if sources != None:
            for source in sources:
                if not isinstance(source, unicode):
                    sys.stderr.write(
                        'ill-formed source: {} should be a string\n'.format(
                            source))
                    lose()
                    break
        if metas != None:
            for label in metas.keys():
                meta = metas[label]
                if label == u'taxonomy':
                    True
                elif (isinstance(meta, dict) and u'study_id' in meta
                      and u'tree_id' in meta):
                    True
                else:
                    sys.stderr.write(
                        'ill-formed meta: {} should be {}"study_id": ..., "tree_id": ...{}\n'
                        .format(meta, '{', '}'))
                    lose()
                    break
    sys.exit(code[0])