Ejemplo n.º 1
0
def test_post_json_write_local_file():
    url = pj(tmp_dir, "toto.json")
    data = dict(toto=1)
    post_json(url, data)

    with open(url, 'r') as f:
        new_data = json.load(f)

    assert id(data) != id(new_data)
    assert data == new_data
Ejemplo n.º 2
0
def test_server_delete():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    del_pth = pj(wdir, wait_for_content(answer_file, NB)['args']['urldelete'])

    post_json(del_pth, dict())

    oas.join()

    assert not exists(del_pth)
Ejemplo n.º 3
0
def test_post_json_raise_error_if_non_serializable_data():
    url = pj(tmp_dir, "toto.json")

    def my_func(x):
        return x

    assert_raises(TypeError, lambda: post_json(url, my_func))
Ejemplo n.º 4
0
def test_server_ping():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    ping_pth = pj(wdir, get_json(answer_file)['args']['urlping'])
    remove(answer_file)

    post_json(ping_pth, dict(url=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['state'] == 'waiting',
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
    assert not exists(ping_pth)
Ejemplo n.º 5
0
def test_server_do_not_react_to_unknown_files():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    post_json(pj(wdir, "takapouet.cmd"), dict(a=1))

    ping_pth = pj(wdir, get_json(answer_file)['args']['urlping'])
    remove(answer_file)

    post_json(ping_pth, dict(url=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['state'] == 'waiting',
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
Ejemplo n.º 6
0
def test_server_compute():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    cpt_pth = pj(wdir, get_json(answer_file)['args']['url'])
    remove(answer_file)

    post_json(cpt_pth, dict(workflow="pycode:def main(a): return a",
                            urldata="a = 1",
                            urlreturn=answer_file))

    ans = wait_for_content(answer_file, NB)
    res = [ans['result'] == 1,
           ans['id'] == "doofus"]

    oas.stop()
    oas.join()

    assert all(res)
    assert not exists(cpt_pth)
Ejemplo n.º 7
0
def test_server_full_life():
    answer_file = pj(tmp_dir, "answer.json")

    oas = OAServerFile("doofus", wdir)
    oas.start()
    oas.register(answer_file)

    ans = wait_for_content(answer_file, NB)
    cpt_pth = pj(wdir, ans['args']['url'])
    ping_pth = pj(wdir, ans['args']['urlping'])
    del_pth = pj(wdir, ans['args']['urldelete'])

    res = []
    for a in (1, 2):
        post_json(cpt_pth, dict(workflow="pycode:" + pycode,
                                urldata="a = %d" % a,
                                urlreturn=answer_file))

        answer_ping = pj(tmp_dir, "answer_ping.json")
        post_json(ping_pth, dict(url=answer_ping))
        ans = wait_for_content(answer_ping, NB)
        res.append(ans['id'] == "doofus")
        res.append(ans['state'] in ('running', 'waiting'))

        ans = wait_for_content(answer_file, NB)
        res.append(ans['result'] == a)
        res.append(ans['id'] == "doofus")

        answer_ping = pj(tmp_dir, "answer_ping.json")
        post_json(ping_pth, dict(url=answer_ping))
        ans = wait_for_content(answer_ping, NB)
        res.append(ans['id'] == "doofus")
        res.append(ans['state'] == 'waiting')

    post_json(del_pth, dict())

    oas.join()
Ejemplo n.º 8
0
 def cr_file():
     post_json(tmp_file, "data")
Ejemplo n.º 9
0
def test_post_json_raise_error_if_bad_location():
    url = pj(tmp_dir, "titi", "toto.json")
    assert_raises(URLError, lambda: post_json(url, None))
Ejemplo n.º 10
0
 def cr_file():
     post_json(tmp_file, "toto")
Ejemplo n.º 11
0
 def cr_file():
     post_json(tmp_file, big_data)