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

Side by Side Diff: tests/rietveld_test.py

Issue 180723002: Incorrect SSLError attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 6 years, 9 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 ssl
10 import sys 11 import sys
12 import time
11 import traceback 13 import traceback
12 import unittest 14 import unittest
13 15
14 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 16 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15 17
16 from testing_support.patches_data import GIT, RAW 18 from testing_support.patches_data import GIT, RAW
17 from testing_support import auto_stub 19 from testing_support import auto_stub
18 20
19 import patch 21 import patch
20 import rietveld 22 import rietveld
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 435
434 436
435 def MockSend(request_path, payload=None, 437 def MockSend(request_path, payload=None,
436 content_type="application/octet-stream", 438 content_type="application/octet-stream",
437 timeout=None, 439 timeout=None,
438 extra_headers=None, 440 extra_headers=None,
439 **kwargs): 441 **kwargs):
440 """Mock upload.py's Send() to probe the timeout value""" 442 """Mock upload.py's Send() to probe the timeout value"""
441 raise ProbeException(timeout) 443 raise ProbeException(timeout)
442 444
445 def MockSendTimeout(request_path, payload=None,
446 content_type="application/octet-stream",
447 timeout=None,
448 extra_headers=None,
449 **kwargs):
450 """Mock upload.py's Send() to raise SSLError"""
451 raise ssl.SSLError('The read operation timed out')
452
443 453
444 class DefaultTimeoutTest(auto_stub.TestCase): 454 class DefaultTimeoutTest(auto_stub.TestCase):
445 TESTED_CLASS = rietveld.Rietveld 455 TESTED_CLASS = rietveld.Rietveld
446 456
447 def setUp(self): 457 def setUp(self):
448 super(DefaultTimeoutTest, self).setUp() 458 super(DefaultTimeoutTest, self).setUp()
449 self.rietveld = self.TESTED_CLASS('url', 'email', 'password') 459 self.rietveld = self.TESTED_CLASS('url', 'email', 'password')
450 self.mock(self.rietveld.rpc_server, 'Send', MockSend) 460 self.mock(self.rietveld.rpc_server, 'Send', MockSend)
461 self.sleep_time = 0
451 462
452 def test_timeout_get(self): 463 def test_timeout_get(self):
453 with self.assertRaises(ProbeException) as cm: 464 with self.assertRaises(ProbeException) as cm:
454 self.rietveld.get('/api/1234') 465 self.rietveld.get('/api/1234')
455 466
456 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s' 467 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
457 % traceback.format_exc()) 468 % traceback.format_exc())
458 469
459 def test_timeout_post(self): 470 def test_timeout_post(self):
460 with self.assertRaises(ProbeException) as cm: 471 with self.assertRaises(ProbeException) as cm:
461 self.rietveld.post('/api/1234', [('key', 'data')]) 472 self.rietveld.post('/api/1234', [('key', 'data')])
462 473
463 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s' 474 self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
464 % traceback.format_exc()) 475 % traceback.format_exc())
465 476
477 def MockSleep(self, t):
478 self.sleep_time = t
479
480 def test_ssl_timeout_post(self):
481 self.mock(self.rietveld.rpc_server, 'Send', MockSendTimeout)
482 self.mock(time, 'sleep', self.MockSleep)
483 self.sleep_time = 0
484 with self.assertRaises(ssl.SSLError):
485 self.rietveld.post('/api/1234', [('key', 'data')])
486 self.assertNotEqual(self.sleep_time, 0)
466 487
467 if __name__ == '__main__': 488 if __name__ == '__main__':
468 logging.basicConfig(level=[ 489 logging.basicConfig(level=[
469 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) 490 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
470 unittest.main() 491 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