Ejemplo n.º 1
0
def test_server_compute_use_remote_in_data():
    result_url = pj(tmp_dir, "result.json")
    data_url = "http://myserver.myns/data.json"
    oas = OAServer("oas")
    oas.registered()

    with requests_mock.Mocker() as m:
        m.get(data_url, text=json.dumps({'a': 4}))
        oas.compute("pycode:def main(a): return a", data_url, result_url)
        assert get_json(result_url) == dict(id='oas', result=4)
Ejemplo n.º 2
0
def test_server_compute_use_pycode_in_data():
    result_url = pj(tmp_dir, "result.json")
    oas = OAServer("oas")
    oas.registered()

    oas.compute("pycode:def main(a): return a", "a = 1", result_url)
    assert get_json(result_url) == dict(id='oas', result=1)

    oas.compute("pycode:def main(a): return a", "code:a = 2", result_url)
    assert get_json(result_url) == dict(id='oas', result=2)
Ejemplo n.º 3
0
def test_server_compute_is_working():
    oas = OAServer("toto")
    oas.registered()

    def text_callback(request, context):
        del context
        resp = json.loads(request.text)
        assert resp["id"] == "toto"

    with requests_mock.Mocker() as m:
        m.post('http://test.com/return', text=text_callback)
        oas.compute("pycode:" + pycode, 'a=0.1', 'http://test.com/return')
Ejemplo n.º 4
0
def test_server_compute_use_local_in_data():
    result_url = pj(tmp_dir, "result.json")
    data_url = pj(tmp_dir, "data.json")
    oas = OAServer("oas")
    oas.registered()

    with open(data_url, 'w') as f:
        json.dump({'a': 3}, f)
    oas.compute("pycode:def main(a): return a",
                "file:%s" % data_url,
                result_url)
    assert get_json(result_url) == dict(id='oas', result=3)
Ejemplo n.º 5
0
def test_server_ready_to_compute():
    oas = OAServer("toto")
    assert_raises(AssertionError, lambda: oas.compute("toto", "data", "ret"))