2121@patch ("cleanup_tags.cleanup_tags" )
2222def test_cleanup_tags_with_retry__success (mock_cleanup_tags ):
2323 """cleanup_tags succeeds on first attempt"""
24- cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID )
24+ cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID , REPOSITORY )
2525
26- mock_cleanup_tags .assert_called_once_with (GRAPHQL_API , IMAGE_ID )
26+ mock_cleanup_tags .assert_called_once_with (GRAPHQL_API , IMAGE_ID , REPOSITORY )
2727
2828
2929@patch ("cleanup_tags.cleanup_tags" )
3030def test_cleanup_tags_with_retry__success_after_one_attempt (mock_cleanup_tags ):
3131 """cleanup_tags succeeds after one retry"""
3232 mock_cleanup_tags .side_effect = [RuntimeError ("error" ), None ]
3333
34- cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID , backoff_factor = 0 )
34+ cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID , REPOSITORY , backoff_factor = 0 )
3535
3636 assert mock_cleanup_tags .call_count == 2
3737
@@ -42,7 +42,7 @@ def test_cleanup_tags_with_retry__fails(mock_cleanup_tags):
4242 mock_cleanup_tags .side_effect = RuntimeError ("error" )
4343
4444 with pytest .raises (RuntimeError ):
45- cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID , retries = 2 , backoff_factor = 0 )
45+ cleanup_tags_with_retry (GRAPHQL_API , IMAGE_ID , REPOSITORY , retries = 2 , backoff_factor = 0 )
4646
4747 assert mock_cleanup_tags .call_count == 2
4848
@@ -72,7 +72,7 @@ def test_cleanup_tags__success(
7272 [image1 , image3 ],
7373 ]
7474
75- cleanup_tags (GRAPHQL_API , "1111" )
75+ cleanup_tags (GRAPHQL_API , "1111" , REPOSITORY )
7676
7777 mock_get_image .assert_called_once_with (GRAPHQL_API , "1111" )
7878 assert mock_get_candidates_for_cleanup .call_args_list == [
@@ -81,7 +81,7 @@ def test_cleanup_tags__success(
8181 call (GRAPHQL_API , REGISTRY , REPOSITORY , "9.4-1111" ),
8282 ]
8383 mock_update_images .assert_called_once_with (
84- GRAPHQL_API , ["latest" , "9.4" , "9.4-1111" ], {image2 ["_id" ]: image2 }
84+ GRAPHQL_API , ["latest" , "9.4" , "9.4-1111" ], {image2 ["_id" ]: image2 }, REPOSITORY
8585 )
8686
8787
@@ -108,15 +108,17 @@ def test_cleanup_tags__nothing_to_cleanup(
108108 [image1 , image2 ],
109109 ]
110110
111- cleanup_tags (GRAPHQL_API , "1111" )
111+ cleanup_tags (GRAPHQL_API , "1111" , REPOSITORY )
112112
113113 mock_get_image .assert_called_once_with (GRAPHQL_API , "1111" )
114114 assert mock_get_candidates_for_cleanup .call_args_list == [
115115 call (GRAPHQL_API , REGISTRY , REPOSITORY , "latest" ),
116116 call (GRAPHQL_API , REGISTRY , REPOSITORY , "9.4" ),
117117 call (GRAPHQL_API , REGISTRY , REPOSITORY , "9.4-1111" ),
118118 ]
119- mock_update_images .assert_called_once_with (GRAPHQL_API , ["latest" , "9.4" , "9.4-1111" ], {})
119+ mock_update_images .assert_called_once_with (
120+ GRAPHQL_API , ["latest" , "9.4" , "9.4-1111" ], {}, REPOSITORY
121+ )
120122
121123
122124@patch ("pyxis.graphql_query" )
@@ -137,7 +139,7 @@ def test_get_rh_registry_image_properties__success():
137139 """
138140 image = generate_image ("1111" , "amd64" , ["latest" ])
139141
140- registry , repository , tags = get_rh_registry_image_properties (image )
142+ registry , repository , tags = get_rh_registry_image_properties (image , REPOSITORY )
141143
142144 assert registry == REGISTRY
143145 assert repository == REPOSITORY
@@ -152,13 +154,25 @@ def test_get_rh_registry_image_properties__no_tags():
152154 image ["repositories" ][0 ]["tags" ] = None
153155 image ["repositories" ][1 ]["tags" ] = None
154156
155- registry , repository , tags = get_rh_registry_image_properties (image )
157+ registry , repository , tags = get_rh_registry_image_properties (image , REPOSITORY )
156158
157159 assert registry == REGISTRY
158160 assert repository == REPOSITORY
159161 assert tags == []
160162
161163
164+ def test_get_rh_registry_image_properties__multiple_images__repository_set__success ():
165+ """Basic scenario where the function parses the image with multiple repositories
166+ and returns the expected values
167+ """
168+ image = generate_image ("1111" , "amd64" , ["latest" ], True )
169+ registry , repository , tags = get_rh_registry_image_properties (image , REPOSITORY )
170+
171+ assert registry == REGISTRY
172+ assert repository == REPOSITORY
173+ assert tags == ["latest" ]
174+
175+
162176def test_get_rh_registry_image_properties__failure ():
163177 """The Red Hat registry repository is not found in the image,
164178 so an exception is raised
@@ -176,7 +190,7 @@ def test_get_rh_registry_image_properties__failure():
176190 ]
177191
178192 with pytest .raises (RuntimeError ):
179- get_rh_registry_image_properties (image )
193+ get_rh_registry_image_properties (image , REPOSITORY )
180194
181195
182196@patch ("pyxis.graphql_query" )
@@ -203,16 +217,26 @@ def test_update_images__success(mock_update_image):
203217 """Happy path scenario:
204218 There are 2 images on input and both have the correct tags removed
205219 """
220+
221+ lasting_tags = {
222+ "image1" : [{"name" : "latest" }, {"name" : "9.4" }, {"name" : "9.4-1111" }],
223+ "image2" : [{"name" : "9.4" }, {"name" : "9.4-2222" }],
224+ }
225+
206226 image1 = generate_image ("1111" , "amd64" , ["latest" , "9.4" , "9.4-1111" ])
207227 image1_new = generate_image ("1111" , "amd64" , ["9.4-1111" ])
228+ image1_new ["repositories" ][0 ]["tags" ] = lasting_tags ["image1" ]
229+
208230 image2 = generate_image ("2222" , "amd64" , ["9.4" , "9.4-2222" ])
209231 image2_new = generate_image ("2222" , "amd64" , ["9.4-2222" ])
232+ image2_new ["repositories" ][0 ]["tags" ] = lasting_tags ["image2" ]
233+
210234 images = {
211235 image1 ["_id" ]: image1 ,
212236 image2 ["_id" ]: image2 ,
213237 }
214238
215- update_images (GRAPHQL_API , ["latest" , "9.4" , "9.4-0000" ], images )
239+ update_images (GRAPHQL_API , ["latest" , "9.4" , "9.4-0000" ], images , REPOSITORY )
216240
217241 assert mock_update_image .call_args_list == [
218242 call (GRAPHQL_API , image1_new ),
@@ -252,7 +276,7 @@ def test_remove_none_values__success():
252276 assert remove_none_values (data ) == expected_result
253277
254278
255- def generate_image (id , architecture , tags ):
279+ def generate_image (id , architecture , tags , multiple_repos = False ):
256280 image = {
257281 "_id" : id ,
258282 "architecture" : architecture ,
@@ -269,6 +293,16 @@ def generate_image(id, architecture, tags):
269293 },
270294 ],
271295 }
296+
297+ if multiple_repos is not False :
298+ image ["repositories" ].append (
299+ {
300+ "registry" : REGISTRY ,
301+ "repository" : "redhat-nonprod/myproduct----myimage" ,
302+ "tags" : [{"name" : tag } for tag in tags ],
303+ }
304+ )
305+
272306 return image
273307
274308
0 commit comments