Merge pull request #479 from rachmadaniHaryono/bugfix/bukuserver-create-bookmark

fix: bukuserver bookmark creation
This commit is contained in:
Mischievous Meerkat 2020-11-22 04:39:53 +05:30 committed by GitHub
commit 899280efdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View File

@ -154,12 +154,13 @@ class BookmarkModelView(BaseModelView):
def create_form(self, obj=None):
form = super().create_form(obj)
if 'url' in request.args.keys():
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):

View File

@ -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