示例#1
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)
        )
def test_from_dict_success(
    fixture_add_build_details_json,
    fixture_rm_build_details_json,
    fixture_regenerate_bundle_build_details_json,
    fixture_optional_args_missing_json,
    fixture_merge_index_image_build_details_json,
):

    model1 = IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
    assert model1 == AddModel(**fixture_add_build_details_json)

    model2 = IIBBuildDetailsModel.from_dict(fixture_rm_build_details_json)
    assert model2 == RmModel(**fixture_rm_build_details_json)

    model3 = IIBBuildDetailsModel.from_dict(
        fixture_regenerate_bundle_build_details_json)
    assert model3 == RegenerateBundleModel(
        **fixture_regenerate_bundle_build_details_json)

    model4 = IIBBuildDetailsModel.from_dict(fixture_optional_args_missing_json)
    assert model4 == RegenerateBundleModel(
        **fixture_optional_args_missing_json)

    model5 = IIBBuildDetailsModel.from_dict(
        fixture_merge_index_image_build_details_json)
    assert model5 == MergeIndexImageModel(
        **fixture_merge_index_image_build_details_json)
def test_add_model_attributes(fixture_add_build_details_json):
    model = AddModel.from_dict(fixture_add_build_details_json)

    assert model.binary_image == model._data["binary_image"]
    assert model.binary_image_resolved == model._data["binary_image_resolved"]
    assert model.bundles == model._data["bundles"]
    assert model.bundle_mapping == model._data["bundle_mapping"]
    assert model.from_index == model._data["from_index"]
    assert model.from_index_resolved == model._data["from_index_resolved"]
    assert model.index_image == model._data["index_image"]
    assert model.removed_operators == model._data["removed_operators"]
    assert model.organization == model._data["organization"]
    assert model.omps_operator_version == model._data["omps_operator_version"]
    assert model.distribution_scope == model._data["distribution_scope"]
def test_from_dict_failure(
    fixture_add_build_details_json,
    fixture_rm_build_details_json,
    fixture_bundle_image_missing_json,
    fixture_unknown_request_type_json,
):

    key_error_msg = "Unsupported request type: unknown"
    type_error_msg = "Class AddModel doesn't accept rm request type"

    add_model_state_finished = AddModel(
        id=1,
        arches=["x86_64"],
        state="finished",
        state_reason="state_reason",
        request_type="add",
        state_history=[],
        batch=1,
        batch_annotations={"batch_annotations": 1},
        logs={},
        updated="updated",
        user="******",
        binary_image="binary_image",
        binary_image_resolved="binary_image_resolved",
        bundles=["bundles1"],
        bundle_mapping={"bundle_mapping": "map"},
        from_index="from_index",
        from_index_resolved="from_index_resolved",
        index_image="index_image",
        removed_operators=["operator1"],
        organization="organization",
        omps_operator_version={"operator": "1.0"},
        distribution_scope="null",
    )

    add_model_wrong_request_type = {
        "id": 1,
        "arches": ["x86_64"],
        "state": "in_progress",
        "state_reason": "state_reason",
        "request_type": "rm",
        "state_history": [],
        "batch": 1,
        "batch_annotations": {
            "batch_annotations": 1
        },
        "logs": {},
        "updated": "updated",
        "user": "******",
        "binary_image": "binary_image",
        "binary_image_resolved": "binary_image_resolved",
        "bundles": ["bundles1"],
        "bundle_mapping": {
            "bundle_mapping": "map"
        },
        "from_index": "from_index",
        "from_index_resolved": "from_index_resolved",
        "index_image": "index_image",
        "removed_operators": ["operator1"],
        "organization": "organization",
        "omps_operator_version": {
            "operator": "1.0"
        },
        "distribution_scope": "null",
    }

    model1 = IIBBuildDetailsModel.from_dict(fixture_add_build_details_json)
    assert model1 != add_model_state_finished

    model2 = IIBBuildDetailsModel.from_dict(fixture_rm_build_details_json)
    assert model2 != model1

    with raises(KeyError):
        IIBBuildDetailsModel.from_dict(fixture_bundle_image_missing_json)

    with raises(KeyError, match=key_error_msg):
        IIBBuildDetailsModel.from_dict(fixture_unknown_request_type_json)

    with raises(TypeError, match=type_error_msg):
        AddModel.from_dict(add_model_wrong_request_type)
示例#5
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
示例#6
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