Skip to content

Commit

Permalink
Merge pull request #744 from LeXofLeviafan/fix-getrecallbyids
Browse files Browse the repository at this point in the history
fixed get_rec_all_by_ids
  • Loading branch information
jarun authored Jun 3, 2024
2 parents 950b9d8 + c5318f5 commit 704018a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion buku
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ class BukuDb:
"""

placeholder = ', '.join(['?'] * len(indices))
return indices and self._fetch(f'SELECT * FROM bookmarks WHERE id IN ({placeholder})', list(indices))
return indices and self._fetch(f'SELECT * FROM bookmarks WHERE id IN ({placeholder})', *list(indices))

def get_rec_id(self, url):
"""Check if URL already exists in DB.
Expand Down
17 changes: 9 additions & 8 deletions tests/test_bukuDb.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,21 @@ def test_get_rec_by_id(self):
_add_rec(self.bdb, *bookmark)

# the expected bookmark
expected = (
1,
"http://slashdot.org",
"SLASHDOT",
",news,old,",
"News for old nerds, stuff that doesn't matter",
0,
)
expected = (1,) + tuple(TEST_BOOKMARKS[0]) + (0,)
bookmark_from_db = self.bdb.get_rec_by_id(1)
# asserting bookmark matches expected
self.assertEqual(expected, bookmark_from_db)
# asserting None returned if index out of range
self.assertIsNone(self.bdb.get_rec_by_id(len(self.bookmarks[0]) + 1))

def test_get_rec_all_by_ids(self):
for bookmark in self.bookmarks:
# adding bookmark from self.bookmarks
_add_rec(self.bdb, *bookmark)
expected = [(i+1,) + tuple(TEST_BOOKMARKS[i]) + (0,) for i in [0, 2]]
bookmarks_from_db = self.bdb.get_rec_all_by_ids([3, 1, 1, 3, 5]) # ignoring order and duplicates
self.assertEqual(expected, bookmarks_from_db)

def test_get_rec_id(self):
for idx, bookmark in enumerate(self.bookmarks):
# adding bookmark from self.bookmarks to database
Expand Down

0 comments on commit 704018a

Please sign in to comment.