3 from mygpo
.podcasts
.models
import Podcast
4 from django
.contrib
.postgres
.search
import SearchVector
5 from django
.test
import TransactionTestCase
6 from django
.test
.utils
import override_settings
8 from .index
import search_podcasts
9 from .tasks
import update_search_index
12 class SearchTests(TransactionTestCase
):
13 """Tests podcast search"""
15 def test_search_podcast(self
):
16 """Search if a podcast is found in the search results"""
21 title
="Awesome Podcast",
22 description
="An amazing podcast on many topics",
26 # explicitly trigger a search index update
29 # search for the podcast
30 results
= search_podcasts("awesome")
31 self
.assertEqual(results
[0].id, podcast
.id)
33 @override_settings(QUERY_LENGTH_CUTOFF
=3)
34 def test_shortest_search_podcast(self
):
36 Search for a podcast with query length smaller than 3
37 With QUERY_LENGTH_CUTOFF = 3
38 Server would normally time out, however Podcasts exist for the given
44 title
="The Tricky Podcast",
45 description
="The only podcast containing tricky messages.",
49 # explicitly trigger a search index update
52 results
= search_podcasts("The")
53 self
.assertEqual(len(results
), 0)
55 results
= search_podcasts("The Tricky")
56 self
.assertEqual(results
[0].id, podcast
.id)