diff --git a/bukuserver/server.py b/bukuserver/server.py index c83e84d..39bc8bd 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -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 diff --git a/tests/test_server.py b/tests/test_server.py index d53405a..70f18ff 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -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']