Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: appengine/monorail/features/test/commands_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 """Classes and functions that implement command-line-like issue updates."""
7
8 import logging
9 import unittest
10
11 from features import commands
12 from framework import framework_constants
13 from proto import tracker_pb2
14 from services import service_manager
15 from testing import fake
16 from tracker import tracker_bizobj
17 from tracker import tracker_constants
18
19
20 class CommandsTest(unittest.TestCase):
21
22 def VerifyParseQuickEditCommmand(
23 self, cmd, exp_summary='sum', exp_status='New', exp_owner_id=111L,
24 exp_cc_ids=None, exp_labels=None):
25
26 issue = tracker_pb2.Issue()
27 issue.project_name = 'proj'
28 issue.local_id = 1
29 issue.summary = 'sum'
30 issue.status = 'New'
31 issue.owner_id = 111L
32 issue.cc_ids.extend([222L, 333L])
33 issue.labels.extend(['Type-Defect', 'Priority-Medium', 'Hot'])
34
35 if exp_cc_ids is None:
36 exp_cc_ids = [222L, 333L]
37 if exp_labels is None:
38 exp_labels = ['Type-Defect', 'Priority-Medium', 'Hot']
39
40 config = tracker_bizobj.MakeDefaultProjectIssueConfig(789)
41 logged_in_user_id = 999L
42 services = service_manager.Services(
43 config=fake.ConfigService(),
44 issue=fake.IssueService(),
45 user=fake.UserService())
46 services.user.TestAddUser('jrobbins', 333L)
47 services.user.TestAddUser('jrobbins@jrobbins.org', 888L)
48
49 cnxn = 'fake cnxn'
50 (summary, status, owner_id, cc_ids,
51 labels) = commands.ParseQuickEditCommand(
52 cnxn, cmd, issue, config, logged_in_user_id, services)
53 self.assertEqual(exp_summary, summary)
54 self.assertEqual(exp_status, status)
55 self.assertEqual(exp_owner_id, owner_id)
56 self.assertListEqual(exp_cc_ids, cc_ids)
57 self.assertListEqual(exp_labels, labels)
58
59 def testParseQuickEditCommmand_Empty(self):
60 self.VerifyParseQuickEditCommmand('') # Nothing should change.
61
62 def testParseQuickEditCommmand_BuiltInFields(self):
63 self.VerifyParseQuickEditCommmand(
64 'status=Fixed', exp_status='Fixed')
65 self.VerifyParseQuickEditCommmand( # Normalized capitalization.
66 'status=fixed', exp_status='Fixed')
67 self.VerifyParseQuickEditCommmand(
68 'status=limbo', exp_status='limbo')
69
70 self.VerifyParseQuickEditCommmand(
71 'owner=me', exp_owner_id=999L)
72 self.VerifyParseQuickEditCommmand(
73 'owner=jrobbins@jrobbins.org', exp_owner_id=888L)
74 self.VerifyParseQuickEditCommmand(
75 'owner=----', exp_owner_id=framework_constants.NO_USER_SPECIFIED)
76
77 self.VerifyParseQuickEditCommmand(
78 'summary=JustOneWord', exp_summary='JustOneWord')
79 self.VerifyParseQuickEditCommmand(
80 'summary="quoted sentence"', exp_summary='quoted sentence')
81 self.VerifyParseQuickEditCommmand(
82 "summary='quoted sentence'", exp_summary='quoted sentence')
83
84 self.VerifyParseQuickEditCommmand(
85 'cc=me', exp_cc_ids=[222L, 333L, 999L])
86 self.VerifyParseQuickEditCommmand(
87 'cc=jrobbins@jrobbins.org', exp_cc_ids=[222L, 333L, 888L])
88 self.VerifyParseQuickEditCommmand(
89 'cc=me,jrobbins@jrobbins.org',
90 exp_cc_ids=[222L, 333L, 999L, 888L])
91 self.VerifyParseQuickEditCommmand(
92 'cc=-jrobbins,jrobbins@jrobbins.org',
93 exp_cc_ids=[222L, 888L])
94
95 def testParseQuickEditCommmand_Labels(self):
96 self.VerifyParseQuickEditCommmand(
97 'Priority=Low', exp_labels=['Type-Defect', 'Hot', 'Priority-Low'])
98 self.VerifyParseQuickEditCommmand(
99 'priority=low', exp_labels=['Type-Defect', 'Hot', 'Priority-Low'])
100 self.VerifyParseQuickEditCommmand(
101 'priority-low', exp_labels=['Type-Defect', 'Hot', 'Priority-Low'])
102 self.VerifyParseQuickEditCommmand(
103 '-priority-low', exp_labels=['Type-Defect', 'Priority-Medium', 'Hot'])
104 self.VerifyParseQuickEditCommmand(
105 '-priority-medium', exp_labels=['Type-Defect', 'Hot'])
106
107 self.VerifyParseQuickEditCommmand(
108 'Cold', exp_labels=['Type-Defect', 'Priority-Medium', 'Hot', 'Cold'])
109 self.VerifyParseQuickEditCommmand(
110 '+Cold', exp_labels=['Type-Defect', 'Priority-Medium', 'Hot', 'Cold'])
111 self.VerifyParseQuickEditCommmand(
112 '-Hot Cold', exp_labels=['Type-Defect', 'Priority-Medium', 'Cold'])
113 self.VerifyParseQuickEditCommmand(
114 '-Hot', exp_labels=['Type-Defect', 'Priority-Medium'])
115
116 def testParseQuickEditCommmand_Multiple(self):
117 self.VerifyParseQuickEditCommmand(
118 'Priority=Low -hot owner:me cc:-jrobbins summary="other summary"',
119 exp_summary='other summary', exp_owner_id=999L,
120 exp_cc_ids=[222L], exp_labels=['Type-Defect', 'Priority-Low'])
121
122 def testBreakCommandIntoParts_Empty(self):
123 self.assertListEqual(
124 [],
125 commands._BreakCommandIntoParts(''))
126
127 def testBreakCommandIntoParts_Single(self):
128 self.assertListEqual(
129 [('summary', 'new summary')],
130 commands._BreakCommandIntoParts('summary="new summary"'))
131 self.assertListEqual(
132 [('summary', 'OneWordSummary')],
133 commands._BreakCommandIntoParts('summary=OneWordSummary'))
134 self.assertListEqual(
135 [('key', 'value')],
136 commands._BreakCommandIntoParts('key=value'))
137 self.assertListEqual(
138 [('key', 'value-with-dashes')],
139 commands._BreakCommandIntoParts('key=value-with-dashes'))
140 self.assertListEqual(
141 [('key', 'value')],
142 commands._BreakCommandIntoParts('key:value'))
143 self.assertListEqual(
144 [('key', 'value')],
145 commands._BreakCommandIntoParts(' key:value '))
146 self.assertListEqual(
147 [('key', 'value')],
148 commands._BreakCommandIntoParts('key:"value"'))
149 self.assertListEqual(
150 [('key', 'user@dom.com')],
151 commands._BreakCommandIntoParts('key:user@dom.com'))
152 self.assertListEqual(
153 [('key', 'a@dom.com,-b@dom.com')],
154 commands._BreakCommandIntoParts('key:a@dom.com,-b@dom.com'))
155 self.assertListEqual(
156 [(None, 'label')],
157 commands._BreakCommandIntoParts('label'))
158 self.assertListEqual(
159 [(None, '-label')],
160 commands._BreakCommandIntoParts('-label'))
161 self.assertListEqual(
162 [(None, '+label')],
163 commands._BreakCommandIntoParts('+label'))
164
165 def testBreakCommandIntoParts_Multiple(self):
166 self.assertListEqual(
167 [('summary', 'new summary'), (None, 'Hot'), (None, '-Cold'),
168 ('owner', 'me'), ('cc', '+a,-b')],
169 commands._BreakCommandIntoParts(
170 'summary="new summary" Hot -Cold owner:me cc:+a,-b'))
171
172
173 class CommandSyntaxParsingTest(unittest.TestCase):
174
175 def setUp(self):
176 self.services = service_manager.Services(
177 project=fake.ProjectService(),
178 config=fake.ConfigService(),
179 user=fake.UserService())
180
181 self.services.project.TestAddProject('proj', owner_ids=[111L])
182 self.services.user.TestAddUser('a@example.com', 222L)
183
184 cnxn = 'fake connection'
185 config = self.services.config.GetProjectConfig(cnxn, 789)
186
187 for status in ['New', 'ReadyForReview']:
188 config.well_known_statuses.append(tracker_pb2.StatusDef(
189 status=status))
190
191 for label in ['Prioity-Low', 'Priority-High']:
192 config.well_known_labels.append(tracker_pb2.LabelDef(
193 label=label))
194
195 config.exclusive_label_prefixes.extend(
196 tracker_constants.DEFAULT_EXCL_LABEL_PREFIXES)
197
198 self.services.config.StoreConfig(cnxn, config)
199
200 def testStandardizeStatus(self):
201 config = self.services.config.GetProjectConfig('fake cnxn', 789)
202 self.assertEqual('New',
203 commands._StandardizeStatus('NEW', config))
204 self.assertEqual('New',
205 commands._StandardizeStatus('n$Ew ', config))
206 self.assertEqual(
207 'custom-label',
208 commands._StandardizeLabel('custom=label ', config))
209
210 def testStandardizeLabel(self):
211 config = self.services.config.GetProjectConfig('fake cnxn', 789)
212 self.assertEqual(
213 'Priority-High',
214 commands._StandardizeLabel('priority-high', config))
215 self.assertEqual(
216 'Priority-High',
217 commands._StandardizeLabel('PRIORITY=HIGH', config))
218
219 def testLookupMeOrUsername(self):
220 self.assertEqual(
221 123L,
222 commands._LookupMeOrUsername('fake cnxn', 'me', self.services, 123L))
223
224 self.assertEqual(
225 222L,
226 commands._LookupMeOrUsername(
227 'fake cnxn', 'a@example.com', self.services, 0))
228
229
230 if __name__ == '__main__':
231 unittest.main()
OLDNEW
« no previous file with comments | « appengine/monorail/features/test/autolink_test.py ('k') | appengine/monorail/features/test/commitlogcommands_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698