From 7c5c6c52250ca57257ab4af2cc9cdf4425595ec0 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 3 Jul 2021 00:18:13 +0000 Subject: Initial commit --- tests/test_db.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/test_db.py (limited to 'tests/test_db.py') diff --git a/tests/test_db.py b/tests/test_db.py new file mode 100644 index 0000000..7a35593 --- /dev/null +++ b/tests/test_db.py @@ -0,0 +1,30 @@ +import pytest + +import sqlite3 + +from sw.db import get_db + + +def test_get_close_db(app): + with app.app_context(): + db = get_db() + assert db is get_db() + + with pytest.raises(sqlite3.ProgrammingError) as e: + db.execute("select 1") + + assert "closed" in str(e.value) + + +def test_init_db_command(runner, monkeypatch): + class Recorder(object): + called = False + + def fake_init_db(): + Recorder.called = True + + monkeypatch.setattr("sw.db.init_db", fake_init_db) + result = runner.invoke(args=["init-db"]) + + assert "Initialised" in result.output + assert Recorder.called -- cgit v1.2.1