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

Side by Side Diff: dashboard/dashboard/pinpoint/models/change/change_test.py

Issue 3019553002: [pinpoint] Gerrit patch support. (Closed)
Patch Set: Example URL Created 3 years, 2 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
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import mock 5 import mock
6 6
7 from dashboard.common import namespaced_stored_object 7 from dashboard.common import namespaced_stored_object
8 from dashboard.common import testing_common 8 from dashboard.common import testing_common
9 from dashboard.pinpoint.models.change import change 9 from dashboard.pinpoint.models.change import change
10 from dashboard.pinpoint.models.change import commit 10 from dashboard.pinpoint.models.change import commit
(...skipping 20 matching lines...) Expand all
31 _CATAPULT_URL: 'catapult', 31 _CATAPULT_URL: 'catapult',
32 _CHROMIUM_URL: 'chromium', 32 _CHROMIUM_URL: 'chromium',
33 }) 33 })
34 34
35 35
36 class ChangeTest(_ChangeTest): 36 class ChangeTest(_ChangeTest):
37 37
38 def testChange(self): 38 def testChange(self):
39 base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c') 39 base_commit = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36b56c')
40 dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba') 40 dep = commit.Commit('catapult', 'e0a2efbb3d1a81aac3c90041eefec24f066d26ba')
41 p = patch.Patch('https://codereview.chromium.org', 2565263002, 20001) 41 p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7')
42 42
43 # Also test the deps conversion to frozenset. 43 # Also test the deps conversion to frozenset.
44 c = change.Change([base_commit, dep], p) 44 c = change.Change([base_commit, dep], p)
45 45
46 self.assertEqual(c, change.Change((base_commit, dep), p)) 46 self.assertEqual(c, change.Change((base_commit, dep), p))
47 string = ('chromium@aaa7336 catapult@e0a2efb + ' 47 string = ('chromium@aaa7336 catapult@e0a2efb + '
48 'https://codereview.chromium.org/2565263002/20001') 48 'https://codereview.com/672011/2f0d5c7')
49 id_string = ('catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba ' 49 id_string = ('catapult@e0a2efbb3d1a81aac3c90041eefec24f066d26ba '
50 'chromium@aaa7336c821888839f759c6c0a36b56c + ' 50 'chromium@aaa7336c821888839f759c6c0a36b56c + '
51 'https://codereview.chromium.org/2565263002/20001') 51 'https://codereview.com/672011/2f0d5c7')
52 self.assertEqual(str(c), string) 52 self.assertEqual(str(c), string)
53 self.assertEqual(c.id_string, id_string) 53 self.assertEqual(c.id_string, id_string)
54 self.assertEqual(c.base_commit, base_commit) 54 self.assertEqual(c.base_commit, base_commit)
55 self.assertEqual(c.last_commit, dep) 55 self.assertEqual(c.last_commit, dep)
56 self.assertEqual(c.deps, (dep,)) 56 self.assertEqual(c.deps, (dep,))
57 self.assertEqual(c.commits, (base_commit, dep)) 57 self.assertEqual(c.commits, (base_commit, dep))
58 self.assertEqual(c.patch, p) 58 self.assertEqual(c.patch, p)
59 59
60 def testAsDict(self): 60 def testAsDict(self):
61 commits = (commit.Commit('chromium', 'aaa7336c82'), 61 commits = (commit.Commit('chromium', 'aaa7336c82'),
62 commit.Commit('catapult', 'e0a2efbb3d')) 62 commit.Commit('catapult', 'e0a2efbb3d'))
63 p = patch.Patch('https://codereview.chromium.org', 2565263002, 20001) 63 p = patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7')
64 c = change.Change(commits, p) 64 c = change.Change(commits, p)
65 65
66 expected = { 66 expected = {
67 'commits': [ 67 'commits': [
68 { 68 {
69 'repository': 'chromium', 69 'repository': 'chromium',
70 'git_hash': 'aaa7336c82', 70 'git_hash': 'aaa7336c82',
71 'url': _CHROMIUM_URL + '/+/aaa7336c82', 71 'url': _CHROMIUM_URL + '/+/aaa7336c82',
72 }, 72 },
73 { 73 {
74 'repository': 'catapult', 74 'repository': 'catapult',
75 'git_hash': 'e0a2efbb3d', 75 'git_hash': 'e0a2efbb3d',
76 'url': _CATAPULT_URL + '/+/e0a2efbb3d', 76 'url': _CATAPULT_URL + '/+/e0a2efbb3d',
77 }, 77 },
78 ], 78 ],
79 'patch': { 79 'patch': {
80 'server': 'https://codereview.chromium.org', 80 'server': 'https://codereview.com',
81 'issue': 2565263002, 81 'change': 672011,
82 'patchset': 20001, 82 'revision': '2f0d5c7',
83 }, 83 },
84 } 84 }
85 self.assertEqual(c.AsDict(), expected) 85 self.assertEqual(c.AsDict(), expected)
86 86
87 @mock.patch('dashboard.services.gitiles_service.CommitInfo') 87 @mock.patch('dashboard.services.gitiles_service.CommitInfo')
88 def testFromDictWithJustOneCommit(self, _): 88 def testFromDictWithJustOneCommit(self, _):
89 c = change.Change.FromDict({ 89 c = change.Change.FromDict({
90 'commits': [{'repository': 'chromium', 'git_hash': 'aaa7336'}], 90 'commits': [{'repository': 'chromium', 'git_hash': 'aaa7336'}],
91 }) 91 })
92 92
93 expected = change.Change((commit.Commit('chromium', 'aaa7336'),)) 93 expected = change.Change((commit.Commit('chromium', 'aaa7336'),))
94 self.assertEqual(c, expected) 94 self.assertEqual(c, expected)
95 95
96 @mock.patch('dashboard.services.gerrit_service.GetChange')
96 @mock.patch('dashboard.services.gitiles_service.CommitInfo') 97 @mock.patch('dashboard.services.gitiles_service.CommitInfo')
97 def testFromDictWithAllFields(self, _): 98 def testFromDictWithAllFields(self, _, get_change):
99 get_change.return_value = {
100 'id': 'repo~branch~id',
101 'revisions': {'2f0d5c7': {}}
102 }
103
98 c = change.Change.FromDict({ 104 c = change.Change.FromDict({
99 'commits': ( 105 'commits': (
100 {'repository': 'chromium', 'git_hash': 'aaa7336'}, 106 {'repository': 'chromium', 'git_hash': 'aaa7336'},
101 {'repository': 'catapult', 'git_hash': 'e0a2efb'}, 107 {'repository': 'catapult', 'git_hash': 'e0a2efb'},
102 ), 108 ),
103 'patch': { 109 'patch': {
104 'server': 'https://codereview.chromium.org', 110 'server': 'https://codereview.com',
105 'issue': 2565263002, 111 'change': 672011,
106 'patchset': 20001, 112 'revision': '2f0d5c7',
107 }, 113 },
108 }) 114 })
109 115
110 commits = (commit.Commit('chromium', 'aaa7336'), 116 commits = (commit.Commit('chromium', 'aaa7336'),
111 commit.Commit('catapult', 'e0a2efb')) 117 commit.Commit('catapult', 'e0a2efb'))
112 p = patch.Patch('https://codereview.chromium.org', 2565263002, 20001) 118 p = patch.GerritPatch('https://codereview.com', 'repo~branch~id', '2f0d5c7')
113 expected = change.Change(commits, p) 119 expected = change.Change(commits, p)
114 self.assertEqual(c, expected) 120 self.assertEqual(c, expected)
115 121
116 122
117 class MidpointTest(_ChangeTest): 123 class MidpointTest(_ChangeTest):
118 124
119 def setUp(self): 125 def setUp(self):
120 super(MidpointTest, self).setUp() 126 super(MidpointTest, self).setUp()
121 127
122 patcher = mock.patch('dashboard.services.gitiles_service.CommitRange') 128 patcher = mock.patch('dashboard.services.gitiles_service.CommitRange')
(...skipping 16 matching lines...) Expand all
139 if git_hash <= 4: # DEPS roll at chromium@5 145 if git_hash <= 4: # DEPS roll at chromium@5
140 return 'deps = {"chromium/catapult": "%s@0"}' % (_CATAPULT_URL + '.git') 146 return 'deps = {"chromium/catapult": "%s@0"}' % (_CATAPULT_URL + '.git')
141 else: 147 else:
142 return 'deps = {"chromium/catapult": "%s@9"}' % _CATAPULT_URL 148 return 'deps = {"chromium/catapult": "%s@9"}' % _CATAPULT_URL
143 file_contents.side_effect = _FileContents 149 file_contents.side_effect = _FileContents
144 150
145 def testDifferingPatch(self): 151 def testDifferingPatch(self):
146 change_a = change.Change((commit.Commit('chromium', '0e57e2b'),)) 152 change_a = change.Change((commit.Commit('chromium', '0e57e2b'),))
147 change_b = change.Change( 153 change_b = change.Change(
148 (commit.Commit('chromium', 'babe852'),), 154 (commit.Commit('chromium', 'babe852'),),
149 patch=patch.Patch('https://codereview.chromium.org', 2565263002, 20001)) 155 patch=patch.GerritPatch('https://codereview.com', 672011, '2f0d5c7'))
150 with self.assertRaises(commit.NonLinearError): 156 with self.assertRaises(commit.NonLinearError):
151 change.Change.Midpoint(change_a, change_b) 157 change.Change.Midpoint(change_a, change_b)
152 158
153 def testDifferingRepository(self): 159 def testDifferingRepository(self):
154 change_a = change.Change((commit.Commit('chromium', '0e57e2b'),)) 160 change_a = change.Change((commit.Commit('chromium', '0e57e2b'),))
155 change_b = change.Change((commit.Commit('not_chromium', 'babe852'),)) 161 change_b = change.Change((commit.Commit('not_chromium', 'babe852'),))
156 with self.assertRaises(commit.NonLinearError): 162 with self.assertRaises(commit.NonLinearError):
157 change.Change.Midpoint(change_a, change_b) 163 change.Change.Midpoint(change_a, change_b)
158 164
159 def testDifferingCommitCount(self): 165 def testDifferingCommitCount(self):
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 commit.Commit('catapult', 6))) 210 commit.Commit('catapult', 6)))
205 self.assertEqual(change.Change.Midpoint(change_a, change_b), expected) 211 self.assertEqual(change.Change.Midpoint(change_a, change_b), expected)
206 212
207 def testAdjacentWithDepsRollAndDepAlreadyOverridden(self): 213 def testAdjacentWithDepsRollAndDepAlreadyOverridden(self):
208 change_a = change.Change((commit.Commit('chromium', 4),)) 214 change_a = change.Change((commit.Commit('chromium', 4),))
209 change_b = change.Change((commit.Commit('chromium', 5), 215 change_b = change.Change((commit.Commit('chromium', 5),
210 commit.Commit('catapult', 4))) 216 commit.Commit('catapult', 4)))
211 expected = change.Change((commit.Commit('chromium', 4), 217 expected = change.Change((commit.Commit('chromium', 4),
212 commit.Commit('catapult', 2))) 218 commit.Commit('catapult', 2)))
213 self.assertEqual(change.Change.Midpoint(change_a, change_b), expected) 219 self.assertEqual(change.Change.Midpoint(change_a, change_b), expected)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698