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
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