async def test_move_but_path_is_recursive(client: TestClient, namespace: Namespace): payload = {"from_path": "a/b", "to_path": "a/b/c"} client.login(namespace.owner.id) response = await client.post("/files/move", json=payload) message = "Destination path should not start with source path" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_upload_but_to_a_special_path(client: TestClient, namespace: Namespace): payload = { "file": BytesIO(b"Dummy file"), "path": (None, b"Trash"), } client.login(namespace.owner.id) response = await client.post("/files/upload", files=payload) # type: ignore message = "Uploads to the Trash are not allowed" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_move_to_trash_but_it_is_a_trash( client: TestClient, namespace: Namespace, ): payload = {"path": "Trash"} client.login(namespace.owner.id) response = await client.post("/files/move_to_trash", json=payload) message = "Can't move Trash into itself" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_move_but_it_is_a_special_path( client: TestClient, namespace: Namespace, path: str, ): payload = {"from_path": path, "to_path": "Trashbin"} client.login(namespace.owner.id) response = await client.post("/files/move", json=payload) message = "Can't move Home or Trash folder" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_delete_immediately_batch_but_it_is_a_special_folder( client: TestClient, namespace: Namespace, path: str, ): payload = {"items": [{"path": path}]} client.login(namespace.owner.id) response = await client.post("/files/delete_immediately_batch", json=payload) message = f"Path '{path}' is a special path and can't be deleted" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_move_but_path_missing_parent( client: TestClient, namespace: Namespace, file_factory: FileFactory, ): file_a = await file_factory(namespace.path, path="file_a.txt") payload = {"from_path": file_a.path, "to_path": f"folder/{file_a.path}"} client.login(namespace.owner.id) response = await client.post("/files/move", json=payload) message = "Some parents don't exist in the destination path" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400
async def test_move_but_to_a_special_path( client: TestClient, namespace: Namespace, file_factory: FileFactory, next_path: str, ): file = await file_factory(namespace.path) payload = {"from_path": file.path, "to_path": next_path} client.login(namespace.owner.id) response = await client.post("/files/move", json=payload) message = "Can't move Home or Trash folder" assert response.json() == MalformedPath(message).as_dict() assert response.status_code == 400