From 7197add803bfa1f9c77449d6bad2fc892595d48a Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 13 Apr 2019 07:40:55 +0800 Subject: [PATCH 1/4] fix: test: test_update_rec_exec_arg for p 3.7 --- tests/test_bukuDb.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 25eea84..ba7938c 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -1027,52 +1027,71 @@ def test_update_rec_index_0(caplog): @pytest.mark.parametrize( - 'kwargs, exp_query, exp_arguments', + 'kwargs, exp_query, exp_query_p37, exp_arguments, exp_arguments_p37', [ [ {'index': 1, 'url': 'http://example.com'}, 'UPDATE bookmarks SET URL = ?, metadata = ? WHERE id = ?', - ['http://example.com', 'Example Domain', 1] + 'UPDATE bookmarks SET URL = ?, desc = ?, metadata = ? WHERE id = ?', + ['http://example.com', 'Example Domain', 1], + ['http://example.com', '', 'Example Domain', 1] ], [ {'index': 1, 'url': 'http://example.com', 'title_in': 'randomtitle'}, 'UPDATE bookmarks SET URL = ?, metadata = ? WHERE id = ?', + 'UPDATE bookmarks SET URL = ?, metadata = ? WHERE id = ?', + ['http://example.com', 'randomtitle', 1], ['http://example.com', 'randomtitle', 1] ], [ {'index': 1, 'url': 'http://example.com', 'tags_in': 'tag1'}, 'UPDATE bookmarks SET URL = ?, tags = ?, metadata = ? WHERE id = ?', - ['http://example.com', ',tag1', 'Example Domain', 1] + 'UPDATE bookmarks SET URL = ?, tags = ?, desc = ?, metadata = ? WHERE id = ?', + ['http://example.com', ',tag1', 'Example Domain', 1], + ['http://example.com', ',tag1,', '', 'Example Domain', 1] ], [ {'index': 1, 'url': 'http://example.com', 'tags_in': '+,tag1'}, 'UPDATE bookmarks SET URL = ?, metadata = ? WHERE id = ?', - ['http://example.com', 'Example Domain', 1] + 'UPDATE bookmarks SET URL = ?, desc = ?, metadata = ? WHERE id = ?', + ['http://example.com', 'Example Domain', 1], + ['http://example.com', '', 'Example Domain', 1] ], [ {'index': 1, 'url': 'http://example.com', 'tags_in': '-,tag1'}, 'UPDATE bookmarks SET URL = ?, metadata = ? WHERE id = ?', - ['http://example.com', 'Example Domain', 1] + 'UPDATE bookmarks SET URL = ?, desc = ?, metadata = ? WHERE id = ?', + ['http://example.com', 'Example Domain', 1], + ['http://example.com', '', 'Example Domain', 1] ], [ {'index': 1, 'url': 'http://example.com', 'desc': 'randomdesc'}, 'UPDATE bookmarks SET URL = ?, desc = ?, metadata = ? WHERE id = ?', + 'UPDATE bookmarks SET URL = ?, desc = ?, metadata = ? WHERE id = ?', + ['http://example.com', 'randomdesc', 'Example Domain', 1], ['http://example.com', 'randomdesc', 'Example Domain', 1] ], ] ) -def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_arguments): +def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_arguments, exp_arguments_p37): """test method.""" + if (sys.version_info.major, sys.version_info.minor) == (3, 7): + caplog.set_level(logging.DEBUG) + exp_query = exp_query_p37 + exp_arguments = exp_arguments_p37 bdb = BukuDb() res = bdb.update_rec(**kwargs) assert res + exp_log = 'query: "{}", args: {}'.format(exp_query, exp_arguments) + if (sys.version_info.major, sys.version_info.minor) == (3, 7): + exp_log = 'update_rec ' + exp_log try: assert caplog.records[-1].getMessage() == exp_log assert caplog.records[-1].levelname == 'DEBUG' From 0a085e194668f3b5a1e485af06cd5140872a2c3c Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 13 Apr 2019 07:57:34 +0800 Subject: [PATCH 2/4] fix: test: test_search_by_tag_query --- tests/test_bukuDb.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index ba7938c..ae28d4a 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -1107,37 +1107,51 @@ def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_argum @pytest.mark.parametrize( - 'tags_to_search, exp_query, exp_arguments', + 'tags_to_search, exp_query, exp_query_p37, exp_arguments', [ [ 'tag1, tag2', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%' " "OR tags LIKE '%' || ? || '%' ORDER BY id ASC", + "SELECT id, url, metadata, tags, desc " + "FROM (SELECT *, CASE WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END + CASE " + "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END AS score " + "FROM bookmarks WHERE score > 0 ORDER BY score DESC)", [',tag1,', ',tag2,'] - ], [ 'tag1+tag2,tag3, tag4', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%' " "OR tags LIKE '%' || ? || '%' OR tags LIKE '%' || ? || '%' ORDER BY id ASC", + "SELECT id, url, metadata, tags, desc " + "FROM (SELECT *, CASE WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END + CASE " + "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END + CASE " + "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END AS score " + "FROM bookmarks WHERE score > 0 ORDER BY score DESC)", [',tag1+tag2,', ',tag3,', ',tag4,'] ], [ 'tag1 + tag2+tag3', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%' " "AND tags LIKE '%' || ? || '%' ORDER BY id ASC", + None, [',tag1,', ',tag2+tag3,'] ], [ 'tag1-tag2 + tag 3 - tag4', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE (tags LIKE '%' || ? || '%' " "AND tags LIKE '%' || ? || '%' ) AND tags NOT REGEXP ? ORDER BY id ASC", + None, [',tag1-tag2,', ',tag 3,', ',tag4,'] ] ] ) -def test_search_by_tag_query(caplog, tags_to_search, exp_query, exp_arguments): +def test_search_by_tag_query(caplog, tags_to_search, exp_query, exp_query_p37, exp_arguments): """test that the correct query and argments are constructed""" + if (sys.version_info.major, sys.version_info.minor) == (3, 7): + caplog.set_level(logging.DEBUG) + if exp_query_p37: + exp_query = exp_query_p37 bdb = BukuDb() bdb.search_by_tag(tags_to_search) exp_log = 'query: "{}", args: {}'.format(exp_query, exp_arguments) From fc4f6bff6e6dc3b2058070cadc5537f70965be5b Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 13 Apr 2019 08:02:08 +0800 Subject: [PATCH 3/4] fix: test: test_update_rec_update_all_bookmark for p 3.7 --- tests/test_bukuDb.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index ae28d4a..41e0063 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -1120,7 +1120,7 @@ def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_argum [',tag1,', ',tag2,'] ], [ - 'tag1+tag2,tag3, tag4', + 'tag2+tag2,tag3, tag4', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%' " "OR tags LIKE '%' || ? || '%' OR tags LIKE '%' || ? || '%' ORDER BY id ASC", "SELECT id, url, metadata, tags, desc " @@ -1207,6 +1207,8 @@ def test_update_rec_invalid_tag(caplog, invalid_tag): @pytest.mark.parametrize('read_in_retval', ['y', 'n', '']) def test_update_rec_update_all_bookmark(caplog, read_in_retval): """test method.""" + if (sys.version_info.major, sys.version_info.minor) == (3, 7): + caplog.set_level(logging.DEBUG) with mock.patch('buku.read_in', return_value=read_in_retval): import buku bdb = buku.BukuDb() @@ -1216,8 +1218,12 @@ def test_update_rec_update_all_bookmark(caplog, read_in_retval): return assert res try: - assert caplog.records[0].getMessage() == \ - 'query: "UPDATE bookmarks SET tags = ?", args: [\',tags1\']' + if (sys.version_info.major, sys.version_info.minor) == (3, 7): + assert caplog.records[0].getMessage() == \ + 'update_rec query: "UPDATE bookmarks SET tags = ?", args: [\',tags1,\']' + else: + assert caplog.records[0].getMessage() == \ + 'query: "UPDATE bookmarks SET tags = ?", args: [\',tags1\']' assert caplog.records[0].levelname == 'DEBUG' except IndexError as e: # TODO: fix test From fc9558e6f39750cab96ec535fe3305dd41ba0855 Mon Sep 17 00:00:00 2001 From: rachmadaniHaryono Date: Sat, 13 Apr 2019 08:18:33 +0800 Subject: [PATCH 4/4] fix: test: exp argument test_search_by_tag_query --- tests/test_bukuDb.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 41e0063..2e33b3d 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -1107,7 +1107,7 @@ def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_argum @pytest.mark.parametrize( - 'tags_to_search, exp_query, exp_query_p37, exp_arguments', + 'tags_to_search, exp_query, exp_query_p37, exp_arguments, exp_arguments_p37', [ [ 'tag1, tag2', @@ -1117,7 +1117,8 @@ def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_argum "FROM (SELECT *, CASE WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END + CASE " "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END AS score " "FROM bookmarks WHERE score > 0 ORDER BY score DESC)", - [',tag1,', ',tag2,'] + [',tag1,', ',tag2,'], + None ], [ 'tag2+tag2,tag3, tag4', @@ -1128,30 +1129,35 @@ def test_update_rec_exec_arg(caplog, kwargs, exp_query, exp_query_p37, exp_argum "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END + CASE " "WHEN tags LIKE '%' || ? || '%' THEN 1 ELSE 0 END AS score " "FROM bookmarks WHERE score > 0 ORDER BY score DESC)", - [',tag1+tag2,', ',tag3,', ',tag4,'] + [',tag1+tag2,', ',tag3,', ',tag4,'], + [',tag2+tag2,', ',tag3,', ',tag4,'] ], [ 'tag1 + tag2+tag3', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE tags LIKE '%' || ? || '%' " "AND tags LIKE '%' || ? || '%' ORDER BY id ASC", None, - [',tag1,', ',tag2+tag3,'] + [',tag1,', ',tag2+tag3,'], + None ], [ 'tag1-tag2 + tag 3 - tag4', "SELECT id, url, metadata, tags, desc FROM bookmarks WHERE (tags LIKE '%' || ? || '%' " "AND tags LIKE '%' || ? || '%' ) AND tags NOT REGEXP ? ORDER BY id ASC", None, - [',tag1-tag2,', ',tag 3,', ',tag4,'] + [',tag1-tag2,', ',tag 3,', ',tag4,'], + None ] ] ) -def test_search_by_tag_query(caplog, tags_to_search, exp_query, exp_query_p37, exp_arguments): +def test_search_by_tag_query(caplog, tags_to_search, exp_query, exp_query_p37, exp_arguments, exp_arguments_p37): """test that the correct query and argments are constructed""" if (sys.version_info.major, sys.version_info.minor) == (3, 7): caplog.set_level(logging.DEBUG) if exp_query_p37: exp_query = exp_query_p37 + if exp_arguments_p37: + exp_arguments = exp_arguments_p37 bdb = BukuDb() bdb.search_by_tag(tags_to_search) exp_log = 'query: "{}", args: {}'.format(exp_query, exp_arguments)