summaryrefslogtreecommitdiff
path: root/tests/test_db.py
diff options
context:
space:
mode:
authorTom Harley2021-07-03 00:18:13 +0000
committerTom Harley2021-07-03 00:18:13 +0000
commit7c5c6c52250ca57257ab4af2cc9cdf4425595ec0 (patch)
treed36019286125bf984e0c267645d53ff562533ebf /tests/test_db.py
downloadswap-7c5c6c52250ca57257ab4af2cc9cdf4425595ec0.tar.gz
swap-7c5c6c52250ca57257ab4af2cc9cdf4425595ec0.zip

Initial commit

Diffstat (limited to 'tests/test_db.py')
-rw-r--r--tests/test_db.py30
1 files changed, 30 insertions, 0 deletions
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