diff --git a/bukuserver/server.py b/bukuserver/server.py index 69e8a8c..68063ef 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -516,7 +516,7 @@ def search_bookmarks(): return res -def create_app(config_filename=None): +def create_app(db_file=None): """create app.""" app = FlaskAPI(__name__) 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 app.config['BUKUSERVER_URL_RENDER_MODE'] = url_render_mode 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']) app.app_context().push() setattr(flask.g, 'bukudb', bukudb) diff --git a/tests/test_server.py b/tests/test_server.py index c9ac243..d2c0750 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,5 +1,6 @@ -import pytest from click.testing import CliRunner +import flask +import pytest from bukuserver import server @@ -15,3 +16,12 @@ def test_cli(args, word): result = runner.invoke(server.cli, [args]) assert result.exit_code == 0 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()