Commit f64d8e8be4151be00b7b5becd64c802b123a0e9f
Committed by
Luiz Oliveira
1 parent
b844dd9d
Exists in
master
and in
4 other branches
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
164 additions
and
130 deletions
Show diff stats
colab/search/tests.py
@@ -1,130 +0,0 @@ | @@ -1,130 +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 | -from colab.search.forms import ColabSearchForm | ||
9 | - | ||
10 | - | ||
11 | -class SearchViewTest(TestCase): | ||
12 | - | ||
13 | - fixtures = ['test_data.json'] | ||
14 | - | ||
15 | - def setUp(self): | ||
16 | - call_command('rebuild_index', interactive=False, verbosity=0) | ||
17 | - self.client = Client() | ||
18 | - | ||
19 | - def tearDown(self): | ||
20 | - call_command('clear_index', interactive=False, verbosity=0) | ||
21 | - | ||
22 | - def test_search_thread(self): | ||
23 | - request = self.client.get('/search/?q=thread') | ||
24 | - thread_list = request.context['page'].object_list | ||
25 | - | ||
26 | - self.assertEqual(3, len(thread_list)) | ||
27 | - | ||
28 | - condition = any('This is a repply to Thread 1 on list A' in | ||
29 | - t.description for t in thread_list) | ||
30 | - self.assertTrue(condition) | ||
31 | - condition = any('This is a repply to Thread 1 on list B' in | ||
32 | - t.description for t in thread_list) | ||
33 | - self.assertTrue(condition) | ||
34 | - condition = any('This is a repply to Thread 1 on list C' in | ||
35 | - t.description for t in thread_list) | ||
36 | - self.assertTrue(condition) | ||
37 | - | ||
38 | - def test_search_account_by_firstName(self): | ||
39 | - request = self.client.get('/search/?q=Chuck') | ||
40 | - user_list = request.context['page'].object_list | ||
41 | - | ||
42 | - self.assertEqual(1, len(user_list)) | ||
43 | - | ||
44 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
45 | - self.assertIn('Chuck', user_list[0].object.first_name) | ||
46 | - self.assertIn('Norris', user_list[0].object.last_name) | ||
47 | - self.assertIn('chucknorris', user_list[0].object.username) | ||
48 | - | ||
49 | - def test_search_account_by_lastName(self): | ||
50 | - request = self.client.get('/search/?q=Norris') | ||
51 | - user_list = request.context['page'].object_list | ||
52 | - | ||
53 | - self.assertEqual(2, len(user_list)) | ||
54 | - | ||
55 | - self.assertIn('heisenberg@mail.com', user_list[1].object.email) | ||
56 | - self.assertIn('Heisenberg', user_list[1].object.first_name) | ||
57 | - self.assertIn('Norris', user_list[1].object.last_name) | ||
58 | - self.assertIn('heisenbergnorris', user_list[1].object.username) | ||
59 | - | ||
60 | - self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
61 | - self.assertIn('Chuck', user_list[0].object.first_name) | ||
62 | - self.assertIn('Norris', user_list[0].object.last_name) | ||
63 | - self.assertIn('chucknorris', user_list[0].object.username) | ||
64 | - | ||
65 | - def test_search_plugin_filters(self): | ||
66 | - plugin_filter = { | ||
67 | - 'plugin_name': { | ||
68 | - 'name': 'PluginData', | ||
69 | - 'icon': 'plugin_icon', | ||
70 | - 'fields': ( | ||
71 | - ('field_1', 'Field1', ''), | ||
72 | - ('field_2', 'Field2', ''), | ||
73 | - ), | ||
74 | - }, | ||
75 | - } | ||
76 | - filters_importer.import_plugin_filters = mock.Mock( | ||
77 | - return_value=plugin_filter) | ||
78 | - | ||
79 | - request = self.client.get('/search/?q=') | ||
80 | - | ||
81 | - value = [('plugin_name', 'PluginData', 'plugin_icon')] | ||
82 | - | ||
83 | - self.assertEqual(request.context['filters_options'], value) | ||
84 | - | ||
85 | - def test_search_dynamic_form_fields(self): | ||
86 | - plugin_filter = { | ||
87 | - 'plugin_name': { | ||
88 | - 'name': 'PluginData', | ||
89 | - 'icon': 'plugin_icon', | ||
90 | - 'fields': ( | ||
91 | - ('field_1', 'Field1', ''), | ||
92 | - ('field_2', 'Field2', ''), | ||
93 | - ), | ||
94 | - }, | ||
95 | - } | ||
96 | - filters_importer.import_plugin_filters = mock.Mock( | ||
97 | - return_value=plugin_filter) | ||
98 | - | ||
99 | - form = ColabSearchForm() | ||
100 | - | ||
101 | - self.assertIn('field_1', form.fields.keys()) | ||
102 | - self.assertIn('field_2', form.fields.keys()) | ||
103 | - | ||
104 | - def test_search_multiple_filters(self): | ||
105 | - request = self.client.get('/search/?q=&type=thread+user') | ||
106 | - user_list = request.context['page'].object_list | ||
107 | - | ||
108 | - self.assertEqual(6, len(user_list)) | ||
109 | - | ||
110 | - self.assertIn('admin@mail.com', user_list[0].object.email) | ||
111 | - self.assertIn('admin', user_list[0].object.username) | ||
112 | - | ||
113 | - self.assertIn('chucknorris@mail.com', user_list[1].object.email) | ||
114 | - self.assertIn('Chuck', user_list[1].object.first_name) | ||
115 | - self.assertIn('Norris', user_list[1].object.last_name) | ||
116 | - self.assertIn('chucknorris', user_list[1].object.username) | ||
117 | - | ||
118 | - self.assertIn('heisenberg@mail.com', user_list[2].object.email) | ||
119 | - self.assertIn('Heisenberg', user_list[2].object.first_name) | ||
120 | - self.assertIn('Norris', user_list[2].object.last_name) | ||
121 | - self.assertIn('heisenbergnorris', user_list[2].object.username) | ||
122 | - | ||
123 | - self.assertIn('Admin Administrator', user_list[3].author) | ||
124 | - self.assertIn('Response to Thread 1A', user_list[3].title) | ||
125 | - | ||
126 | - self.assertIn('Admin Administrator', user_list[4].author) | ||
127 | - self.assertIn('Message 1 on Thread 1B', user_list[4].title) | ||
128 | - | ||
129 | - self.assertIn('Admin Administrator', user_list[5].author) | ||
130 | - self.assertIn('Message 1 on Thread 1C', user_list[5].title) |
@@ -0,0 +1,130 @@ | @@ -0,0 +1,130 @@ | ||
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 | +from colab.search.forms import ColabSearchForm | ||
9 | + | ||
10 | + | ||
11 | +class SearchViewTest(TestCase): | ||
12 | + | ||
13 | + fixtures = ['test_data.json'] | ||
14 | + | ||
15 | + def setUp(self): | ||
16 | + call_command('rebuild_index', interactive=False, verbosity=0) | ||
17 | + self.client = Client() | ||
18 | + | ||
19 | + def tearDown(self): | ||
20 | + call_command('clear_index', interactive=False, verbosity=0) | ||
21 | + | ||
22 | + def test_search_thread(self): | ||
23 | + request = self.client.get('/search/?q=thread') | ||
24 | + thread_list = request.context['page'].object_list | ||
25 | + | ||
26 | + self.assertEqual(3, len(thread_list)) | ||
27 | + | ||
28 | + condition = any('This is a repply to Thread 1 on list A' in | ||
29 | + t.description for t in thread_list) | ||
30 | + self.assertTrue(condition) | ||
31 | + condition = any('This is a repply to Thread 1 on list B' in | ||
32 | + t.description for t in thread_list) | ||
33 | + self.assertTrue(condition) | ||
34 | + condition = any('This is a repply to Thread 1 on list C' in | ||
35 | + t.description for t in thread_list) | ||
36 | + self.assertTrue(condition) | ||
37 | + | ||
38 | + def test_search_account_by_firstName(self): | ||
39 | + request = self.client.get('/search/?q=Chuck') | ||
40 | + user_list = request.context['page'].object_list | ||
41 | + | ||
42 | + self.assertEqual(1, len(user_list)) | ||
43 | + | ||
44 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
45 | + self.assertIn('Chuck', user_list[0].object.first_name) | ||
46 | + self.assertIn('Norris', user_list[0].object.last_name) | ||
47 | + self.assertIn('chucknorris', user_list[0].object.username) | ||
48 | + | ||
49 | + def test_search_account_by_lastName(self): | ||
50 | + request = self.client.get('/search/?q=Norris') | ||
51 | + user_list = request.context['page'].object_list | ||
52 | + | ||
53 | + self.assertEqual(2, len(user_list)) | ||
54 | + | ||
55 | + self.assertIn('heisenberg@mail.com', user_list[1].object.email) | ||
56 | + self.assertIn('Heisenberg', user_list[1].object.first_name) | ||
57 | + self.assertIn('Norris', user_list[1].object.last_name) | ||
58 | + self.assertIn('heisenbergnorris', user_list[1].object.username) | ||
59 | + | ||
60 | + self.assertIn('chucknorris@mail.com', user_list[0].object.email) | ||
61 | + self.assertIn('Chuck', user_list[0].object.first_name) | ||
62 | + self.assertIn('Norris', user_list[0].object.last_name) | ||
63 | + self.assertIn('chucknorris', user_list[0].object.username) | ||
64 | + | ||
65 | + def test_search_plugin_filters(self): | ||
66 | + plugin_filter = { | ||
67 | + 'plugin_name': { | ||
68 | + 'name': 'PluginData', | ||
69 | + 'icon': 'plugin_icon', | ||
70 | + 'fields': ( | ||
71 | + ('field_1', 'Field1', ''), | ||
72 | + ('field_2', 'Field2', ''), | ||
73 | + ), | ||
74 | + }, | ||
75 | + } | ||
76 | + filters_importer.import_plugin_filters = mock.Mock( | ||
77 | + return_value=plugin_filter) | ||
78 | + | ||
79 | + request = self.client.get('/search/?q=') | ||
80 | + | ||
81 | + value = [('plugin_name', 'PluginData', 'plugin_icon')] | ||
82 | + | ||
83 | + self.assertEqual(request.context['filters_options'], value) | ||
84 | + | ||
85 | + def test_search_dynamic_form_fields(self): | ||
86 | + plugin_filter = { | ||
87 | + 'plugin_name': { | ||
88 | + 'name': 'PluginData', | ||
89 | + 'icon': 'plugin_icon', | ||
90 | + 'fields': ( | ||
91 | + ('field_1', 'Field1', ''), | ||
92 | + ('field_2', 'Field2', ''), | ||
93 | + ), | ||
94 | + }, | ||
95 | + } | ||
96 | + filters_importer.import_plugin_filters = mock.Mock( | ||
97 | + return_value=plugin_filter) | ||
98 | + | ||
99 | + form = ColabSearchForm() | ||
100 | + | ||
101 | + self.assertIn('field_1', form.fields.keys()) | ||
102 | + self.assertIn('field_2', form.fields.keys()) | ||
103 | + | ||
104 | + def test_search_multiple_filters(self): | ||
105 | + request = self.client.get('/search/?q=&type=thread+user') | ||
106 | + user_list = request.context['page'].object_list | ||
107 | + | ||
108 | + self.assertEqual(6, len(user_list)) | ||
109 | + | ||
110 | + self.assertIn('admin@mail.com', user_list[0].object.email) | ||
111 | + self.assertIn('admin', user_list[0].object.username) | ||
112 | + | ||
113 | + self.assertIn('chucknorris@mail.com', user_list[1].object.email) | ||
114 | + self.assertIn('Chuck', user_list[1].object.first_name) | ||
115 | + self.assertIn('Norris', user_list[1].object.last_name) | ||
116 | + self.assertIn('chucknorris', user_list[1].object.username) | ||
117 | + | ||
118 | + self.assertIn('heisenberg@mail.com', user_list[2].object.email) | ||
119 | + self.assertIn('Heisenberg', user_list[2].object.first_name) | ||
120 | + self.assertIn('Norris', user_list[2].object.last_name) | ||
121 | + self.assertIn('heisenbergnorris', user_list[2].object.username) | ||
122 | + | ||
123 | + self.assertIn('Admin Administrator', user_list[3].author) | ||
124 | + self.assertIn('Response to Thread 1A', user_list[3].title) | ||
125 | + | ||
126 | + self.assertIn('Admin Administrator', user_list[4].author) | ||
127 | + self.assertIn('Message 1 on Thread 1B', user_list[4].title) | ||
128 | + | ||
129 | + self.assertIn('Admin Administrator', user_list[5].author) | ||
130 | + self.assertIn('Message 1 on Thread 1C', user_list[5].title) |
@@ -0,0 +1,34 @@ | @@ -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")) |