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.
/-/new-empty-database-file test, refs simonw/datasette-app#30
- Loading branch information
Showing
1 changed file
with
25 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,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} |