@@ -191,6 +191,74 @@ def test_422_raises_with_fields(self):
191191 assert exc_info .value .fields == {"source_kind" : ["Not a valid choice." ]}
192192
193193
194+ class TestGetMetadata :
195+ @httpretty .activate (allow_net_connect = False )
196+ def test_success_returns_metadata_entry (self ):
197+ body = {
198+ "slug_perm" : META ,
199+ "content" : {"foo" : "bar" },
200+ "content_type" : "application/json" ,
201+ "classification" : "generic" ,
202+ "source_kind" : "customer" ,
203+ "source_identity" : "cloudsmith-cli@1.16.0" ,
204+ "is_canonical" : True ,
205+ "source_table" : "package_metadata" ,
206+ "created_at" : "2026-04-30T12:34:56Z" ,
207+ }
208+ httpretty .register_uri (
209+ httpretty .GET ,
210+ DETAIL_URL ,
211+ body = json .dumps (body ),
212+ status = 200 ,
213+ content_type = "application/json" ,
214+ )
215+
216+ result = metadata .get_metadata (PKG , META )
217+
218+ assert result == body
219+ sent = _last_request ()
220+ assert sent .method == "GET"
221+ assert sent .headers .get ("X-Api-Key" ) == "test-api-key"
222+
223+ @httpretty .activate (allow_net_connect = False )
224+ def test_404_on_unknown_metadata (self ):
225+ httpretty .register_uri (
226+ httpretty .GET ,
227+ DETAIL_URL ,
228+ body = json .dumps ({"detail" : "Not found." }),
229+ status = 404 ,
230+ content_type = "application/json" ,
231+ )
232+
233+ with pytest .raises (ApiException ) as exc_info :
234+ metadata .get_metadata (PKG , META )
235+
236+ assert exc_info .value .status == 404
237+ assert exc_info .value .detail == "Not found."
238+
239+ @httpretty .activate (allow_net_connect = False )
240+ def test_422_raises_with_fields (self ):
241+ body = {
242+ "detail" : "Validation failed." ,
243+ "fields" : {"metadata_slug_perm" : ["Invalid metadata slug." ]},
244+ }
245+ httpretty .register_uri (
246+ httpretty .GET ,
247+ DETAIL_URL ,
248+ body = json .dumps (body ),
249+ status = 422 ,
250+ content_type = "application/json" ,
251+ )
252+
253+ with pytest .raises (ApiException ) as exc_info :
254+ metadata .get_metadata (PKG , META )
255+
256+ assert exc_info .value .status == 422
257+ assert exc_info .value .fields == {
258+ "metadata_slug_perm" : ["Invalid metadata slug." ]
259+ }
260+
261+
194262class TestCreateMetadata :
195263 @httpretty .activate (allow_net_connect = False )
196264 def test_success_posts_required_fields (self ):
0 commit comments