Skip to content

Commit

Permalink
/-/new-empty-database-file test, refs simonw/datasette-app#30
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 4, 2021
1 parent 7c36a3e commit ba3be3c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_new_empty_database_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from datasette.app import Datasette
import pytest
import sqlite3


@pytest.mark.asyncio
async def test_new_empty_database_file(tmpdir):
datasette = Datasette([], memory=True)
path = str(tmpdir / "new.db")
response = await datasette.client.post(
"/-/new-empty-database-file", json={"path": path}
)
assert response.status_code == 200
assert response.json() == {"ok": True, "path": "/new"}
response = await datasette.client.get("/new.json")
assert (
response.json().items()
>= {"database": "new", "path": "/new", "tables": []}.items()
)
# Attempting to create the same file again throws an error
response2 = await datasette.client.post(
"/-/new-empty-database-file", json={"path": path}
)
assert response2.status_code == 400
assert response2.json() == {"error": "That file already exists", "ok": False}

0 comments on commit ba3be3c

Please sign in to comment.