Feature/test add rec (#140)

* new: test: test empty url.

* new: test: test is_bad_url

* new: test: network_handler

* new: test: test exec arg on add_rec

* fix: test: restore global variable.

* chg: test: change test

- add more falsey url for test_add_rec_add_invalid_url
- add more arg for test_add_rec_exec_arg

* chg: test: use old test when testing is_bad_url
This commit is contained in:
rachmadani haryono 2017-03-31 00:52:47 +08:00 committed by Arun Prakash Jana
parent b978672e50
commit f25f67bfc1
2 changed files with 81 additions and 2 deletions

View File

@ -18,13 +18,18 @@ only_python_3_5 = pytest.mark.skipif(sys.version_info < (3, 5), reason="requires
@pytest.mark.parametrize(
'url, exp_res',
[
('http://example.com', False),
['http://example.com', False],
['ftp://ftp.somedomain.org', False],
['http://examplecom.', True],
['http://.example.com', True],
['http://example.com.', True],
]
)
def test_is_bad_url(url, exp_res):
"""test func."""
import buku
assert exp_res == buku.is_bad_url(url)
res = buku.is_bad_url(url)
assert res == exp_res
@pytest.mark.parametrize(
@ -479,3 +484,21 @@ def test_sigint_handler(capsys):
# assert proper error message
assert out == ''
assert err == "\nInterrupted.\n"
@pytest.mark.parametrize(
'url, exp_res',
[
['http://example.com.', ('', 0, 1)],
['http://example.com', ('Example Domain', 0, 0)],
['http://example.com/page1.txt', (('', 1, 0))],
]
)
def test_network_handler_with_url(url, exp_res):
"""test func."""
import buku
import urllib3
buku.urllib3 = urllib3
buku.myproxy = None
res = buku.network_handler(url)
assert res == exp_res

View File

@ -748,6 +748,62 @@ def test_delete_rec_on_non_interger(index, low, high, is_range):
assert bdb.delete_rec(index=index, low=low, high=high, is_range=is_range)
@pytest.mark.parametrize('url', ['', False, None, 0])
def test_add_rec_add_invalid_url(caplog, url):
"""test method."""
bdb = BukuDb()
res = bdb.add_rec(url=url)
assert res == -1
caplog.records[0].levelname == 'ERROR'
caplog.records[0].getMessage() == 'Invalid URL'
@pytest.mark.parametrize(
"kwargs, exp_arg",
[
[
{'url': 'example.com'},
('example.com', 'Example Domain', ',', '', 0)
],
[
{'url': 'http://example.com'},
('http://example.com', 'Example Domain', ',', '', 0)
],
[
{'url': 'http://example.com', 'immutable': 1},
('http://example.com', 'Example Domain', ',', '', 1)
],
[
{'url': 'http://example.com', 'desc': 'randomdesc'},
('http://example.com', 'Example Domain', ',', 'randomdesc', 0)
],
[
{'url': 'http://example.com', 'title_in': 'randomtitle'},
('http://example.com', 'randomtitle', ',', '', 0)
],
[
{'url': 'http://example.com', 'tags_in': 'tag1'},
('http://example.com', 'Example Domain', ',tag1', '', 0),
],
[
{'url': 'http://example.com', 'tags_in': ',tag1'},
('http://example.com', 'Example Domain', ',tag1,', '', 0),
],
[
{'url': 'http://example.com', 'tags_in': ',tag1,'},
('http://example.com', 'Example Domain', ',tag1,', '', 0),
],
]
)
def test_add_rec_exec_arg(kwargs, exp_arg):
"""test func."""
bdb = BukuDb()
bdb.cur = mock.Mock()
bdb.get_rec_id = mock.Mock(return_value=-1)
bdb.add_rec(**kwargs)
assert bdb.cur.execute.call_args[0][1] == exp_arg
# Helper functions for testcases