new: dev: db_file and test

This commit is contained in:
rachmadaniHaryono 2019-05-07 20:14:36 +08:00
parent de74fe61f4
commit 4fa973d306
2 changed files with 13 additions and 3 deletions

View File

@ -516,7 +516,7 @@ def search_bookmarks():
return res return res
def create_app(config_filename=None): def create_app(db_file=None):
"""create app.""" """create app."""
app = FlaskAPI(__name__) app = FlaskAPI(__name__)
per_page = int(os.getenv('BUKUSERVER_PER_PAGE', str(views.DEFAULT_PER_PAGE))) per_page = int(os.getenv('BUKUSERVER_PER_PAGE', str(views.DEFAULT_PER_PAGE)))
@ -527,7 +527,7 @@ def create_app(config_filename=None):
url_render_mode = views.DEFAULT_URL_RENDER_MODE url_render_mode = views.DEFAULT_URL_RENDER_MODE
app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode
app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24) app.config['SECRET_KEY'] = os.getenv('BUKUSERVER_SECRET_KEY') or os.urandom(24)
app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE') app.config['BUKUSERVER_DB_FILE'] = os.getenv('BUKUSERVER_DB_FILE') or db_file
bukudb = BukuDb(dbfile=app.config['BUKUSERVER_DB_FILE']) bukudb = BukuDb(dbfile=app.config['BUKUSERVER_DB_FILE'])
app.app_context().push() app.app_context().push()
setattr(flask.g, 'bukudb', bukudb) setattr(flask.g, 'bukudb', bukudb)

View File

@ -1,5 +1,6 @@
import pytest
from click.testing import CliRunner from click.testing import CliRunner
import flask
import pytest
from bukuserver import server from bukuserver import server
@ -15,3 +16,12 @@ def test_cli(args, word):
result = runner.invoke(server.cli, [args]) result = runner.invoke(server.cli, [args])
assert result.exit_code == 0 assert result.exit_code == 0
assert word in result.output assert word in result.output
def test_home(tmp_path):
test_db = tmp_path / 'test.db'
app = server.create_app(test_db.as_posix())
client = app.test_client()
rd = client.get('/')
assert rd.status_code == 200
assert not flask.g.bukudb.get_rec_all()