@@ -476,3 +476,110 @@ async def test_create_catalog_collection_nonexistent_catalog(
476476 "/catalogs/nonexistent-catalog/collections" , json = test_collection
477477 )
478478 assert resp .status_code == 404
479+
480+
481+ @pytest .mark .asyncio
482+ async def test_delete_catalog (catalogs_app_client , load_test_data ):
483+ """Test deleting a catalog without cascade."""
484+ # Create a catalog
485+ test_catalog = load_test_data ("test_catalog.json" )
486+ test_catalog ["id" ] = f"test-catalog-{ uuid .uuid4 ()} "
487+ test_catalog ["links" ] = [
488+ link for link in test_catalog .get ("links" , []) if link .get ("rel" ) != "child"
489+ ]
490+
491+ create_resp = await catalogs_app_client .post ("/catalogs" , json = test_catalog )
492+ assert create_resp .status_code == 201
493+ catalog_id = test_catalog ["id" ]
494+
495+ # Verify catalog exists
496+ get_resp = await catalogs_app_client .get (f"/catalogs/{ catalog_id } " )
497+ assert get_resp .status_code == 200
498+
499+ # Delete the catalog
500+ delete_resp = await catalogs_app_client .delete (f"/catalogs/{ catalog_id } " )
501+ assert delete_resp .status_code == 204
502+
503+ # Verify catalog is deleted
504+ get_resp = await catalogs_app_client .get (f"/catalogs/{ catalog_id } " )
505+ assert get_resp .status_code == 404
506+
507+
508+ @pytest .mark .asyncio
509+ async def test_delete_catalog_cascade (catalogs_app_client , load_test_data ):
510+ """Test deleting a catalog with cascade delete of collections."""
511+ # Create a catalog
512+ test_catalog = load_test_data ("test_catalog.json" )
513+ test_catalog ["id" ] = f"test-catalog-{ uuid .uuid4 ()} "
514+ test_catalog ["links" ] = [
515+ link for link in test_catalog .get ("links" , []) if link .get ("rel" ) != "child"
516+ ]
517+
518+ create_resp = await catalogs_app_client .post ("/catalogs" , json = test_catalog )
519+ assert create_resp .status_code == 201
520+ catalog_id = test_catalog ["id" ]
521+
522+ # Create a collection in the catalog
523+ test_collection = load_test_data ("test_collection.json" )
524+ test_collection ["id" ] = f"test-collection-{ uuid .uuid4 ()} "
525+
526+ coll_resp = await catalogs_app_client .post (
527+ f"/catalogs/{ catalog_id } /collections" , json = test_collection
528+ )
529+ assert coll_resp .status_code == 201
530+ collection_id = test_collection ["id" ]
531+
532+ # Verify collection exists
533+ get_coll_resp = await catalogs_app_client .get (f"/collections/{ collection_id } " )
534+ assert get_coll_resp .status_code == 200
535+
536+ # Delete the catalog with cascade=true
537+ delete_resp = await catalogs_app_client .delete (
538+ f"/catalogs/{ catalog_id } ?cascade=true"
539+ )
540+ assert delete_resp .status_code == 204
541+
542+ # Verify catalog is deleted
543+ get_resp = await catalogs_app_client .get (f"/catalogs/{ catalog_id } " )
544+ assert get_resp .status_code == 404
545+
546+ # Verify collection is also deleted (cascade delete)
547+ get_coll_resp = await catalogs_app_client .get (f"/collections/{ collection_id } " )
548+ assert get_coll_resp .status_code == 404
549+
550+
551+ @pytest .mark .asyncio
552+ async def test_delete_catalog_no_cascade (catalogs_app_client , load_test_data ):
553+ """Test deleting a catalog without cascade (collections remain)."""
554+ # Create a catalog
555+ test_catalog = load_test_data ("test_catalog.json" )
556+ test_catalog ["id" ] = f"test-catalog-{ uuid .uuid4 ()} "
557+ test_catalog ["links" ] = [
558+ link for link in test_catalog .get ("links" , []) if link .get ("rel" ) != "child"
559+ ]
560+
561+ create_resp = await catalogs_app_client .post ("/catalogs" , json = test_catalog )
562+ assert create_resp .status_code == 201
563+ catalog_id = test_catalog ["id" ]
564+
565+ # Create a collection in the catalog
566+ test_collection = load_test_data ("test_collection.json" )
567+ test_collection ["id" ] = f"test-collection-{ uuid .uuid4 ()} "
568+
569+ coll_resp = await catalogs_app_client .post (
570+ f"/catalogs/{ catalog_id } /collections" , json = test_collection
571+ )
572+ assert coll_resp .status_code == 201
573+ collection_id = test_collection ["id" ]
574+
575+ # Delete the catalog with cascade=false (default)
576+ delete_resp = await catalogs_app_client .delete (f"/catalogs/{ catalog_id } " )
577+ assert delete_resp .status_code == 204
578+
579+ # Verify catalog is deleted
580+ get_resp = await catalogs_app_client .get (f"/catalogs/{ catalog_id } " )
581+ assert get_resp .status_code == 404
582+
583+ # Verify collection still exists (no cascade delete)
584+ get_coll_resp = await catalogs_app_client .get (f"/collections/{ collection_id } " )
585+ assert get_coll_resp .status_code == 200
0 commit comments