diff --git a/app/routers/hosted_file.py b/app/routers/hosted_file.py index be198cf..936ebe4 100644 --- a/app/routers/hosted_file.py +++ b/app/routers/hosted_file.py @@ -458,7 +458,7 @@ async def upload_files( link_to_id_random = link_to_id_random, check_allowed_extension = check_allowed_extension, ) - + hosted_file_id = None hosted_file_dict = {} @@ -858,10 +858,11 @@ async def test_upload_files( async def delete_hosted_file( hosted_file_id: str = Path(min_length=11, max_length=22), - link_to_type: str = None, - link_to_id: Union[int, str] = None, + # These are needed to identify the hosted_file_link record to be deleted + link_to_type: str = None, # Type of object the hosted file is linked to + link_to_id: Union[int, str] = None, # ID of the object the hosted file is linked to - rm_orphan: bool = False, + rm_orphan: bool = False, # Whether to remove orphaned files commons: Common_Route_Params = Depends(common_route_params), ): diff --git a/tests/e2e/test_e2e_hosted_file_live_delete.py b/tests/e2e/test_e2e_hosted_file_live_delete.py new file mode 100644 index 0000000..de9bcd5 --- /dev/null +++ b/tests/e2e/test_e2e_hosted_file_live_delete.py @@ -0,0 +1,78 @@ +import requests +import json + +# Configuration +BASE_URL = "https://dev-api.oneskyit.com" +API_KEY = "IDF68Em5X4HTZlswRNgepQ" +ACCOUNT_ID = "Q8lR8Ai8hx2FjbQ3C_EH1Q" +LINK_TO_TYPE = "archive_content" +LINK_TO_ID = "bZOa7CtUm0E" + +# IDs created in the previous turn +FILE_IDS = ['2R06T6yuQLw', 'dG60rqQK-mA', 'sKMzAD5mlwo', 'Ob-voYn7SkY'] + +def delete_file(file_id, rm_orphan=False): + print(f"\n--- Deleting File ID: {file_id} (rm_orphan={rm_orphan}) ---") + + url = f"{BASE_URL}/hosted_file/{file_id}" + params = { + "link_to_type": LINK_TO_TYPE, + "link_to_id": LINK_TO_ID, + "rm_orphan": str(rm_orphan).lower() + } + headers = { + "X-Aether-API-Key": API_KEY, + "x-account-id": ACCOUNT_ID + } + + try: + response = requests.delete(url, headers=headers, params=params) + print(f"Status Code: {response.status_code}") + if response.status_code == 200: + print(f"✅ Success: {response.json().get('status_message')}") + return True + else: + print(f"❌ Failed: {response.text}") + return False + except Exception as e: + print(f"💥 Exception: {e}") + return False + +def verify_file_exists(file_id): + url = f"{BASE_URL}/hosted_file/{file_id}" + headers = { + "X-Aether-API-Key": API_KEY, + "x-account-id": ACCOUNT_ID + } + response = requests.get(url, headers=headers) + return response.status_code == 200 + +if __name__ == "__main__": + print("Starting Live E2E Deletion Tests...") + + # 1. Delete one link WITHOUT rm_orphan + # The record should still exist in the DB (but link is gone) + target_1 = FILE_IDS[0] + if delete_file(target_1, rm_orphan=False): + exists = verify_file_exists(target_1) + print(f"Verification: File record exists after link-only delete? {exists}") + if not exists: + print("⚠️ Warning: File record was deleted even though rm_orphan=False (or it was already missing).") + + # 2. Delete one link WITH rm_orphan=True + # Since these files only have one link, the record and physical file should be deleted. + target_2 = FILE_IDS[1] + if delete_file(target_2, rm_orphan=True): + exists = verify_file_exists(target_2) + print(f"Verification: File record exists after orphan delete? {exists}") + if exists: + print("❌ Failure: File record still exists after rm_orphan=True.") + else: + print("✅ Success: File record was correctly removed.") + + # 3. Cleanup the rest + print("\n--- Cleaning up remaining files ---") + for fid in FILE_IDS[2:]: + delete_file(fid, rm_orphan=True) + + print("\nTests Complete.")