summaryrefslogtreecommitdiff
path: root/tests/test_db.py
blob: 7a35593a263b7271d71b8b0a672823f7d96891af (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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