OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is govered 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 |
| 8 import unittest |
| 9 |
| 10 from services import service_manager |
| 11 from testing import fake |
| 12 from testing import testing_helpers |
| 13 from tracker import issueadvsearch |
| 14 |
| 15 class IssueAdvSearchTest(unittest.TestCase): |
| 16 |
| 17 def setUp(self): |
| 18 self.services = service_manager.Services( |
| 19 config=fake.ConfigService(), |
| 20 issue=fake.IssueService(), |
| 21 user=fake.UserService(), |
| 22 project=fake.ProjectService()) |
| 23 self.project = self.services.project.TestAddProject('proj', project_id=987) |
| 24 self.servlet = issueadvsearch.IssueAdvancedSearch( |
| 25 'req', 'res', services=self.services) |
| 26 |
| 27 def testGatherData(self): |
| 28 mr = testing_helpers.MakeMonorailRequest( |
| 29 path='/p/proj/issues/advsearch') |
| 30 page_data = self.servlet.GatherPageData(mr) |
| 31 |
| 32 self.assertTrue('issue_tab_mode' in page_data) |
| 33 self.assertTrue('page_perms' in page_data) |
| 34 |
| 35 def testProcessFormData(self): |
| 36 mr = testing_helpers.MakeMonorailRequest( |
| 37 path='/p/proj/issues/advsearch') |
| 38 post_data = {} |
| 39 url = self.servlet.ProcessFormData(mr, post_data) |
| 40 self.assertTrue('can=2' in url) |
| 41 |
| 42 post_data['can'] = 42 |
| 43 url = self.servlet.ProcessFormData(mr, post_data) |
| 44 self.assertTrue('can=42' in url) |
| 45 |
| 46 post_data['starcount'] = 42 |
| 47 url = self.servlet.ProcessFormData(mr, post_data) |
| 48 self.assertTrue('starcount%3A42' in url) |
| 49 |
| 50 def _testAND(self, operator, field, post_data, query): |
| 51 self.servlet._AccumulateANDTerm(operator, field, post_data, query) |
| 52 return query |
| 53 |
| 54 def test_AccumulateANDTerm(self): |
| 55 query = self._testAND('', 'foo', {'foo':'bar'}, []) |
| 56 self.assertEquals(['bar'], query) |
| 57 |
| 58 query = self._testAND('', 'bar', {'bar':'baz=zippy'}, query) |
| 59 self.assertEquals(['bar', 'baz', 'zippy'], query) |
| 60 |
| 61 def _testOR(self, operator, field, post_data, query): |
| 62 self.servlet._AccumulateORTerm(operator, field, post_data, query) |
| 63 return query |
| 64 |
| 65 def test_AccumulateORTerm(self): |
| 66 query = self._testOR('', 'foo', {'foo':'bar'}, []) |
| 67 self.assertEquals(['bar'], query) |
| 68 |
| 69 query = self._testOR('', 'bar', {'bar':'baz=zippy'}, query) |
| 70 self.assertEquals(['bar', 'baz,zippy'], query) |
| 71 |
OLD | NEW |