1 # -*- coding: utf-8 -*-
2 from django.test import TestCase
3 from catalogue import models, views
4 from django.contrib.auth.models import User, AnonymousUser
6 class SimpleSearchTest(TestCase):
8 t = models.Tag(name=u'Tadeusz Żeleński (Boy)', category=u'author', slug=u'a1')
11 self.user = AnonymousUser()
16 def test_too_short(self):
17 self.assertRaises(ValueError, views.find_best_matches, u'', self.user)
18 self.assertRaises(ValueError, views.find_best_matches, u't', self.user)
20 def test_match_beginning(self):
21 self.assertEqual(views.find_best_matches(u'Tad', self.user), (self.t,))
23 def test_match_case(self):
24 self.assertEqual(views.find_best_matches(u'TAD', self.user), (self.t,))
26 def test_word_boundary(self):
27 self.assertEqual(views.find_best_matches(u'Boy', self.user), (self.t,))
28 self.assertEqual(views.find_best_matches(u'(Boy', self.user), (self.t,))
30 def test_not_found(self):
31 self.assertEqual(views.find_best_matches(u'andrzej', self.user), ())
32 self.assertEqual(views.find_best_matches(u'deusz', self.user), ())
34 def test_locale(self):
35 self.assertEqual(views.find_best_matches(u'ele', self.user), ())
36 self.assertEqual(views.find_best_matches(u'Żele', self.user), (self.t,))
37 self.assertEqual(views.find_best_matches(u'żele', self.user), (self.t,))
39 def test_sloppy(self):
40 self.assertEqual(views.find_best_matches(u'Żelenski', self.user), (self.t,))
41 self.assertEqual(views.find_best_matches(u'zelenski', self.user), (self.t,))
45 class SetSearchTest(TestCase):
47 self.me = User(name='me')
48 self.other = User(name='other')