mirror of https://github.com/mitsuhiko/flask.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
617 B
29 lines
617 B
7 years ago
|
import sqlite3
|
||
|
|
||
|
import pytest
|
||
|
from flaskr.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)
|
||
|
|
||
|
|
||
|
def test_init_db_command(runner, monkeypatch):
|
||
|
class Recorder(object):
|
||
|
called = False
|
||
|
|
||
|
def fake_init_db():
|
||
|
Recorder.called = True
|
||
|
|
||
|
monkeypatch.setattr('flaskr.db.init_db', fake_init_db)
|
||
|
result = runner.invoke(args=['init-db'])
|
||
|
assert 'Initialized' in result.output
|
||
|
assert Recorder.called
|