Skip to content

Commit

Permalink
Test for /-/dump-temporary-to-file endpoint, refs #9
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 9, 2021
1 parent 506e4c8 commit 10dac6b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_dump_restore_temporary.py
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")]

0 comments on commit 10dac6b

Please sign in to comment.