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

Side by Side Diff: dashboard/dashboard/services/gitiles_service_test.py

Issue 3013753002: [pinpoint] Increase Gitiles service timeout. (Closed)
Patch Set: Dashboard unit tests. 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 json 5 import json
6 import unittest 6 import unittest
7 7
8 import mock 8 import mock
9 9
10 from google.appengine.api import urlfetch 10 from google.appengine.api import urlfetch
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 'new_path': 'a/b/c.py', 42 'new_path': 'a/b/c.py',
43 }, 43 },
44 ], 44 ],
45 } 45 }
46 _SetFetchReturnValues(mock_fetch, return_value) 46 _SetFetchReturnValues(mock_fetch, return_value)
47 self.assertEqual( 47 self.assertEqual(
48 gitiles_service.CommitInfo('https://chromium.googlesource.com/repo', 48 gitiles_service.CommitInfo('https://chromium.googlesource.com/repo',
49 'commit_hash'), 49 'commit_hash'),
50 return_value) 50 return_value)
51 mock_fetch.assert_called_once_with( 51 mock_fetch.assert_called_once_with(
52 'https://chromium.googlesource.com/repo/+/commit_hash?format=JSON') 52 'https://chromium.googlesource.com/repo/+/commit_hash?format=JSON',
53 deadline=10)
53 54
54 def testCommitRange(self, mock_fetch): 55 def testCommitRange(self, mock_fetch):
55 return_value = { 56 return_value = {
56 'log': [ 57 'log': [
57 { 58 {
58 'commit': 'commit_2_hash', 59 'commit': 'commit_2_hash',
59 'tree': 'tree_2_hash', 60 'tree': 'tree_2_hash',
60 'parents': ['parent_2_hash'], 61 'parents': ['parent_2_hash'],
61 'author': { 62 'author': {
62 'name': 'username', 63 'name': 'username',
(...skipping 25 matching lines...) Expand all
88 }, 89 },
89 ], 90 ],
90 } 91 }
91 _SetFetchReturnValues(mock_fetch, return_value) 92 _SetFetchReturnValues(mock_fetch, return_value)
92 self.assertEqual( 93 self.assertEqual(
93 gitiles_service.CommitRange('https://chromium.googlesource.com/repo', 94 gitiles_service.CommitRange('https://chromium.googlesource.com/repo',
94 'commit_0_hash', 'commit_2_hash'), 95 'commit_0_hash', 'commit_2_hash'),
95 return_value['log']) 96 return_value['log'])
96 mock_fetch.assert_called_once_with( 97 mock_fetch.assert_called_once_with(
97 'https://chromium.googlesource.com/repo/+log/' 98 'https://chromium.googlesource.com/repo/+log/'
98 'commit_0_hash..commit_2_hash?format=JSON') 99 'commit_0_hash..commit_2_hash?format=JSON',
100 deadline=10)
99 101
100 def testCommitRangePaginated(self, mock_fetch): 102 def testCommitRangePaginated(self, mock_fetch):
101 return_value_1 = { 103 return_value_1 = {
102 'log': [ 104 'log': [
103 {'commit': 'commit_4_hash'}, 105 {'commit': 'commit_4_hash'},
104 {'commit': 'commit_3_hash'}, 106 {'commit': 'commit_3_hash'},
105 ], 107 ],
106 'next': 'commit_2_hash', 108 'next': 'commit_2_hash',
107 } 109 }
108 return_value_2 = { 110 return_value_2 = {
(...skipping 11 matching lines...) Expand all
120 return_value_1['log'] + return_value_2['log']) 122 return_value_1['log'] + return_value_2['log'])
121 123
122 def testFileContents(self, mock_fetch): 124 def testFileContents(self, mock_fetch):
123 mock_fetch.return_value = mock.MagicMock( 125 mock_fetch.return_value = mock.MagicMock(
124 content='aGVsbG8=', status_code=200) 126 content='aGVsbG8=', status_code=200)
125 self.assertEqual( 127 self.assertEqual(
126 gitiles_service.FileContents('https://chromium.googlesource.com/repo', 128 gitiles_service.FileContents('https://chromium.googlesource.com/repo',
127 'commit_hash', 'path'), 129 'commit_hash', 'path'),
128 'hello') 130 'hello')
129 mock_fetch.assert_called_once_with( 131 mock_fetch.assert_called_once_with(
130 'https://chromium.googlesource.com/repo/+/commit_hash/path?format=TEXT') 132 'https://chromium.googlesource.com/repo/+/commit_hash/path?format=TEXT',
133 deadline=10)
131 134
132 def testRetries(self, mock_fetch): 135 def testRetries(self, mock_fetch):
133 mock_fetch.side_effect = urlfetch.Error() 136 mock_fetch.side_effect = urlfetch.Error()
134 with self.assertRaises(urlfetch.Error): 137 with self.assertRaises(urlfetch.Error):
135 gitiles_service.FileContents('https://chromium.googlesource.com/repo', 138 gitiles_service.FileContents('https://chromium.googlesource.com/repo',
136 'commit_hash', 'path') 139 'commit_hash', 'path')
137 140
138 mock_fetch.side_effect = urlfetch.Error(), mock.MagicMock( 141 mock_fetch.side_effect = urlfetch.Error(), mock.MagicMock(
139 content='aGVsbG8=', status_code=200) 142 content='aGVsbG8=', status_code=200)
140 self.assertEqual( 143 self.assertEqual(
(...skipping 15 matching lines...) Expand all
156 159
157 160
158 def _SetFetchReturnValues(mock_fetch, *return_values): 161 def _SetFetchReturnValues(mock_fetch, *return_values):
159 mock_fetch.side_effect = tuple( 162 mock_fetch.side_effect = tuple(
160 _MockifyReturnValue(return_value) for return_value in return_values) 163 _MockifyReturnValue(return_value) for return_value in return_values)
161 164
162 165
163 def _MockifyReturnValue(return_value): 166 def _MockifyReturnValue(return_value):
164 return mock.MagicMock(content=")]}'\n" + json.dumps(return_value), 167 return mock.MagicMock(content=")]}'\n" + json.dumps(return_value),
165 status_code=200) 168 status_code=200)
OLDNEW
« no previous file with comments | « dashboard/dashboard/services/gitiles_service.py ('k') | dashboard/dashboard/start_try_job_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698