blob: a84e4e1b5729fa2d5ce7ebdc7b7afbf6e36c4e5e [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001# 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.
Copybara854996b2021-09-07 19:36:02 +00004
5"""Tests for monorail.tracker.issueadvsearch."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
12from services import service_manager
13from testing import fake
14from testing import testing_helpers
15from tracker import issueadvsearch
16
17class 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ínezf19ea432024-01-23 20:20:52 +010027 self.servlet = issueadvsearch.IssueAdvancedSearch(services=self.services)
Copybara854996b2021-09-07 19:36:02 +000028
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)