Skip to content

Commit

Permalink
Add test that forces book_authors_search_vector_trigger to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Nov 26, 2023
1 parent b5805ac commit d6eb390
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bookwyrm/tests/test_book_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ def test_search_after_author_add(self):
self.assertEqual(self.edition, self._search_first("Mozilla"))
self.assertEqual(self.edition, self._search_first("Name"))

def test_search_after_author_add_remove_sql(self):
"""add/remove author through SQL to ensure execution of book_authors trigger"""
# Tests calling edition.save(), above, pass even if the trigger in
# bookwyrm_book_authors is removed (probably because they trigger the one
# in bookwyrm_book directly). Here we make sure to exercise the former.
new_author = models.Author.objects.create(name="Mozilla")

with connection.cursor() as cursor:
cursor.execute(
"DELETE FROM bookwyrm_book_authors WHERE book_id = %s",
[self.edition.id],
)
self.assertFalse(self._search("Name"))
self.assertFalse(self._search("Mozilla"))

with connection.cursor() as cursor:
cursor.execute(
"INSERT INTO bookwyrm_book_authors (book_id,author_id) VALUES (%s,%s)",
[self.edition.id, new_author.id],
)
self.assertFalse(self._search("Name"))
self.assertEqual(self.edition, self._search_first("Mozilla"))

def test_search_after_updated_author_name(self):
"""book found under new author name"""
self.assertEqual(self.edition, self._search_first("Name"))
Expand Down

0 comments on commit d6eb390

Please sign in to comment.