Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Tests for monorail.tracker.issueadvsearch.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | import unittest |
| 11 | |
| 12 | from services import service_manager |
| 13 | from testing import fake |
| 14 | from testing import testing_helpers |
| 15 | from tracker import issueadvsearch |
| 16 | |
| 17 | class IssueAdvSearchTest(unittest.TestCase): |
| 18 | |
| 19 | def setUp(self): |
| 20 | self.services = service_manager.Services( |
| 21 | config=fake.ConfigService(), |
| 22 | features=fake.FeaturesService(), |
| 23 | issue=fake.IssueService(), |
| 24 | user=fake.UserService(), |
| 25 | project=fake.ProjectService()) |
| 26 | self.project = self.services.project.TestAddProject('proj', project_id=987) |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame^] | 27 | self.servlet = issueadvsearch.IssueAdvancedSearch(services=self.services) |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 28 | |
| 29 | def testGatherData(self): |
| 30 | mr = testing_helpers.MakeMonorailRequest( |
| 31 | path='/p/proj/issues/advsearch') |
| 32 | page_data = self.servlet.GatherPageData(mr) |
| 33 | |
| 34 | self.assertTrue('issue_tab_mode' in page_data) |
| 35 | self.assertTrue('page_perms' in page_data) |
| 36 | |
| 37 | def testProcessFormData(self): |
| 38 | mr = testing_helpers.MakeMonorailRequest( |
| 39 | path='/p/proj/issues/advsearch') |
| 40 | post_data = {} |
| 41 | url = self.servlet.ProcessFormData(mr, post_data) |
| 42 | self.assertTrue('can=2' in url) |
| 43 | |
| 44 | post_data['can'] = 42 |
| 45 | url = self.servlet.ProcessFormData(mr, post_data) |
| 46 | self.assertTrue('can=42' in url) |
| 47 | |
| 48 | post_data['starcount'] = 42 |
| 49 | url = self.servlet.ProcessFormData(mr, post_data) |
| 50 | self.assertTrue('starcount%3A42' in url) |
| 51 | |
| 52 | post_data['starcount'] = -1 |
| 53 | url = self.servlet.ProcessFormData(mr, post_data) |
| 54 | self.assertTrue('starcount' not in url) |
| 55 | |
| 56 | def _testAND(self, operator, field, post_data, query): |
| 57 | self.servlet._AccumulateANDTerm(operator, field, post_data, query) |
| 58 | return query |
| 59 | |
| 60 | def test_AccumulateANDTerm(self): |
| 61 | query = self._testAND('', 'foo', {'foo': 'bar'}, []) |
| 62 | self.assertEqual(['bar'], query) |
| 63 | |
| 64 | query = self._testAND('', 'bar', {'bar': 'baz=zippy'}, query) |
| 65 | self.assertEqual(['bar', 'baz', 'zippy'], query) |
| 66 | |
| 67 | def _testOR(self, operator, field, post_data, query): |
| 68 | self.servlet._AccumulateORTerm(operator, field, post_data, query) |
| 69 | return query |
| 70 | |
| 71 | def test_AccumulateORTerm(self): |
| 72 | query = self._testOR('', 'foo', {'foo': 'bar'}, []) |
| 73 | self.assertEqual(['bar'], query) |
| 74 | |
| 75 | query = self._testOR('', 'bar', {'bar': 'baz=zippy'}, query) |
| 76 | self.assertEqual(['bar', 'baz,zippy'], query) |