new: test: test_get_max_id

This commit is contained in:
rachmadaniHaryono 2019-04-28 08:43:54 +08:00
parent bb2e49566a
commit d66d2e3570
2 changed files with 16 additions and 1 deletions

2
buku
View File

@ -518,7 +518,7 @@ class BukuDb:
resultset = self.cur.fetchall()
return resultset[0][0] if resultset else -1
def get_max_id(self):
def get_max_id(self) -> int:
"""Fetch the ID of the last record.
Returns

View File

@ -1435,6 +1435,21 @@ def test_exportdb_single_rec(tmpdir):
assert f.read()
@pytest.mark.parametrize(
'urls, exp_res',
[
[[], -1],
[['http://example.com'], 1],
[['htttp://example.com', 'http://google.com'], 2],
])
def test_get_max_id(urls, exp_res):
with NamedTemporaryFile(delete=False) as f:
db = BukuDb(dbfile=f.name)
if urls:
list(map(lambda x: db.add_rec(x), urls))
assert db.get_max_id() == exp_res
# Helper functions for testcases