Exemple #1
0
def test_async_call_task_without_huey(client):
    class FailHuey:
        def __getattr__(self, item):
            raise ModuleNotFoundError()

    import huey

    previous_api = huey.api
    huey.api = FailHuey()
    response = client.get("/foo/bar")
    status_url = assert_202_regex(response, "/foo/bar/status/.*")
    assert re.match("http://localhost/foo/bar/status/.*", response.json["url"])
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/bar/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.json == {"status": "why not", "foo": "bar"}

    response = client.get("/foo/bar2")
    status_url = assert_202_regex(response, "/foo/bar2/status/.*")
    assert re.match("http://localhost/foo/bar2/status/.*", response.json["url"])
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/bar2/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.json == [{"status2": "why not2", "foo2": "bar2"}]
    huey.api = previous_api
Exemple #2
0
def test_async_call_with_path_parameters_and_modified_response(client):
    response = client.get("/foo/path_parameters/tests/2")
    status_url = assert_202_regex(response, "/foo/path_parameters/tests/2/status/.*")
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/path_parameters/tests/2/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.get_data(as_text=True) == "tests: 6"
Exemple #3
0
def test_async_call_with_modified_response(client):
    response = client.get("/foo/modified_task_result")
    status_url = assert_202_regex(response, "/foo/modified_task_result/status/.*")
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/modified_task_result/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.get_data(as_text=True) == "6\n"
Exemple #4
0
def test_custom_exception_raised_and_propagated(client):
    response = client.get("/foo/custom_exception")
    status_url = assert_202_regex(response, ".*")
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, ".*")
    result = client.get(result_url)
    assert result.status_code == 500
    assert result.json == {"message": "Custom exception"}
Exemple #5
0
def test_async_call_without_serialization(client):
    response = client.get("/foo/csv")
    status_url = assert_202_regex(response, "/foo/csv/status/.*")
    assert re.match("http://localhost/foo/csv/status/.*", response.json["url"])
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/csv/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.get_data(as_text=True) == "a;b;c"
Exemple #6
0
def test_async_call_task(client):
    response = client.get("/foo/bar")
    status_url = assert_202_regex(response, "/foo/bar/status/.*")
    assert re.match("http://localhost/foo/bar/status/.*", response.json["url"])
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/bar/result/.*")
    result_reply = client.get(result_url)
    assert result_reply.status_code == 200
    assert result_reply.json == {"status": "why not", "foo": "bar"}

    response = client.get("/foo/bar2")
    status_url = assert_202_regex(response, "/foo/bar2/status/.*")
    assert re.match("http://localhost/foo/bar2/status/.*", response.json["url"])
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, "/foo/bar2/result/.*")
    result_reply = client.get(result_url)
    assert result_reply == 200
    assert result_reply.json == [{"status2": "why not2", "foo2": "bar2"}]
Exemple #7
0
def test_exception_raised_and_propagated(client):
    response = client.get("/foo/exception")
    status_url = assert_202_regex(response, ".*")
    status_reply = client.get(status_url)
    result_url = assert_303_regex(status_reply, ".*")
    assert client.get(result_url).status_code == 500