@@ -747,3 +747,65 @@ async def test_backup_not_found(api_client: TestClient, method: str, url: str):
747747 assert resp .status == 404
748748 resp = await resp .json ()
749749 assert resp ["message" ] == "Backup does not exist"
750+
751+
752+ @pytest .mark .usefixtures ("tmp_supervisor_data" )
753+ async def test_remove_backup_from_location (api_client : TestClient , coresys : CoreSys ):
754+ """Test removing a backup from one location of multiple."""
755+ backup_file = get_fixture_path ("backup_example.tar" )
756+ location_1 = Path (copy (backup_file , coresys .config .path_backup ))
757+ location_2 = Path (copy (backup_file , coresys .config .path_core_backup ))
758+
759+ await coresys .backups .reload ()
760+ assert (backup := coresys .backups .get ("7fed74c8" ))
761+ assert backup .all_locations == {None : location_1 , ".cloud_backup" : location_2 }
762+
763+ resp = await api_client .delete (
764+ "/backups/7fed74c8" , json = {"location" : ".cloud_backup" }
765+ )
766+ assert resp .status == 200
767+
768+ assert location_1 .exists ()
769+ assert not location_2 .exists ()
770+ assert coresys .backups .get ("7fed74c8" )
771+ assert backup .all_locations == {None : location_1 }
772+
773+
774+ async def test_download_backup_from_location (
775+ api_client : TestClient , coresys : CoreSys , tmp_supervisor_data : Path
776+ ):
777+ """Test downloading a backup from a specific location."""
778+ backup_file = get_fixture_path ("backup_example.tar" )
779+ location_1 = Path (copy (backup_file , coresys .config .path_backup ))
780+ location_2 = Path (copy (backup_file , coresys .config .path_core_backup ))
781+
782+ await coresys .backups .reload ()
783+ assert (backup := coresys .backups .get ("7fed74c8" ))
784+ assert backup .all_locations == {None : location_1 , ".cloud_backup" : location_2 }
785+
786+ # The use case of this is user might want to pick a particular mount if one is flaky
787+ # To simulate this, remove the file from one location and show one works and the other doesn't
788+ assert backup .location is None
789+ location_1 .unlink ()
790+
791+ resp = await api_client .get ("/backups/7fed74c8/download?location=" )
792+ assert resp .status == 404
793+
794+ resp = await api_client .get ("/backups/7fed74c8/download?location=.cloud_backup" )
795+ assert resp .status == 200
796+ out_file = tmp_supervisor_data / "backup_example.tar"
797+ with out_file .open ("wb" ) as out :
798+ out .write (await resp .read ())
799+
800+ out_backup = Backup (coresys , out_file , "out" , None )
801+ await out_backup .load ()
802+ assert backup == out_backup
803+
804+
805+ @pytest .mark .usefixtures ("mock_full_backup" )
806+ async def test_download_backup_from_invalid_location (api_client : TestClient ):
807+ """Test error for invalid download location."""
808+ resp = await api_client .get ("/backups/test/download?location=.cloud_backup" )
809+ assert resp .status == 400
810+ body = await resp .json ()
811+ assert body ["message" ] == "Backup test is not in location .cloud_backup"
0 commit comments