Commit 1137d15b8ee4ffb3b0a4a55c5bdae764938c2e2b
1 parent
cd78bd85
Exists in
search_block
Test get_template_search_preview template tag
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Lucas Moura <lucas.moura28@gmail.com> Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com>
Showing
4 changed files
with
93 additions
and
59 deletions
Show diff stats
colab/search/tests.py
... | ... | @@ -1,59 +0,0 @@ |
1 | -# -*- coding:utf-8 -*- | |
2 | - | |
3 | -from django.test import TestCase, Client | |
4 | -from django.core.management import call_command | |
5 | - | |
6 | - | |
7 | -class SearchViewTest(TestCase): | |
8 | - | |
9 | - fixtures = ['test_data.json'] | |
10 | - | |
11 | - def setUp(self): | |
12 | - call_command('rebuild_index', interactive=False, verbosity=0) | |
13 | - self.client = Client() | |
14 | - | |
15 | - def tearDown(self): | |
16 | - call_command('clear_index', interactive=False, verbosity=0) | |
17 | - | |
18 | - def test_search_thread(self): | |
19 | - request = self.client.get('/search/?q=thread') | |
20 | - thread_list = request.context['page'].object_list | |
21 | - | |
22 | - self.assertEqual(3, len(thread_list)) | |
23 | - | |
24 | - condition = any('This is a repply to Thread 1 on list A' in | |
25 | - t.description for t in thread_list) | |
26 | - self.assertTrue(condition) | |
27 | - condition = any('This is a repply to Thread 1 on list B' in | |
28 | - t.description for t in thread_list) | |
29 | - self.assertTrue(condition) | |
30 | - condition = any('This is a repply to Thread 1 on list C' in | |
31 | - t.description for t in thread_list) | |
32 | - self.assertTrue(condition) | |
33 | - | |
34 | - def test_search_account_by_firstName(self): | |
35 | - request = self.client.get('/search/?q=Chuck') | |
36 | - user_list = request.context['page'].object_list | |
37 | - | |
38 | - self.assertEqual(1, len(user_list)) | |
39 | - | |
40 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
41 | - self.assertIn('Chuck', user_list[0].object.first_name) | |
42 | - self.assertIn('Norris', user_list[0].object.last_name) | |
43 | - self.assertIn('chucknorris', user_list[0].object.username) | |
44 | - | |
45 | - def test_search_account_by_lastName(self): | |
46 | - request = self.client.get('/search/?q=Norris') | |
47 | - user_list = request.context['page'].object_list | |
48 | - | |
49 | - self.assertEqual(2, len(user_list)) | |
50 | - | |
51 | - self.assertIn('heisenberg@mail.com', user_list[1].object.email) | |
52 | - self.assertIn('Heisenberg', user_list[1].object.first_name) | |
53 | - self.assertIn('Norris', user_list[1].object.last_name) | |
54 | - self.assertIn('heisenbergnorris', user_list[1].object.username) | |
55 | - | |
56 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
57 | - self.assertIn('Chuck', user_list[0].object.first_name) | |
58 | - self.assertIn('Norris', user_list[0].object.last_name) | |
59 | - self.assertIn('chucknorris', user_list[0].object.username) |
... | ... | @@ -0,0 +1,59 @@ |
1 | +# -*- coding:utf-8 -*- | |
2 | + | |
3 | +from django.test import TestCase, Client | |
4 | +from django.core.management import call_command | |
5 | + | |
6 | + | |
7 | +class SearchViewTest(TestCase): | |
8 | + | |
9 | + fixtures = ['test_data.json'] | |
10 | + | |
11 | + def setUp(self): | |
12 | + call_command('rebuild_index', interactive=False, verbosity=0) | |
13 | + self.client = Client() | |
14 | + | |
15 | + def tearDown(self): | |
16 | + call_command('clear_index', interactive=False, verbosity=0) | |
17 | + | |
18 | + def test_search_thread(self): | |
19 | + request = self.client.get('/search/?q=thread') | |
20 | + thread_list = request.context['page'].object_list | |
21 | + | |
22 | + self.assertEqual(3, len(thread_list)) | |
23 | + | |
24 | + condition = any('This is a repply to Thread 1 on list A' in | |
25 | + t.description for t in thread_list) | |
26 | + self.assertTrue(condition) | |
27 | + condition = any('This is a repply to Thread 1 on list B' in | |
28 | + t.description for t in thread_list) | |
29 | + self.assertTrue(condition) | |
30 | + condition = any('This is a repply to Thread 1 on list C' in | |
31 | + t.description for t in thread_list) | |
32 | + self.assertTrue(condition) | |
33 | + | |
34 | + def test_search_account_by_firstName(self): | |
35 | + request = self.client.get('/search/?q=Chuck') | |
36 | + user_list = request.context['page'].object_list | |
37 | + | |
38 | + self.assertEqual(1, len(user_list)) | |
39 | + | |
40 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
41 | + self.assertIn('Chuck', user_list[0].object.first_name) | |
42 | + self.assertIn('Norris', user_list[0].object.last_name) | |
43 | + self.assertIn('chucknorris', user_list[0].object.username) | |
44 | + | |
45 | + def test_search_account_by_lastName(self): | |
46 | + request = self.client.get('/search/?q=Norris') | |
47 | + user_list = request.context['page'].object_list | |
48 | + | |
49 | + self.assertEqual(2, len(user_list)) | |
50 | + | |
51 | + self.assertIn('heisenberg@mail.com', user_list[1].object.email) | |
52 | + self.assertIn('Heisenberg', user_list[1].object.first_name) | |
53 | + self.assertIn('Norris', user_list[1].object.last_name) | |
54 | + self.assertIn('heisenbergnorris', user_list[1].object.username) | |
55 | + | |
56 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
57 | + self.assertIn('Chuck', user_list[0].object.first_name) | |
58 | + self.assertIn('Norris', user_list[0].object.last_name) | |
59 | + self.assertIn('chucknorris', user_list[0].object.username) | ... | ... |
... | ... | @@ -0,0 +1,34 @@ |
1 | +# -*- coding:utf-8 -*- | |
2 | + | |
3 | +from django.test import TestCase | |
4 | +from colab.search.templatetags.search_preview_templates import ( | |
5 | + get_search_preview_templates) | |
6 | +from mock import MagicMock, PropertyMock | |
7 | + | |
8 | + | |
9 | +class SearchTemplateTagsTest(TestCase): | |
10 | + | |
11 | + def setUp(self): | |
12 | + self.model_indexed_mock = MagicMock() | |
13 | + self.template_path = "{}/{}_search_preview.html" | |
14 | + | |
15 | + def set_mock_value(self, value): | |
16 | + type(self.model_indexed_mock).type = PropertyMock(return_value=value) | |
17 | + | |
18 | + def test_get_search_preview_templates_with_user(self): | |
19 | + self.set_mock_value("user") | |
20 | + include_path = get_search_preview_templates(self.model_indexed_mock) | |
21 | + self.assertEqual(include_path, self.template_path.format("accounts", | |
22 | + "user")) | |
23 | + | |
24 | + def test_get_search_preview_templates_with_thread(self): | |
25 | + self.set_mock_value("thread") | |
26 | + include_path = get_search_preview_templates(self.model_indexed_mock) | |
27 | + self.assertEqual(include_path, | |
28 | + self.template_path.format("superarchives", "thread")) | |
29 | + | |
30 | + def test_get_search_preview_templates_with_plugin(self): | |
31 | + self.set_mock_value("plugin_model") | |
32 | + include_path = get_search_preview_templates(self.model_indexed_mock) | |
33 | + self.assertEqual(include_path, self.template_path.format("plugin", | |
34 | + "model")) | ... | ... |