text: 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
  
  
  def test_index(client, auth):
      response = client.get('/')
      assert b"Log In" in response.data
      assert b"Register" in response.data
  
      auth.login()
      response = client.get('/')
      assert b'Log Out' in response.data
      assert b'test title' in response.data
      assert b'by test on 2018-01-01' in response.data
      assert b'test\nbody' in response.data
      assert b'href="/1/update"' in response.data
  