From 695c45158aafcbbc4e2b4216d30c80a6b8694249 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Tue, 14 May 2019 02:47:29 +0800 Subject: [PATCH] new: dev: test api on empty database --- tests/test_server.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_server.py b/tests/test_server.py index d2c0750..1bab16c 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -18,10 +18,28 @@ def test_cli(args, word): assert word in result.output -def test_home(tmp_path): +@pytest.fixture +def client(tmp_path): test_db = tmp_path / 'test.db' app = server.create_app(test_db.as_posix()) client = app.test_client() + return client + + +def test_home(client): rd = client.get('/') assert rd.status_code == 200 assert not flask.g.bukudb.get_rec_all() + + +@pytest.mark.parametrize( + 'url, exp_res', [ + ['/api/tags', {'tags': []}], + ['/api/bookmarks', {'bookmarks': []}], + ['/api/bookmarks/search', {'bookmarks': []}] + ] +) +def test_api_empty_db(client, url, exp_res): + rd = client.get(url) + assert rd.status_code == 200 + assert rd.get_json() == exp_res