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

Side by Side Diff: tests/rietveld_test.py

Issue 1683603002: Raise exceptions properly on HTTP errors from OAuthRpcServer (which is only used on bots) (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 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 httplib
8 import logging 9 import logging
9 import os 10 import os
10 import socket 11 import socket
11 import ssl 12 import ssl
13 import StringIO
12 import sys 14 import sys
13 import time 15 import time
14 import traceback 16 import traceback
15 import unittest 17 import unittest
18 import urllib2
16 19
17 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18 21
19 from testing_support.patches_data import GIT, RAW 22 from testing_support.patches_data import GIT, RAW
20 from testing_support import auto_stub 23 from testing_support import auto_stub
24 from third_party import httplib2
21 25
22 import patch 26 import patch
23 import rietveld 27 import rietveld
24 28
25 29
26 def _api(files): 30 def _api(files):
27 """Mock a rietveld api request.""" 31 """Mock a rietveld api request."""
28 return rietveld.json.dumps({'files': files}) 32 return rietveld.json.dumps({'files': files})
29 33
30 34
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 self.rietveld.post('/api/1234', [('key', 'data')]) 487 self.rietveld.post('/api/1234', [('key', 'data')])
484 self.assertNotEqual(self.sleep_time, 0) 488 self.assertNotEqual(self.sleep_time, 0)
485 489
486 def test_socket_connect_timeout_post(self): 490 def test_socket_connect_timeout_post(self):
487 self.mock(self.rietveld.rpc_server, 'Send', MockSocketConnectTimeout) 491 self.mock(self.rietveld.rpc_server, 'Send', MockSocketConnectTimeout)
488 self.mock(time, 'sleep', self.MockSleep) 492 self.mock(time, 'sleep', self.MockSleep)
489 with self.assertRaises(socket.timeout): 493 with self.assertRaises(socket.timeout):
490 self.rietveld.post('/api/1234', [('key', 'data')]) 494 self.rietveld.post('/api/1234', [('key', 'data')])
491 self.assertNotEqual(self.sleep_time, 0) 495 self.assertNotEqual(self.sleep_time, 0)
492 496
497
498 class OAuthRpcServerTest(auto_stub.TestCase):
499 def setUp(self):
500 super(OAuthRpcServerTest, self).setUp()
501 self.rpc_server = rietveld.OAuthRpcServer(
502 'http://www.example.com', 'foo', 'bar')
503
504 def set_mock_response(self, status):
505 def MockHttpRequest(*args, **kwargs):
506 return (httplib2.Response({'status': status}), 'body')
507 self.mock(self.rpc_server._http, 'request', MockHttpRequest)
508
509 def test_404(self):
510 self.set_mock_response(404)
511 with self.assertRaises(urllib2.HTTPError) as ctx:
512 self.rpc_server.Send('/foo')
513 self.assertEquals(404, ctx.exception.code)
514
515 def test_200(self):
516 self.set_mock_response(200)
517 ret = self.rpc_server.Send('/foo')
518 self.assertEquals('body', ret)
519
520
493 if __name__ == '__main__': 521 if __name__ == '__main__':
494 logging.basicConfig(level=[ 522 logging.basicConfig(level=[
495 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) 523 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
496 unittest.main() 524 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