new: dev: update bookmarks api

This commit is contained in:
rachmadaniHaryono 2019-05-14 14:35:47 +08:00
parent e5d0dd01a0
commit 8a1e3995a4
2 changed files with 19 additions and 8 deletions

View File

@ -2,6 +2,7 @@
# pylint: disable=wrong-import-order, ungrouped-imports
"""Server module."""
from typing import Union
from unittest import mock
from urllib.parse import urlparse
import os
import sys
@ -173,14 +174,13 @@ def bookmarks():
flash(Markup('Failed creating bookmark {}.'.format(bm_text)), 'danger')
return redirect(url_for('bookmarks-html'))
elif request.method == 'DELETE':
result_flag = bukudb.cleardb()
res = [
jsonify(response.response_template['success']), status.HTTP_200_OK,
{'ContentType': 'application/json'}
] if result_flag else [
jsonify(response.response_template['failure']), status.HTTP_400_BAD_REQUEST,
{'ContentType': 'application/json'}
]
with mock.patch('buku.read_in', return_value='y'):
result_flag = bukudb.cleardb()
if result_flag:
res = jsonify(response.response_template['success'])
else:
res = jsonify(response.response_template['failure'])
res.status_code = status.HTTP_400_BAD_REQUEST
return res

View File

@ -106,3 +106,14 @@ def test_bookmark_api(client):
assert rd.status_code == 200
assert rd.get_json() == {
'description': '', 'tags': [], 'title': '', 'url': 'http://google.com'}
@pytest.mark.parametrize('d_url', ['/api/bookmarks', '/api/bookmarks/1'])
def test_bookmark_api_delete(client, d_url):
url = 'http://google.com'
rd = client.post('/api/bookmarks', data={'url': url})
assert rd.status_code == 200
assert rd.get_json() == response_template['success']
rd = client.delete(d_url)
assert rd.status_code == 200
assert rd.get_json() == response_template['success']