Esempio n. 1
0
def test_client_wait_for_build(fixture_add_build_details_json):
    iibc = IIBClient("fake-host", poll_interval=1)
    bdetails_finished = copy.copy(fixture_add_build_details_json)
    bdetails_finished["state"] = "complete"
    with requests_mock.Mocker() as m:
        m.register_uri(
            "GET",
            "/api/v1/builds/1",
            [
                {"json": fixture_add_build_details_json, "status_code": 200},
                {"json": bdetails_finished, "status_code": 200},
            ],
        )
        iibc.wait_for_build(
            IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
        )

    bdetails_finished["state"] = "failed"
    with requests_mock.Mocker() as m:
        m.register_uri(
            "GET",
            "/api/v1/builds/1",
            [
                {"json": fixture_add_build_details_json, "status_code": 200},
                {"json": bdetails_finished, "status_code": 200},
            ],
        )
        iibc.wait_for_build(
            IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
        )
Esempio n. 2
0
def test_client_wait_for_build_retry(fixture_add_build_details_json):
    iibc = IIBClient("fake-host.test", poll_interval=1, retries=10, backoff_factor=0)

    with pytest.raises(
        requests.exceptions.RequestException, match=".*Max retries exceeded*."
    ):
        iibc.wait_for_build(
            IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
        )
Esempio n. 3
0
def test_client_wait_for_build_timeout(fixture_add_build_details_json):
    # set wait timeout for 2 seconds
    iibc = IIBClient("fake-host.test", poll_interval=1, wait_for_build_timeout=2)

    with requests_mock.Mocker() as m:
        m.register_uri(
            "GET",
            "/api/v1/builds/{}".format(fixture_add_build_details_json["id"]),
            status_code=200,
            json=fixture_add_build_details_json,
        )

        with pytest.raises(IIBException, match="Timeout*."):
            iibc.wait_for_build(
                IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
            )