From 08e81c292392bf7ee0b2e5fbf17647fef976f901 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Nov 2020 04:30:46 +0800 Subject: [PATCH 1/3] fix: dev: bukuserver bookmark creation temporary fix until actual cause found --- bukuserver/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bukuserver/views.py b/bukuserver/views.py index 24bad71..35b841c 100644 --- a/bukuserver/views.py +++ b/bukuserver/views.py @@ -154,7 +154,7 @@ class BookmarkModelView(BaseModelView): def create_form(self, obj=None): form = super().create_form(obj) - if 'url' in request.args.keys(): + if 'url' in request.args.keys() and not request.args.get("url").startswith('/bookmark/'): form.url.data = request.args.get("url") if 'title' in request.args.keys(): form.title.data = request.args.get("title") From 1cf72371279c6c8b5a0f1ef2076dab45284cd529 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Wed, 18 Nov 2020 06:45:18 +0800 Subject: [PATCH 2/3] new: test: create_form for BMV --- tests/test_views.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_views.py b/tests/test_views.py index 92b64be..62b6aae 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -2,7 +2,7 @@ from argparse import Namespace from types import SimpleNamespace import pytest -from flask import current_app +from flask import current_app, request from buku import BukuDb from bukuserver import server @@ -100,3 +100,22 @@ def test_tag_model_view_get_list(tmv_instance, sort_field, sort_desc, filters, e tmv_instance.bukudb.add_rec('http://example.com/3.jpg', tags_in='t3') res = tmv_instance.get_list(0, sort_field, sort_desc, None, filters) assert res == exp_res + + +@pytest.fixture +def bmv_instance(tmp_path): + """define tag model view instance""" + test_db = tmp_path / 'test.db' + bukudb = BukuDb(dbfile=test_db.as_posix()) + inst = BookmarkModelView(bukudb) + return inst + + +@pytest.mark.parametrize('url, exp_url', [ + ['http://example.com', 'http://example.com'], + ['/bookmark/', None], +]) +def test_bmv_create_form(bmv_instance, url, exp_url): + request.args = {'url': url} + form = bmv_instance.create_form() + assert form.url.data == exp_url From b2de7de38add49fb0cf686229dce8cb1a356bdee Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sun, 22 Nov 2020 06:59:59 +0800 Subject: [PATCH 3/3] chg: dev: shorten request.args --- bukuserver/views.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bukuserver/views.py b/bukuserver/views.py index 35b841c..9f113d9 100644 --- a/bukuserver/views.py +++ b/bukuserver/views.py @@ -154,12 +154,13 @@ class BookmarkModelView(BaseModelView): def create_form(self, obj=None): form = super().create_form(obj) - if 'url' in request.args.keys() and not request.args.get("url").startswith('/bookmark/'): - form.url.data = request.args.get("url") - if 'title' in request.args.keys(): - form.title.data = request.args.get("title") - if 'description' in request.args.keys(): - form.description.data = request.args.get("description") + args = request.args + if 'url' in args.keys() and not args.get("url").startswith('/bookmark/'): + form.url.data = args.get("url") + if 'title' in args.keys(): + form.title.data = args.get("title") + if 'description' in args.keys(): + form.description.data = args.get("description") return form def create_model(self, form):