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

Side by Side Diff: tests/rietveld_test.py

Issue 174313002: Added a default timeout to rietveld requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Addressing comments Created 6 years, 10 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
« no previous file with comments | « rietveld.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for rietveld.py.""" 6 """Unit tests for rietveld.py."""
7 7
8 import logging 8 import logging
9 import os 9 import os
10 import sys 10 import sys
11 import traceback
11 import unittest 12 import unittest
12 13
13 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
14 15
15 from testing_support.patches_data import GIT, RAW 16 from testing_support.patches_data import GIT, RAW
17 from testing_support import auto_stub
16 18
17 import patch 19 import patch
18 import rietveld 20 import rietveld
19 21
20 22
21 def _api(files): 23 def _api(files):
22 """Mock a rietveld api request.""" 24 """Mock a rietveld api request."""
23 return rietveld.json.dumps({'files': files}) 25 return rietveld.json.dumps({'files': files})
24 26
25 27
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 416
415 def test_get_patchset_properties(self): 417 def test_get_patchset_properties(self):
416 self.requests = [ 418 self.requests = [
417 ('/api/1/2', '{}'), 419 ('/api/1/2', '{}'),
418 ] 420 ]
419 expected = {} 421 expected = {}
420 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2)) 422 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
421 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2)) 423 self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
422 424
423 425
426 class ProbeException(Exception):
427 """Deep-probe a value."""
428 value = None
429
430 def __init__(self, value):
431 super(ProbeException, self).__init__()
432 self.value = value
433
434
435 def MockSend(request_path, payload=None,
436 content_type="application/octet-stream",
437 timeout=None,
438 extra_headers=None,
439 **kwargs):
440 """Mock upload.py's Send() to probe the timeout value"""
441 raise ProbeException(timeout)
442
443
444 class DefaultTimeoutTest(auto_stub.TestCase):
445 TESTED_CLASS = rietveld.Rietveld
446
447 def setUp(self):
448 super(DefaultTimeoutTest, self).setUp()
449 self.rietveld = self.TESTED_CLASS('url', 'email', 'password')
450 self.mock(self.rietveld.rpc_server, 'Send', MockSend)
451
452 def test_timeout_get(self):
453 with self.assertRaises(ProbeException) as cm:
454 self.rietveld.get('/api/1234')
455
456 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
457 % traceback.format_exc())
458
459 def test_timeout_post(self):
460 with self.assertRaises(ProbeException) as cm:
461 self.rietveld.post('/api/1234', [('key', 'data')])
462
463 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
464 % traceback.format_exc())
465
424 466
425 if __name__ == '__main__': 467 if __name__ == '__main__':
426 logging.basicConfig(level=[ 468 logging.basicConfig(level=[
427 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) 469 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
428 unittest.main() 470 unittest.main()
OLDNEW
« no previous file with comments | « rietveld.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698