generated from simonw/datasette-plugin-template-repository
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for /-/dump-temporary-to-file endpoint, refs #9
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from datasette.app import Datasette | ||
import pytest | ||
import sqlite3 | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_dump_restore_temporary(tmpdir): | ||
datasette = Datasette([], memory=True) | ||
await datasette.invoke_startup() | ||
# Import CSV into temporary | ||
path = str(tmpdir / "backup_demo.csv") | ||
backup_path = str(tmpdir / "backup.db") | ||
open(path, "w").write("id,name\n123,Hello") | ||
response = await datasette.client.post( | ||
"/-/open-csv-file", | ||
json={"path": path}, | ||
headers={"Authorization": "Bearer fake-token"}, | ||
) | ||
assert response.status_code == 200 | ||
# Dump temporary to a file | ||
response = await datasette.client.post( | ||
"/-/dump-temporary-to-file", | ||
json={"path": backup_path}, | ||
headers={"Authorization": "Bearer fake-token"}, | ||
allow_redirects=False, | ||
) | ||
assert response.status_code == 200 | ||
assert response.json() == {"ok": True, "path": backup_path} | ||
# Check that the backup file has the right stuff | ||
conn = sqlite3.connect(backup_path) | ||
assert conn.execute("select * from backup_demo").fetchall() == [("123", "Hello")] |