Merge pull request #799 from maxthomas/fix-openapi-comment
[mygpo.git] / mygpo / search / tests.py
blob418b7f920c92f887fd467fb8706f59fc54927917
1 import uuid
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"""
18 # create a podcast
19 podcast = Podcast(
20 id=uuid.uuid1(),
21 title="Awesome Podcast",
22 description="An amazing podcast on many topics",
24 podcast.save()
26 # explicitly trigger a search index update
27 update_search_index()
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):
35 """
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
39 search term.
40 """
41 # create a podcast
42 podcast = Podcast(
43 id=uuid.uuid1(),
44 title="The Tricky Podcast",
45 description="The only podcast containing tricky messages.",
47 podcast.save()
49 # explicitly trigger a search index update
50 update_search_index()
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)