blob: ce4426aafc8e009b2f2fbe1aeb8e81581ff9a845 [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 the searchpipeline module."""
6from __future__ import print_function
7from __future__ import division
8from __future__ import absolute_import
9
10import unittest
11
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +010012from mrproto import ast_pb2
13from mrproto import tracker_pb2
Copybara854996b2021-09-07 19:36:02 +000014from search import searchpipeline
15from services import service_manager
16from testing import fake
17from tracker import tracker_bizobj
18
19
20class SearchPipelineTest(unittest.TestCase):
21
22 def setUp(self):
23 self.cnxn = 'fake cnxn'
24 self.config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
25 self.services = service_manager.Services(
26 user=fake.UserService(),
27 project=fake.ProjectService(),
28 issue=fake.IssueService(),
29 config=fake.ConfigService())
30 self.services.user.TestAddUser('a@example.com', 111)
31
32 def testIsStarredRE(self):
33 """IS_STARRED_RE matches only the is:starred term."""
34 input_output = {
35 'something:else': 'something:else',
36 'genesis:starred': 'genesis:starred',
37 'is:starred-in-bookmarks': 'is:starred-in-bookmarks',
38 'is:starred': 'foo',
39 'Is:starred': 'foo',
40 'is:STARRED': 'foo',
41 'is:starred is:open': 'foo is:open',
42 'is:open is:starred': 'is:open foo',
43 }
44 for i, o in input_output.items():
45 self.assertEqual(o, searchpipeline.IS_STARRED_RE.sub('foo', i))
46
47 def testMeRE(self):
48 """ME_RE matches only the 'me' value keyword."""
49 input_output = {
50 'something:else': 'something:else',
51 'else:some': 'else:some',
52 'me': 'me', # It needs to have a ":" in front.
53 'cc:me-team': 'cc:me-team',
54 'cc:me=domain@otherdomain': 'cc:me=domain@otherdomain',
55 'cc:me@example.com': 'cc:me@example.com',
56 'me:the-boss': 'me:the-boss',
57 'cc:me': 'cc:foo',
58 'cc=me': 'cc=foo',
59 'owner:Me': 'owner:foo',
60 'reporter:ME': 'reporter:foo',
61 'cc:me is:open': 'cc:foo is:open',
62 'is:open cc:me': 'is:open cc:foo',
63 }
64 for i, o in input_output.items():
65 self.assertEqual(o, searchpipeline.ME_RE.sub('foo', i))
66
67 def testAccumulateIssueProjectsAndConfigs(self):
68 pass # TODO(jrobbins): write tests
69
70 def testReplaceKeywordsWithUserIDs_IsStarred(self):
71 """The term is:starred is replaced with starredby:USERID."""
72 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
73 [111], 'is:starred')
74 self.assertEqual('starredby:111', actual)
75 self.assertEqual([], warnings)
76
77 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
78 [111], 'Pri=1 is:starred M=61')
79 self.assertEqual('Pri=1 starredby:111 M=61', actual)
80 self.assertEqual([], warnings)
81
82 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
83 [], 'Pri=1 is:starred M=61')
84 self.assertEqual('Pri=1 M=61', actual)
85 self.assertEqual(
86 ['"is:starred" ignored because you are not signed in.'],
87 warnings)
88
89 def testReplaceKeywordsWithUserIDs_IsStarred_linked(self):
90 """is:starred is replaced by starredby:uid1,uid2 for linked accounts."""
91 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
92 [111, 222], 'is:starred')
93 self.assertEqual('starredby:111,222', actual)
94 self.assertEqual([], warnings)
95
96 def testReplaceKeywordsWithUserIDs_Me(self):
97 """Terms like owner:me are replaced with owner:USERID."""
98 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
99 [111], 'owner:me')
100 self.assertEqual('owner:111', actual)
101 self.assertEqual([], warnings)
102
103 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
104 [111], 'Pri=1 cc:me M=61')
105 self.assertEqual('Pri=1 cc:111 M=61', actual)
106 self.assertEqual([], warnings)
107
108 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
109 [], 'Pri=1 reporter:me M=61')
110 self.assertEqual('Pri=1 M=61', actual)
111 self.assertEqual(
112 ['"me" keyword ignored because you are not signed in.'],
113 warnings)
114
115 def testReplaceKeywordsWithUserIDs_Me_LinkedAccounts(self):
116 """owner:me is replaced with owner:uid,uid for each linked account."""
117 actual, warnings = searchpipeline.ReplaceKeywordsWithUserIDs(
118 [111, 222], 'owner:me')
119 self.assertEqual('owner:111,222', actual)
120 self.assertEqual([], warnings)