diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-09 18:01:13 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2018-11-09 18:01:13 +0100 |
commit | 4bc7a09fb74d6ed5406faae3a63ffb40e3491f7e (patch) | |
tree | 864e908c176de82c252c64a631dbe0bbe081e83a /ishtar_common | |
parent | 680d66127f7eb596f7ae6b934d3ac37834c6336b (diff) | |
download | Ishtar-4bc7a09fb74d6ed5406faae3a63ffb40e3491f7e.tar.bz2 Ishtar-4bc7a09fb74d6ed5406faae3a63ffb40e3491f7e.zip |
Test pin searches (refs #4308)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/tests.py | 28 | ||||
-rw-r--r-- | ishtar_common/views.py | 9 |
2 files changed, 32 insertions, 5 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 65a5a7593..bd1833594 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -1273,6 +1273,34 @@ class ShortMenuTest(TestCase): self.assertEqual(response.status_code, 200) self.assertFalse(str(treat.cached_label) in response.content) + def test_pin_search(self): + c = Client() + c.login(username=self.username, password=self.password) + base_find, find = self._create_find() + + response = c.post( + reverse('pin-search', args=['find']), + {'value': 'Where is my find'}, + **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} + ) + self.assertEqual(response.status_code, 200) + # the selected find search is pined + self.assertEqual(c.session['pin-search-find'], 'Where is my find') + + # empty search save means empty dependant search + c.get( + reverse('pin', args=['contextrecord', + str(base_find.context_record.pk)]) + ) + response = c.post( + reverse('pin-search', args=['find']), + {'value': ''}, + **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'} + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(c.session['pin-search-find'], '') + self.assertEqual(c.session['contextrecord'], '') + def test_update_current_item(self): c = Client() c.login(username=self.username, password=self.password) diff --git a/ishtar_common/views.py b/ishtar_common/views.py index 6fce21953..827d41ea0 100644 --- a/ishtar_common/views.py +++ b/ishtar_common/views.py @@ -457,12 +457,11 @@ def update_current_item(request, item_type=None, pk=None): def pin_search(request, item_type): key = "pin-search-" + item_type - if not item_type or not (request.is_ajax() and request.method == 'POST'): + if not item_type or not ( + request.is_ajax() and request.method == 'POST' + and 'value' in request.POST): raise Http404 - if 'value' in request.POST: - request.session[key] = request.POST['value'] - else: - request.session[key] = request.POST['value'] + request.session[key] = request.POST['value'] if not request.POST['value']: # empty all unpin(request, item_type, cascade=True) |