Пример #1
0
def test_iib_client_no_overwrite_from_index_or_token(
    fixture_add_build_details_json, fixture_rm_build_details_json
):
    error_msg = (
        "Either both or neither of overwrite-from-index "
        "and overwrite-from-index-token should be specified."
    )
    with requests_mock.Mocker() as m:
        m.register_uri(
            "POST",
            "/api/v1/builds/add",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        m.register_uri(
            "POST",
            "/api/v1/builds/rm",
            status_code=200,
            json=fixture_rm_build_details_json,
        )
        iibc = IIBClient("fake-host")
        with pytest.raises(ValueError, match=error_msg):
            iibc.remove_operators(
                "index-image",
                ["operator1"],
                [],
                binary_image="binary",
                overwrite_from_index=True,
            )
        with pytest.raises(ValueError, match=error_msg):
            iibc.remove_operators(
                "index-image",
                ["operator1"],
                [],
                binary_image="binary",
                overwrite_from_index_token="str",
            )
        with pytest.raises(ValueError, match=error_msg):
            iibc.add_bundles(
                "index-image",
                ["bundles-map"],
                [],
                binary_image="binary",
                cnr_token="cnr",
                organization="org",
                overwrite_from_index=True,
            )
        with pytest.raises(ValueError, match=error_msg):
            iibc.add_bundles(
                "index-image",
                ["bundles-map"],
                [],
                binary_image="binary",
                cnr_token="cnr",
                organization="org",
                overwrite_from_index_token="str",
            )
Пример #2
0
def test_iib_client_deprecation_list(
    fixture_add_build_details_json,
    fixture_deprecation_list_build_details_json,
):
    with requests_mock.Mocker() as m:
        m.register_uri(
            "POST",
            "/api/v1/builds/add",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        iibc = IIBClient("fake-host")
        assert iibc.add_bundles(
            "index-image", ["bundles-map"], [], binary_image="binary"
        ) == AddModel.from_dict(fixture_add_build_details_json)

        assert (
            iibc.add_bundles(
                "index-image",
                ["bundles-map"],
                [],
                binary_image="binary",
                cnr_token="cnr",
                organization="org",
                overwrite_from_index=True,
                overwrite_from_index_token="str",
            )
            == AddModel.from_dict(fixture_add_build_details_json)
        )

    with requests_mock.Mocker() as m:
        m.register_uri(
            "POST",
            "/api/v1/builds/add",
            status_code=200,
            json=fixture_deprecation_list_build_details_json,
        )
        iibc = IIBClient("fake-host")

        assert (
            iibc.add_bundles(
                "index-image",
                ["bundles-map"],
                [],
                binary_image="binary",
                cnr_token="cnr",
                deprecation_list=["deprecation_list"],
                organization="org",
                overwrite_from_index=True,
                overwrite_from_index_token="str",
            )
            == AddModel.from_dict(fixture_deprecation_list_build_details_json)
        )
Пример #3
0
def test_iib_client(
    fixture_add_build_details_json,
    fixture_rm_build_details_json,
    fixture_regenerate_bundle_build_details_json,
    fixture_create_empty_index_build_details_json,
    fixture_builds_page1_json,
):
    with requests_mock.Mocker() as m:
        m.register_uri(
            "POST",
            "/api/v1/builds/add",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        m.register_uri(
            "POST",
            "/api/v1/builds/rm",
            status_code=200,
            json=fixture_rm_build_details_json,
        )

        m.register_uri(
            "POST",
            "/api/v1/builds/regenerate-bundle",
            status_code=200,
            json=fixture_regenerate_bundle_build_details_json,
        )
        m.register_uri(
            "POST",
            "/api/v1/builds/create-empty-index",
            status_code=200,
            json=fixture_create_empty_index_build_details_json,
        )
        m.register_uri(
            "GET", "/api/v1/builds", status_code=200, json=fixture_builds_page1_json
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/1",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/2",
            status_code=200,
            json=fixture_rm_build_details_json,
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/3",
            status_code=200,
            json=fixture_regenerate_bundle_build_details_json,
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/4",
            status_code=200,
            json=fixture_create_empty_index_build_details_json,
        )

        iibc = IIBClient("fake-host")
        ret = iibc.add_bundles(
            "index-image", ["bundles-map"], [], binary_image="binary"
        )
        assert ret == AddModel.from_dict(fixture_add_build_details_json)
        ret = iibc.add_bundles(
            "index-image",
            ["bundles-map"],
            [],
            binary_image="binary",
            cnr_token="cnr",
            organization="org",
            overwrite_from_index=True,
            overwrite_from_index_token="str",
            build_tags=["extra-tag1"],
        )
        assert ret == AddModel.from_dict(fixture_add_build_details_json)
        assert (
            iibc.add_bundles(
                "index-image",
                ["bundles-map"],
                [],
                binary_image="binary",
                raw=True,
            )
            == fixture_add_build_details_json
        )
        assert (
            iibc.remove_operators(
                "index-image",
                ["operator1"],
                [],
                binary_image="binary",
                build_tags=["v4.5-2020-10-10"],
                overwrite_from_index=True,
                overwrite_from_index_token="str",
            )
            == RmModel.from_dict(fixture_rm_build_details_json)
        )
        assert (
            iibc.remove_operators(
                "index-image", ["operator1"], [], binary_image="binary", raw=True
            )
            == fixture_rm_build_details_json
        )

        assert iibc.regenerate_bundle(
            bundle_image="bundle_image",
            organization="organization",
        ) == RegenerateBundleModel.from_dict(
            fixture_regenerate_bundle_build_details_json
        )
        assert (
            iibc.regenerate_bundle(
                bundle_image="bundle_image", organization="organization", raw=True
            )
            == fixture_regenerate_bundle_build_details_json
        )

        assert iibc.create_empty_index(
            index_image="from_index",
            binary_image="binary_image",
            labels={"version": "v1"},
        ) == CreateEmptyIndexModel.from_dict(
            fixture_create_empty_index_build_details_json
        )
        assert (
            iibc.create_empty_index(
                index_image="from_index",
                binary_image="binary_image",
                labels={"version": "v1"},
                raw=True,
            )
            == fixture_create_empty_index_build_details_json
        )

        # get_builds - request_type is "add"
        assert iibc.get_build(1) == IIBBuildDetailsModel.from_dict(
            fixture_add_build_details_json
        )
        assert iibc.get_build(1, raw=True) == fixture_add_build_details_json

        # get_builds - request_type is "rm"
        assert iibc.get_build(2) == IIBBuildDetailsModel.from_dict(
            fixture_rm_build_details_json
        )
        assert iibc.get_build(2, raw=True) == fixture_rm_build_details_json

        # get_builds - request_type is "regenerate-bundle"
        assert iibc.get_build(3) == IIBBuildDetailsModel.from_dict(
            fixture_regenerate_bundle_build_details_json
        )
        assert (
            iibc.get_build(3, raw=True) == fixture_regenerate_bundle_build_details_json
        )
        # get_builds - request_type is "create-empty-index"
        assert iibc.get_build(4) == IIBBuildDetailsModel.from_dict(
            fixture_create_empty_index_build_details_json
        )
        assert (
            iibc.get_build(4, raw=True) == fixture_create_empty_index_build_details_json
        )

        assert iibc.get_builds() == IIBBuildDetailsPager.from_dict(
            iibc, fixture_builds_page1_json
        )
        assert iibc.get_builds(raw=True) == fixture_builds_page1_json
Пример #4
0
def test_iib_client(
    fixture_add_build_details_json,
    fixture_rm_build_details_json,
    fixture_regenerate_bundle_build_details_json,
    fixture_builds_page1_json,
):
    with requests_mock.Mocker() as m:
        m.register_uri(
            "POST",
            "/api/v1/builds/add",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        m.register_uri(
            "POST",
            "/api/v1/builds/rm",
            status_code=200,
            json=fixture_rm_build_details_json,
        )

        m.register_uri(
            "POST",
            "/api/v1/builds/regenerate-bundle",
            status_code=200,
            json=fixture_regenerate_bundle_build_details_json,
        )
        m.register_uri("GET",
                       "/api/v1/builds",
                       status_code=200,
                       json=fixture_builds_page1_json)
        m.register_uri(
            "GET",
            "/api/v1/builds/1",
            status_code=200,
            json=fixture_add_build_details_json,
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/2",
            status_code=200,
            json=fixture_rm_build_details_json,
        )
        m.register_uri(
            "GET",
            "/api/v1/builds/3",
            status_code=200,
            json=fixture_regenerate_bundle_build_details_json,
        )

        iibc = IIBClient("fake-host")
        assert iibc.add_bundles("index-image", ["bundles-map"], [],
                                binary_image="binary") == AddModel.from_dict(
                                    fixture_add_build_details_json)
        assert (iibc.add_bundles(
            "index-image",
            ["bundles-map"],
            [],
            binary_image="binary",
            cnr_token="cnr",
            organization="org",
            overwrite_from_index=True,
            overwrite_from_index_token="str",
        ) == AddModel.from_dict(fixture_add_build_details_json))
        assert (iibc.add_bundles("index-image", ["bundles-map"], [],
                                 binary_image="binary",
                                 raw=True) == fixture_add_build_details_json)
        assert (iibc.remove_operators(
            "index-image",
            ["operator1"],
            [],
            binary_image="binary",
            overwrite_from_index=True,
            overwrite_from_index_token="str",
        ) == RmModel.from_dict(fixture_rm_build_details_json))
        assert (iibc.remove_operators(
            "index-image", ["operator1"], [], binary_image="binary",
            raw=True) == fixture_rm_build_details_json)

        assert iibc.regenerate_bundle(
            bundle_image="bundle_image",
            organization="organization",
        ) == RegenerateBundleModel.from_dict(
            fixture_regenerate_bundle_build_details_json)
        assert (iibc.regenerate_bundle(
            bundle_image="bundle_image", organization="organization",
            raw=True) == fixture_regenerate_bundle_build_details_json)

        # get_builds - request_type is "add"
        assert iibc.get_build(1) == IIBBuildDetailsModel.from_dict(
            fixture_add_build_details_json)
        assert iibc.get_build(1, raw=True) == fixture_add_build_details_json

        # get_builds - request_type is "rm"
        assert iibc.get_build(2) == IIBBuildDetailsModel.from_dict(
            fixture_rm_build_details_json)
        assert iibc.get_build(2, raw=True) == fixture_rm_build_details_json

        # get_builds - request_type is "regenerate-bundle"
        assert iibc.get_build(3) == IIBBuildDetailsModel.from_dict(
            fixture_regenerate_bundle_build_details_json)
        assert (iibc.get_build(
            3, raw=True) == fixture_regenerate_bundle_build_details_json)

        assert iibc.get_builds() == IIBBuildDetailsPager.from_dict(
            iibc, fixture_builds_page1_json)
        assert iibc.get_builds(raw=True) == fixture_builds_page1_json