import json
import requests
from datetime import datetime

from nose.plugins.attrib import attr

BASE = 'http://api.indra.bio:8000/'


def _call_api(method, route, *args, **kwargs):
    route = route.lstrip('/')
    req_meth = getattr(requests, method)
    start = datetime.now()
    print("Submitting request to '%s' at %s." % ('/' + route, start))
    print("\targs:", args)
    print("\tkwargs:", kwargs)
    res = req_meth(BASE + route, *args, **kwargs)
    end = datetime.now()
    print("Got result with %s at %s after %s seconds."
          % (res.status_code, end, (end-start).total_seconds()))
    assert res.status_code == 200, res.status_code
    return res


@attr('webservice')
def test_responsive():
    res = _call_api('get', '')
    assert res.content.startswith(b'This is the INDRA REST API.')


@attr('webservice')
def test_assemblers_cyjs():
    stmt_json = {
        "statements": [{
            "sbo": "http://identifiers.org/sbo/SBO:0000526",
            "type": "Complex",
            "id": "acc6d47c-f622-41a4-8ae9-d7b0f3d24a2f",
            "members": [
                {"db_refs": {"TEXT": "MEK", "FPLX": "MEK"}, "name": "MEK"},
                {"db_refs": {"TEXT": "ERK", "FPLX": "ERK"}, "name": "ERK"}
            ],
            "evidence": [{"text": "MEK binds ERK", "source_api": "trips"}]
        }]
    }
    stmt_str = json.dumps(stmt_json)
    res = _call_api('post', 'assemblers/cyjs', stmt_str)
    res_json = res.json()
    assert len(res_json['edges']) == 1, len(res_json['edges'])
    assert len(res_json['nodes']) == 2, len(res_json['nodes'])
    return

@@ -90,16 +90,62 @@
 t attr%0A%0A
+from indra.statements import stmts_from_json%0A%0A
 BASE = '
@@ -849,16 +849,695 @@
 T API.')
+, %5C%0A        %22Unexpected content: %25s%22 %25 res.content%0A%0A%0A@attr('webservice')%0Adef test_options():%0A    res = _call_api('options', '')%0A    assert res.content == b'%7B%7D', %5C%0A        %22Unexpected content: %25s%22 %25 res.content%0A%0A%0A@attr('webservice')%0Adef test_trips_process_text():%0A    res = _call_api('post', 'trips/process_text',%0A                    json=%7B'text': 'MEK phosphorylates ERK.'%7D)%0A    res_json = res.json()%0A    assert 'statements' in res_json.keys(), res_json%0A    print(res_json.keys())%0A    stmts = stmts_from_json(res_json%5B'statements'%5D)%0A    assert len(stmts) == 1, len(stmts)%0A    stmt = stmts%5B0%5D%0A    assert stmt.enz.name == 'MEK', stmt.enz%0A    assert stmt.sub.name == 'ERK', stmt.sub
 %0A%0A%0A@attr

Add a simple test of trips process text and options.