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