fae4ba2e95392f2a6b3284ac5a5ee846a3048c85
[wolnelektury.git] / apps / catalogue / tests.py
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
5
6 class SimpleSearchTest(TestCase):
7     def setUp(self):
8         t = models.Tag(name=u'Tadeusz Żeleński (Boy)', category=u'author', slug=u'a1')
9         t.save()
10         self.t = t
11         self.user = AnonymousUser()
12     
13     def tearDown(self):
14         self.t.delete()
15     
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)
19         
20     def test_match_beginning(self):
21         self.assertEqual(views.find_best_matches(u'Tad', self.user), (self.t,))
22     
23     def test_match_case(self):
24         self.assertEqual(views.find_best_matches(u'TAD', self.user), (self.t,))
25
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,))
29
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), ())
33     
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,))
38     
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,))
42         
43
44
45 class SetSearchTest(TestCase):
46     def setUp(self):
47         self.me = User(name='me')
48         self.other = User(name='other')
49     
50     def tearDown(self):
51         self.me.delete()
52         self.other.delete()
53