diff --git a/buku b/buku index d8f783d..3ab9caf 100755 --- a/buku +++ b/buku @@ -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 diff --git a/tests/test_bukuDb.py b/tests/test_bukuDb.py index 2d70eef..cb0f079 100644 --- a/tests/test_bukuDb.py +++ b/tests/test_bukuDb.py @@ -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