Merge pull request #479 from rachmadaniHaryono/bugfix/bukuserver-create-bookmark
fix: bukuserver bookmark creation
This commit is contained in:
commit
899280efdf
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user