Ejemplo n.º 1
0
def test_environmentbuildlist_post_with_error1(client, project, monkeypatch):
    monkeypatch.setattr(namespace_environment_builds, "make_celery",
                        raise_exception_function())

    data = client.post("/api/environment-builds/",
                       json=create_env_build_request(project.uuid,
                                                     1)).get_json()
    assert len(data["failed_requests"]) == 1
Ejemplo n.º 2
0
def test_environmentbuildlist_post_revert(client, project, monkeypatch):
    monkeypatch.setattr(namespace_environment_builds, "make_celery",
                        raise_exception_function())
    client.post("/api/environment-builds/",
                json=create_env_build_request(project.uuid, 1))

    data = client.get("/api/environment-builds/").get_json()
    data = data["environment_builds"][0]
    assert data["status"] == "FAILURE"
def test_environmentimage_delete_with_builds(client, celery, project,
                                             abortable_async_res):

    req = create_env_build_request(project.uuid, 1)
    env_uuid = req["environment_build_requests"][0]["environment_uuid"]
    client.post("/api/environment-builds/", json=req)

    resp = client.delete(f"/api/environment-images/{project.uuid}/{env_uuid}")
    assert resp.status_code == 200
    assert abortable_async_res.is_aborted()
    assert celery.revoked_tasks
    assert not client.get(
        "/api/environment-builds/").get_json()["environment_builds"]
Ejemplo n.º 4
0
def test_projectenvironmentmostrecentbuild_get(client, celery, project,
                                               abortable_async_res):
    req = create_env_build_request(project.uuid, 1)
    for _ in range(5):
        last_uuid = client.post(
            "/api/environment-builds/",
            json=req).get_json()["environment_builds"][0]["uuid"]

    env_uuid = req["environment_build_requests"][0]["environment_uuid"]
    data = client.get(
        f"/api/environment-builds/most-recent/{project.uuid}/{env_uuid}"
    ).get_json()
    assert data["environment_builds"][0]["uuid"] == last_uuid
Ejemplo n.º 5
0
def test_environmentbuild_delete(client, celery, project, abortable_async_res):

    data = client.post("/api/environment-builds/",
                       json=create_env_build_request(project.uuid,
                                                     1)).get_json()
    data = data["environment_builds"][0]
    assert data["status"] == "PENDING"

    env_build_uuid = data["uuid"]
    resp = client.delete(f"/api/environment-builds/{env_build_uuid}")

    assert resp.status_code == 200
    assert abortable_async_res.is_aborted()
    assert celery.revoked_tasks
Ejemplo n.º 6
0
def test_projectmostrecentbuildlist_get(client, celery, project,
                                        abortable_async_res):
    req = create_env_build_request(project.uuid, 2)
    for _ in range(5):
        data = client.post("/api/environment-builds/",
                           json=req).get_json()["environment_builds"]

    possible_uuids = [data[0]["uuid"], data[1]["uuid"]]

    data = client.get(f"/api/environment-builds/most-recent/{project.uuid}"
                      ).get_json()["environment_builds"]
    assert len(data) == 2
    assert data[0]["uuid"] in possible_uuids
    assert data[1]["uuid"] in possible_uuids
Ejemplo n.º 7
0
def test_environmentbuildlist_post(client, celery, project, monkeypatch):
    req = create_env_build_request(project.uuid, 1)
    data = client.post("/api/environment-builds/", json=req).get_json()

    assert data["failed_requests"] is None

    env = req["environment_build_requests"][0]
    env["status"] = "PENDING"
    env["started_time"] = None
    env["finished_time"] = None

    env_build = data["environment_builds"][0]
    for k, v in env.items():
        assert v == env_build[k]
Ejemplo n.º 8
0
def test_environmentbuildlist_post_with_error2(client, project, monkeypatch):
    celery = CeleryMock()
    # Make it so that only the first request will go through.
    monkeypatch.setattr(
        namespace_environment_builds,
        "make_celery",
        raise_exception_function(should_trigger=lambda: bool(celery.tasks),
                                 return_value=celery),
    )

    data = client.post("/api/environment-builds/",
                       json=create_env_build_request(project.uuid,
                                                     3)).get_json()
    assert len(data["environment_builds"]) == 3
    assert len(data["failed_requests"]) == 2
Ejemplo n.º 9
0
def test_environmentbuildlist_get(client, celery, project):
    client.post("/api/environment-builds/",
                json=create_env_build_request(project.uuid, 1))

    data = client.get("/api/environment-builds/").get_json()
    assert len(data["environment_builds"]) == 1