new: dev: test api and invalid id

This commit is contained in:
rachmadaniHaryono 2019-05-14 04:56:03 +08:00
parent 26e33f87d3
commit de395789b5

View File

@ -43,3 +43,33 @@ def test_api_empty_db(client, url, exp_res):
rd = client.get(url)
assert rd.status_code == 200
assert rd.get_json() == exp_res
@pytest.mark.parametrize(
'url, exp_res, status_code', [
['/api/tags/1', {'message': 'This resource does not exist.'}, 404],
['/api/bookmarks/1', {'message': 'failure', 'status': 1}, 400],
]
)
def test_invalid_id(client, url, exp_res, status_code):
rd = client.get(url)
assert rd.status_code == status_code
assert rd.get_json() == exp_res
def test_api(client):
url = 'http://google.com'
rd = client.post('/api/bookmarks', data={'url': url})
assert rd.status_code == 200
assert rd.get_json() == {'message': 'success', 'status': 0}
rd = client.post('/api/bookmarks', data={'url': url})
assert rd.status_code == 400
assert rd.get_json() == {'message': 'failure', 'status': 1}
rd = client.get('/api/bookmarks/search', query_string={'keywords': 'google.com'})
assert rd.status_code == 200
assert rd.get_json() == {'bookmarks': [
{'description': '', 'id': 1, 'tags': [], 'title': '', 'url': url}]}
rd = client.get('/api/bookmarks/1')
assert rd.status_code == 200
assert rd.get_json() == {
'description': '', 'tags': [], 'title': '', 'url': 'http://google.com'}