Commit 9f770f35306bfbf5c2d33e539d0bc00a082bc8ea
Committed by
Alexandre Barbosa
1 parent
7728549e
Exists in
master
and in
5 other branches
Add search filters tests
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Showing
2 changed files
with
50 additions
and
2 deletions
Show diff stats
colab/search/forms.py
@@ -9,7 +9,7 @@ from haystack.forms import SearchForm | @@ -9,7 +9,7 @@ from haystack.forms import SearchForm | ||
9 | from haystack.inputs import AltParser | 9 | from haystack.inputs import AltParser |
10 | from haystack.inputs import AutoQuery | 10 | from haystack.inputs import AutoQuery |
11 | 11 | ||
12 | -from colab.plugins.utils.filters_importer import import_plugin_filters | 12 | +from colab.plugins.utils import filters_importer |
13 | 13 | ||
14 | 14 | ||
15 | class ColabSearchForm(SearchForm): | 15 | class ColabSearchForm(SearchForm): |
@@ -23,7 +23,7 @@ class ColabSearchForm(SearchForm): | @@ -23,7 +23,7 @@ class ColabSearchForm(SearchForm): | ||
23 | 23 | ||
24 | def __init__(self, *args, **kwargs): | 24 | def __init__(self, *args, **kwargs): |
25 | super(ColabSearchForm, self).__init__(*args, **kwargs) | 25 | super(ColabSearchForm, self).__init__(*args, **kwargs) |
26 | - extra = import_plugin_filters({}) | 26 | + extra = filters_importer.import_plugin_filters({}) |
27 | for filter_types in extra.values(): | 27 | for filter_types in extra.values(): |
28 | for field in filter_types['fields']: | 28 | for field in filter_types['fields']: |
29 | self.fields[field[0]] = forms.CharField(required=False, | 29 | self.fields[field[0]] = forms.CharField(required=False, |
colab/search/tests.py
@@ -5,6 +5,7 @@ import mock | @@ -5,6 +5,7 @@ import mock | ||
5 | from colab.plugins.utils import filters_importer | 5 | from colab.plugins.utils import filters_importer |
6 | from django.test import TestCase, Client | 6 | from django.test import TestCase, Client |
7 | from django.core.management import call_command | 7 | from django.core.management import call_command |
8 | +from colab.search.forms import ColabSearchForm | ||
8 | 9 | ||
9 | 10 | ||
10 | class SearchViewTest(TestCase): | 11 | class SearchViewTest(TestCase): |
@@ -80,3 +81,50 @@ class SearchViewTest(TestCase): | @@ -80,3 +81,50 @@ class SearchViewTest(TestCase): | ||
80 | value = [('plugin_name', 'PluginData', 'plugin_icon')] | 81 | value = [('plugin_name', 'PluginData', 'plugin_icon')] |
81 | 82 | ||
82 | self.assertEqual(request.context['filters_options'], value) | 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) |