new: dev: refactor network handle

This commit is contained in:
rachmadaniHaryono 2019-05-14 19:49:52 +08:00
parent b2c628a27a
commit baa8308ed4
2 changed files with 21 additions and 6 deletions

View File

@ -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/<int:rec_id>/refresh', 'refresh_bookmark', refresh_bookmark, methods=['POST'])
app.add_url_rule('/api/bookmarks/<int:rec_id>/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/<starting_id>/<ending_id>',
'bookmark_range_operations', bookmark_range_operations, methods=['GET', 'PUT', 'DELETE'])

View File

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