new: dev: update tag api
This commit is contained in:
parent
79b4cb795e
commit
1bc4dcf0b0
@ -82,7 +82,11 @@ def tag_detail(tag):
|
|||||||
elif request.method == 'PUT':
|
elif request.method == 'PUT':
|
||||||
res = None
|
res = None
|
||||||
try:
|
try:
|
||||||
new_tags = request.data.get('tags').split(',')
|
new_tags = request.data.get('tags')
|
||||||
|
if new_tags:
|
||||||
|
new_tags = new_tags.split(',')
|
||||||
|
else:
|
||||||
|
return response.response_template['failure'], status.HTTP_400_BAD_REQUEST
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
raise exceptions.ParseError(detail=str(e))
|
raise exceptions.ParseError(detail=str(e))
|
||||||
result_flag = bukudb.replace_tag(tag, new_tags)
|
result_flag = bukudb.replace_tag(tag, new_tags)
|
||||||
|
@ -46,18 +46,21 @@ def test_api_empty_db(client, url, exp_res):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'url, exp_res, status_code', [
|
'url, exp_res, status_code, method', [
|
||||||
['/api/tags/1', {'message': 'This resource does not exist.'}, 404],
|
['/api/tags/1', {'message': 'This resource does not exist.'}, 404, 'get'],
|
||||||
['/api/bookmarks/1', {'message': 'failure', 'status': 1}, 400],
|
['/api/tags/1', {'message': 'failure', 'status': 1}, 400, 'put'],
|
||||||
|
['/api/bookmarks/1', {'message': 'failure', 'status': 1}, 400, 'get'],
|
||||||
|
['/api/bookmarks/1', None, 400, 'put'],
|
||||||
|
['/api/bookmarks/1', {'message': 'failure', 'status': 1}, 400, 'delete'],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_invalid_id(client, url, exp_res, status_code):
|
def test_invalid_id(client, url, exp_res, status_code, method):
|
||||||
rd = client.get(url)
|
rd = getattr(client, method)(url)
|
||||||
assert rd.status_code == status_code
|
assert rd.status_code == status_code
|
||||||
assert rd.get_json() == exp_res
|
assert rd.get_json() == exp_res
|
||||||
|
|
||||||
|
|
||||||
def test_api(client):
|
def test_bookmark_api(client):
|
||||||
url = 'http://google.com'
|
url = 'http://google.com'
|
||||||
rd = client.post('/api/bookmarks', data={'url': url})
|
rd = client.post('/api/bookmarks', data={'url': url})
|
||||||
assert rd.status_code == 200
|
assert rd.status_code == 200
|
||||||
|
Loading…
Reference in New Issue
Block a user