Index: tests/rietveld_test.py |
diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py |
index 17627a5fd1b2a69903e809612d5e0d8e80d6862b..b35aa848631f34d051fa0cbe0b182968b7bc0e29 100755 |
--- a/tests/rietveld_test.py |
+++ b/tests/rietveld_test.py |
@@ -8,12 +8,14 @@ |
import logging |
import os |
import sys |
+import traceback |
import unittest |
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
from testing_support.patches_data import GIT, RAW |
+from testing_support import auto_stub |
Paweł Hajdan Jr.
2014/02/21 00:49:30
nit: Please put it in one "block" with "from testi
Sergey Berezin
2014/02/21 01:30:56
Done.
|
import patch |
import rietveld |
@@ -421,6 +423,50 @@ class CachingRietveldTest(BaseFixture): |
self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2)) |
+class ProbeException(Exception): |
+ """Deep-probe a value.""" |
+ value = None |
+ |
+ def __init__(self, value): |
+ super(ProbeException, self).__init__() |
+ self.value = value |
+ |
+ |
+def MockSend(request_path, payload=None, |
+ content_type="application/octet-stream", |
+ timeout=None, |
+ extra_headers=None, |
+ **kwargs): |
+ """Mock upload.py's Send() to probe the timeout value""" |
+ raise ProbeException(timeout) |
+ |
+ |
+class DefaultTimeoutTest(auto_stub.TestCase): |
+ TESTED_CLASS = rietveld.Rietveld |
+ |
+ def setUp(self): |
+ super(DefaultTimeoutTest, self).setUp() |
+ self.rietveld = self.TESTED_CLASS('url', 'email', 'password') |
+ self.mock(self.rietveld.rpc_server, 'Send', MockSend) |
+ |
+ def test_timeout_get(self): |
+ try: |
+ self.rietveld.get('/api/1234') |
+ except ProbeException as e: |
Paweł Hajdan Jr.
2014/02/21 00:49:30
Use assertRaises instead. This also allows you to
Sergey Berezin
2014/02/21 01:30:56
Done.
|
+ self.assertIsNotNone(e.value, 'Rietveld timeout was not set: %s' |
+ % traceback.format_exc()) |
+ return |
+ self.assertTrue(False, 'This unittest has a bug, we should not get here.') |
+ |
+ def test_timeout_post(self): |
+ try: |
+ self.rietveld.post('/api/1234', [('key', 'data')]) |
+ except ProbeException as e: |
+ self.assertIsNotNone(e.value, 'Rietveld timeout was not set: %s' |
+ % traceback.format_exc()) |
+ return |
+ self.assertTrue(False, 'This unittest has a bug, we should not get here.') |
+ |
if __name__ == '__main__': |
logging.basicConfig(level=[ |