1212from iib .workers .tasks import build
1313from iib .workers .tasks .utils import RequestConfigAddRm
1414from iib .workers .config import get_worker_config
15+ from iib .common .pydantic_models import AddPydanticModel , RmPydanticModel
1516from operator_manifest .operator import ImageName
1617
1718worker_config = get_worker_config ()
@@ -622,7 +623,9 @@ def test_buildah_fail_max_retries(mock_run_cmd: mock.MagicMock) -> None:
622623@mock .patch ('iib.workers.tasks.build._get_present_bundles' )
623624@mock .patch ('iib.workers.tasks.build.set_registry_token' )
624625@mock .patch ('iib.workers.tasks.build.is_image_fbc' )
626+ @mock .patch ('iib.common.pydantic_models.binary_image_check' )
625627def test_handle_add_request (
628+ mock_binary_image_check ,
626629 mock_iifbc ,
627630 mock_srt ,
628631 mock_gpb ,
@@ -692,24 +695,24 @@ def side_effect(*args, base_dir, **kwargs):
692695 mock_ors .return_value = (port , my_mock )
693696 mock_run_cmd .return_value = '{"packageName": "package1", "version": "v1.0", \
694697 "bundlePath": "bundle1"\n }'
695-
696- build .handle_add_request (
697- bundles ,
698- 3 ,
699- binary_image ,
700- 'from-index:latest' ,
701- ['s390x' ],
702- cnr_token ,
703- organization ,
704- force_backport ,
705- False ,
706- None ,
707- None ,
708- greenwave_config ,
709- binary_image_config = binary_image_config ,
698+ add_pydantic_model = AddPydanticModel .model_construct (
699+ bundles = bundles ,
700+ binary_image = binary_image ,
701+ from_index = 'from_index:latest' ,
702+ cnr_token = cnr_token ,
703+ organization = organization ,
704+ force_backport = force_backport ,
705+ overwrite_from_index = False ,
706+ overwrite_from_index_token = None ,
710707 deprecation_list = deprecation_list ,
711708 build_tags = ["extra_tag1" , "extra_tag2" ],
712709 )
710+ build .handle_add_request (
711+ payload = add_pydantic_model ,
712+ request_id = 3 ,
713+ greenwave_config = greenwave_config ,
714+ binary_image_config = binary_image_config ,
715+ )
713716
714717 mock_ors .assert_called_once ()
715718 mock_run_cmd .assert_called_once ()
@@ -778,21 +781,24 @@ def side_effect(*args, base_dir, **kwargs):
778781def test_handle_add_request_raises (mock_iifbc , mock_runcmd , mock_c ):
779782 mock_iifbc .return_value = True
780783 with pytest .raises (IIBError ):
781- build . handle_add_request (
784+ add_pydantic_model = AddPydanticModel . model_construct (
782785 bundles = ['some-bundle:2.3-1' , 'some-deprecation-bundle:1.1-1' ],
783- request_id = 3 ,
784786 binary_image = 'binary-image:latest' ,
785- from_index = 'from-index:latest' ,
786787 add_arches = ['s390x' ],
788+ from_index = 'from_index:latest' ,
787789 cnr_token = 'token' ,
788790 organization = 'org' ,
789791 force_backport = True ,
790792 overwrite_from_index = False ,
791793 overwrite_from_index_token = None ,
792794 distribution_scope = None ,
795+ deprecation_list = [],
796+ )
797+ build .handle_add_request (
798+ payload = add_pydantic_model ,
799+ request_id = 3 ,
793800 greenwave_config = {'some_key' : 'other_value' },
794801 binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
795- deprecation_list = [],
796802 )
797803
798804
@@ -897,21 +903,24 @@ def deprecate_bundles_mock(*args, **kwargs):
897903 ]
898904 mock_sqlite .execute .return_value = 200
899905
906+ add_pydantic_model = AddPydanticModel .model_construct (
907+ bundles = bundles ,
908+ binary_image = 'binary-image:latest' ,
909+ add_arches = ['s390x' ],
910+ from_index = 'from_index:latest' ,
911+ cnr_token = cnr_token ,
912+ organization = organization ,
913+ force_backport = True ,
914+ overwrite_from_index = False ,
915+ overwrite_from_index_token = None ,
916+ distribution_scope = None ,
917+ deprecation_list = deprecation_list ,
918+ )
900919 build .handle_add_request (
901- bundles ,
902- 3 ,
903- 'binary-image:latest' ,
904- 'from-index:latest' ,
905- ['s390x' ],
906- cnr_token ,
907- organization ,
908- True ,
909- False ,
910- None ,
911- None ,
912- greenwave_config ,
920+ payload = add_pydantic_model ,
921+ request_id = 3 ,
922+ greenwave_config = greenwave_config ,
913923 binary_image_config = binary_image_config ,
914- deprecation_list = deprecation_list ,
915924 )
916925
917926 mock_ors .assert_called_once ()
@@ -983,19 +992,21 @@ def test_handle_add_request_gating_failure(
983992 organization = 'org'
984993 greenwave_config = {'some_key' : 'other_value' }
985994 with pytest .raises (IIBError , match = error_msg ):
995+ add_pydantic_model = AddPydanticModel .model_construct (
996+ bundles = bundles ,
997+ binary_image = 'binary-image:latest' ,
998+ add_arches = ['s390x' ],
999+ from_index = 'from_index:latest' ,
1000+ cnr_token = cnr_token ,
1001+ organization = organization ,
1002+ overwrite_from_index = False ,
1003+ overwrite_from_index_token = None ,
1004+ distribution_scope = None ,
1005+ )
9861006 build .handle_add_request (
987- bundles ,
988- 'binary-image:latest' ,
989- 3 ,
990- 'from-index:latest' ,
991- ['s390x' ],
992- cnr_token ,
993- organization ,
994- None ,
995- False ,
996- None ,
997- None ,
998- greenwave_config ,
1007+ payload = add_pydantic_model ,
1008+ request_id = 3 ,
1009+ greenwave_config = greenwave_config ,
9991010 )
10001011 assert mock_cleanup .call_count == 1
10011012 mock_srs2 .assert_called_once ()
@@ -1014,17 +1025,20 @@ def test_handle_add_request_bundle_resolution_failure(mock_grb, mock_srs, mock_c
10141025 organization = 'org'
10151026 greenwave_config = {'some_key' : 'other_value' }
10161027 with pytest .raises (IIBError , match = error_msg ):
1028+ add_pydantic_model = AddPydanticModel .model_construct (
1029+ bundles = bundles ,
1030+ binary_image = 'binary-image:latest' ,
1031+ add_arches = ['s390x' ],
1032+ from_index = 'from_index:latest' ,
1033+ cnr_token = cnr_token ,
1034+ organization = organization ,
1035+ force_backport = False ,
1036+ overwrite_from_index = False ,
1037+ overwrite_from_index_token = None ,
1038+ )
10171039 build .handle_add_request (
1018- bundles ,
1019- 'binary-image:latest' ,
1020- 3 ,
1021- 'from-index:latest' ,
1022- ['s390x' ],
1023- cnr_token ,
1024- organization ,
1025- False ,
1026- False ,
1027- None ,
1040+ payload = add_pydantic_model ,
1041+ request_id = 3 ,
10281042 greenwave_config = greenwave_config ,
10291043 )
10301044 assert mock_cleanup .call_count == 1
@@ -1073,11 +1087,14 @@ def test_handle_rm_request(
10731087 'distribution_scope' : 'PROD' ,
10741088 }
10751089 binary_image_config = {'prod' : {'v4.6' : 'some_image' }}
1090+ rm_pydantic_model = RmPydanticModel .model_construct (
1091+ operators = ['some_operator' ],
1092+ from_index = 'from-index:latest' ,
1093+ binary_image = binary_image ,
1094+ )
10761095 build .handle_rm_request (
1077- ['some-operator' ],
1078- 3 ,
1079- 'from-index:latest' ,
1080- binary_image ,
1096+ payload = rm_pydantic_model ,
1097+ request_id = 3 ,
10811098 binary_image_config = binary_image_config ,
10821099 )
10831100
@@ -1162,11 +1179,14 @@ def test_handle_rm_request_fbc(
11621179 mock_om .return_value = "/tmp/xyz/catalog"
11631180 mock_orrf .return_value = "/tmp/fbc_dir" , "/tmp/cache_dir"
11641181 mock_gcd .return_value = "/some/path"
1165- build .handle_rm_request (
1166- operators = ['some-operator' ],
1167- request_id = 5 ,
1182+ rm_pydantic_model = RmPydanticModel .model_construct (
1183+ operators = ['some_operator' ],
11681184 from_index = 'from-index:latest' ,
11691185 binary_image = 'binary-image:latest' ,
1186+ )
1187+ build .handle_rm_request (
1188+ payload = rm_pydantic_model ,
1189+ request_id = 5 ,
11701190 binary_image_config = {'prod' : {'v4.6' : 'some_image' }},
11711191 )
11721192 mock_prfb .assert_called_once_with (
@@ -1446,9 +1466,8 @@ def test_handle_add_request_check_related_images_fail(
14461466 mock_grb .return_value = ['some-bundle@sha256:123' ]
14471467 mock_iri .side_effect = IIBError (error_msg )
14481468 with pytest .raises (IIBError , match = re .escape (error_msg )):
1449- build . handle_add_request (
1469+ add_pydantic_model = AddPydanticModel . model_construct (
14501470 bundles = bundles ,
1451- request_id = 3 ,
14521471 binary_image = 'binary-image:latest' ,
14531472 from_index = 'from-index:latest' ,
14541473 add_arches = ['s390x' ],
@@ -1458,13 +1477,17 @@ def test_handle_add_request_check_related_images_fail(
14581477 overwrite_from_index = False ,
14591478 overwrite_from_index_token = None ,
14601479 distribution_scope = None ,
1461- greenwave_config = None ,
1462- binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
14631480 deprecation_list = [],
14641481 build_tags = None ,
14651482 graph_update_mode = None ,
14661483 check_related_images = True ,
14671484 )
1485+ build .handle_add_request (
1486+ payload = add_pydantic_model ,
1487+ request_id = 3 ,
1488+ greenwave_config = None ,
1489+ binary_image_config = {'prod' : {'v4.5' : 'some_image' }},
1490+ )
14681491 assert mock_cleanup .call_count == 1
14691492 mock_srs .assert_called_once ()
14701493 mock_grb .assert_called_once_with (bundles )
0 commit comments