Commit cc71f50ac4b305cab2079dbd4295f68910a0e3b1
Committed by
Matheus Fernandes
1 parent
f8e88aa4
Exists in
colab_search
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
116 additions
and
82 deletions
Show diff stats
colab/search/tests.py
... | ... | @@ -1,82 +0,0 @@ |
1 | -# -*- coding:utf-8 -*- | |
2 | - | |
3 | -import mock | |
4 | - | |
5 | -from colab.plugins.utils import filters_importer | |
6 | -from django.test import TestCase, Client | |
7 | -from django.core.management import call_command | |
8 | - | |
9 | - | |
10 | -class SearchViewTest(TestCase): | |
11 | - | |
12 | - fixtures = ['test_data.json'] | |
13 | - | |
14 | - def setUp(self): | |
15 | - call_command('rebuild_index', interactive=False, verbosity=0) | |
16 | - self.client = Client() | |
17 | - | |
18 | - def tearDown(self): | |
19 | - call_command('clear_index', interactive=False, verbosity=0) | |
20 | - | |
21 | - def test_search_thread(self): | |
22 | - request = self.client.get('/search/?q=thread') | |
23 | - thread_list = request.context['page'].object_list | |
24 | - | |
25 | - self.assertEqual(3, len(thread_list)) | |
26 | - | |
27 | - condition = any('This is a repply to Thread 1 on list A' 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 B' in | |
31 | - t.description for t in thread_list) | |
32 | - self.assertTrue(condition) | |
33 | - condition = any('This is a repply to Thread 1 on list C' in | |
34 | - t.description for t in thread_list) | |
35 | - self.assertTrue(condition) | |
36 | - | |
37 | - def test_search_account_by_firstName(self): | |
38 | - request = self.client.get('/search/?q=Chuck') | |
39 | - user_list = request.context['page'].object_list | |
40 | - | |
41 | - self.assertEqual(1, len(user_list)) | |
42 | - | |
43 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
44 | - self.assertIn('Chuck', user_list[0].object.first_name) | |
45 | - self.assertIn('Norris', user_list[0].object.last_name) | |
46 | - self.assertIn('chucknorris', user_list[0].object.username) | |
47 | - | |
48 | - def test_search_account_by_lastName(self): | |
49 | - request = self.client.get('/search/?q=Norris') | |
50 | - user_list = request.context['page'].object_list | |
51 | - | |
52 | - self.assertEqual(2, len(user_list)) | |
53 | - | |
54 | - self.assertIn('heisenberg@mail.com', user_list[1].object.email) | |
55 | - self.assertIn('Heisenberg', user_list[1].object.first_name) | |
56 | - self.assertIn('Norris', user_list[1].object.last_name) | |
57 | - self.assertIn('heisenbergnorris', user_list[1].object.username) | |
58 | - | |
59 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
60 | - self.assertIn('Chuck', user_list[0].object.first_name) | |
61 | - self.assertIn('Norris', user_list[0].object.last_name) | |
62 | - self.assertIn('chucknorris', user_list[0].object.username) | |
63 | - | |
64 | - def test_search_plugin_filters(self): | |
65 | - plugin_filter = { | |
66 | - 'plugin_name': { | |
67 | - 'name': 'PluginData', | |
68 | - 'icon': 'plugin_icon', | |
69 | - 'fields': ( | |
70 | - ('field_1', 'Field1', ''), | |
71 | - ('field_2', 'Field2', ''), | |
72 | - ), | |
73 | - }, | |
74 | - } | |
75 | - filters_importer.import_plugin_filters = mock.Mock( | |
76 | - return_value=plugin_filter) | |
77 | - | |
78 | - request = self.client.get('/search/?q=') | |
79 | - | |
80 | - value = [('plugin_name', 'PluginData', 'plugin_icon')] | |
81 | - | |
82 | - self.assertEqual(request.context['filters_options'], value) |
... | ... | @@ -0,0 +1,82 @@ |
1 | +# -*- coding:utf-8 -*- | |
2 | + | |
3 | +import mock | |
4 | + | |
5 | +from colab.plugins.utils import filters_importer | |
6 | +from django.test import TestCase, Client | |
7 | +from django.core.management import call_command | |
8 | + | |
9 | + | |
10 | +class SearchViewTest(TestCase): | |
11 | + | |
12 | + fixtures = ['test_data.json'] | |
13 | + | |
14 | + def setUp(self): | |
15 | + call_command('rebuild_index', interactive=False, verbosity=0) | |
16 | + self.client = Client() | |
17 | + | |
18 | + def tearDown(self): | |
19 | + call_command('clear_index', interactive=False, verbosity=0) | |
20 | + | |
21 | + def test_search_thread(self): | |
22 | + request = self.client.get('/search/?q=thread') | |
23 | + thread_list = request.context['page'].object_list | |
24 | + | |
25 | + self.assertEqual(3, len(thread_list)) | |
26 | + | |
27 | + condition = any('This is a repply to Thread 1 on list A' 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 B' in | |
31 | + t.description for t in thread_list) | |
32 | + self.assertTrue(condition) | |
33 | + condition = any('This is a repply to Thread 1 on list C' in | |
34 | + t.description for t in thread_list) | |
35 | + self.assertTrue(condition) | |
36 | + | |
37 | + def test_search_account_by_firstName(self): | |
38 | + request = self.client.get('/search/?q=Chuck') | |
39 | + user_list = request.context['page'].object_list | |
40 | + | |
41 | + self.assertEqual(1, len(user_list)) | |
42 | + | |
43 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
44 | + self.assertIn('Chuck', user_list[0].object.first_name) | |
45 | + self.assertIn('Norris', user_list[0].object.last_name) | |
46 | + self.assertIn('chucknorris', user_list[0].object.username) | |
47 | + | |
48 | + def test_search_account_by_lastName(self): | |
49 | + request = self.client.get('/search/?q=Norris') | |
50 | + user_list = request.context['page'].object_list | |
51 | + | |
52 | + self.assertEqual(2, len(user_list)) | |
53 | + | |
54 | + self.assertIn('heisenberg@mail.com', user_list[1].object.email) | |
55 | + self.assertIn('Heisenberg', user_list[1].object.first_name) | |
56 | + self.assertIn('Norris', user_list[1].object.last_name) | |
57 | + self.assertIn('heisenbergnorris', user_list[1].object.username) | |
58 | + | |
59 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | |
60 | + self.assertIn('Chuck', user_list[0].object.first_name) | |
61 | + self.assertIn('Norris', user_list[0].object.last_name) | |
62 | + self.assertIn('chucknorris', user_list[0].object.username) | |
63 | + | |
64 | + def test_search_plugin_filters(self): | |
65 | + plugin_filter = { | |
66 | + 'plugin_name': { | |
67 | + 'name': 'PluginData', | |
68 | + 'icon': 'plugin_icon', | |
69 | + 'fields': ( | |
70 | + ('field_1', 'Field1', ''), | |
71 | + ('field_2', 'Field2', ''), | |
72 | + ), | |
73 | + }, | |
74 | + } | |
75 | + filters_importer.import_plugin_filters = mock.Mock( | |
76 | + return_value=plugin_filter) | |
77 | + | |
78 | + request = self.client.get('/search/?q=') | |
79 | + | |
80 | + value = [('plugin_name', 'PluginData', 'plugin_icon')] | |
81 | + | |
82 | + self.assertEqual(request.context['filters_options'], value) | ... | ... |
... | ... | @@ -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")) | ... | ... |