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

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

Issue 3013013002: [pinpoint] Change refactor. (Closed)
Patch Set: UI Created 3 years, 3 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 governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import mock
6
7 from dashboard.common import namespaced_stored_object
8 from dashboard.common import testing_common
9 from dashboard.pinpoint.models.change import commit
10
11
12 _CHROMIUM_URL = 'https://chromium.googlesource.com/chromium/src'
13
14
15 class _CommitTest(testing_common.TestCase):
16
17 def setUp(self):
18 super(_CommitTest, self).setUp()
19
20 self.SetCurrentUser('internal@chromium.org', is_admin=True)
21
22 namespaced_stored_object.Set('repositories', {
23 'chromium': {'repository_url': _CHROMIUM_URL},
24 })
25
26
27 class CommitTest(_CommitTest):
28
29 def testCommit(self):
30 c = commit.Commit('chromium', 'aaa7336c821888839f759c6c0a36')
31
32 other_commit = commit.Commit(u'chromium', u'aaa7336c821888839f759c6c0a36')
33 self.assertEqual(c, other_commit)
34 self.assertEqual(str(c), 'chromium@aaa7336')
35 self.assertEqual(c.id_string, 'chromium@aaa7336c821888839f759c6c0a36')
36 self.assertEqual(c.repository, 'chromium')
37 self.assertEqual(c.git_hash, 'aaa7336c821888839f759c6c0a36')
38 self.assertEqual(c.repository_url,
39 'https://chromium.googlesource.com/chromium/src')
40
41 @mock.patch('dashboard.services.gitiles_service.FileContents')
42 def testDeps(self, file_contents):
43 file_contents.return_value = """
44 vars = {
45 'chromium_git': 'https://chromium.googlesource.com',
46 }
47 deps = {
48 'src/v8': Var('chromium_git') + '/v8/v8.git' + '@' + 'c092edb',
49 }
50 deps_os = {
51 'win': {
52 'src/third_party/cygwin':
53 Var('chromium_git') + '/chromium/deps/cygwin.git' + '@' + 'c89e446',
54 }
55 }
56 """
57
58 c = commit.Commit('chromium', 'aaa7336')
59 expected = frozenset((
60 commit.Commit('cygwin', 'c89e446'),
61 commit.Commit('v8', 'c092edb'),
62 ))
63 self.assertEqual(c.Deps(), expected)
64
65 def testAsDict(self):
66 c = commit.Commit('chromium', 'aaa7336')
67 expected = {
68 'repository': 'chromium',
69 'git_hash': 'aaa7336',
70 'url': _CHROMIUM_URL + '/+/aaa7336',
71 }
72 self.assertEqual(c.AsDict(), expected)
73
74 @mock.patch('dashboard.services.gitiles_service.CommitInfo')
75 def testFromDict(self, _):
76 c = commit.Commit.FromDict({
77 'repository': 'chromium',
78 'git_hash': 'aaa7336',
79 })
80
81 expected = commit.Commit('chromium', 'aaa7336')
82 self.assertEqual(c, expected)
83
84 @mock.patch('dashboard.services.gitiles_service.CommitInfo')
85 def testFromDictWithRepositoryUrl(self, _):
86 c = commit.Commit.FromDict({
87 'repository': 'https://chromium.googlesource.com/chromium/src',
88 'git_hash': 'aaa7336',
89 })
90
91 expected = commit.Commit('chromium', 'aaa7336')
92 self.assertEqual(c, expected)
93
94 def testFromDictFailureFromUnknownRepo(self):
95 with self.assertRaises(KeyError):
96 commit.Commit.FromDict({
97 'repository': 'unknown repo',
98 'git_hash': 'git hash',
99 })
100
101 @mock.patch('dashboard.services.gitiles_service.CommitInfo')
102 def testFromDictFailureFromUnknownCommit(self, commit_info):
103 commit_info.side_effect = KeyError()
104
105 with self.assertRaises(KeyError):
106 commit.Commit.FromDict({
107 'repository': 'chromium',
108 'git_hash': 'unknown git hash',
109 })
110
111
112 class MidpointTest(_CommitTest):
113
114 @mock.patch('dashboard.services.gitiles_service.CommitRange')
115 def testSuccess(self, commit_range):
116 commit_range.return_value = [
117 {'commit': 'babe852'},
118 {'commit': 'b57345e'},
119 {'commit': '949b36d'},
120 {'commit': '1ef4789'},
121 ]
122
123 commit_a = commit.Commit('chromium', '0e57e2b')
124 commit_b = commit.Commit('chromium', 'babe852')
125 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b),
126 commit.Commit('chromium', '949b36d'))
127
128 def testSameCommit(self):
129 commit_a = commit.Commit('chromium', '0e57e2b')
130 commit_b = commit.Commit('chromium', '0e57e2b')
131 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a)
132
133 @mock.patch('dashboard.services.gitiles_service.CommitRange')
134 def testAdjacentCommits(self, commit_range):
135 commit_range.return_value = [{'commit': 'b57345e'}]
136
137 commit_a = commit.Commit('chromium', '949b36d')
138 commit_b = commit.Commit('chromium', 'b57345e')
139 self.assertEqual(commit.Commit.Midpoint(commit_a, commit_b), commit_a)
140
141 def testRaisesWithDifferingRepositories(self):
142 commit_a = commit.Commit('chromium', '0e57e2b')
143 commit_b = commit.Commit('not_chromium', 'babe852')
144 with self.assertRaises(commit.NonLinearError):
145 commit.Commit.Midpoint(commit_a, commit_b)
146
147 @mock.patch('dashboard.services.gitiles_service.CommitRange')
148 def testRaisesWithEmptyRange(self, commit_range):
149 commit_range.return_value = []
150
151 commit_b = commit.Commit('chromium', 'b57345e')
152 commit_a = commit.Commit('chromium', '949b36d')
153 with self.assertRaises(commit.NonLinearError):
154 commit.Commit.Midpoint(commit_a, commit_b)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698