diff --git a/bukuserver/server.py b/bukuserver/server.py index 8ce23e9..453f098 100644 --- a/bukuserver/server.py +++ b/bukuserver/server.py @@ -55,7 +55,7 @@ def get_tags(): return res -def network_handle_detail(): +def handle_network(): failed_resp = response.response_template['failure'], status.HTTP_400_BAD_REQUEST url = request.data.get('url', None) if not url: @@ -306,11 +306,7 @@ def create_app(db_file=None): app.add_url_rule('/api/bookmarks/refresh', 'refresh_bookmark', refresh_bookmark, defaults={'rec_id': None}, methods=['POST']) app.add_url_rule('/api/bookmarks//refresh', 'refresh_bookmark', refresh_bookmark, methods=['POST']) app.add_url_rule('/api/bookmarks//tiny', 'get_tiny_url', get_tiny_url, methods=['GET']) - app.add_url_rule( - '/api/network_handle', - 'network_handle', - network_handle_detail, - methods=['POST']) + app.add_url_rule('/api/network_handle', 'network_handle', handle_network, methods=['POST']) app.add_url_rule( '/api/bookmarks//', 'bookmark_range_operations', bookmark_range_operations, methods=['GET', 'PUT', 'DELETE']) diff --git a/tests/test_server.py b/tests/test_server.py index 58f82a2..7738b14 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -161,3 +161,22 @@ def test_get_tiny_url(client, url, exp_res, status_code): rd = client.get('/api/bookmarks/1/tiny') assert rd.status_code == status_code assert rd.get_json() == exp_res + + +@pytest.mark.parametrize('kwargs, status_code, exp_res', [ + [ + dict(data={'url': 'http://google.com'}), + 200, + {'bad url': None, 'recognized mime': None, 'title': 'Google'} + ], + [{}, 400, response_template['failure']], + [ + dict(data={'url': 'chrome://bookmarks/'}), + 200, + {'bad url': None, 'recognized mime': None, 'title': None} + ], +]) +def test_network_handle(client, kwargs, status_code, exp_res): + rd = client.post('/api/network_handle', **kwargs) + assert rd.status_code == status_code + assert rd.get_json() == exp_res