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

Side by Side Diff: tests/rietveld_test.py

Issue 1686753003: Revert "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
9 import logging 8 import logging
10 import os 9 import os
11 import socket 10 import socket
12 import ssl 11 import ssl
13 import StringIO
14 import sys 12 import sys
15 import time 13 import time
16 import traceback 14 import traceback
17 import unittest 15 import unittest
18 import urllib2
19 16
20 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 17 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
21 18
22 from testing_support.patches_data import GIT, RAW 19 from testing_support.patches_data import GIT, RAW
23 from testing_support import auto_stub 20 from testing_support import auto_stub
24 from third_party import httplib2
25 21
26 import patch 22 import patch
27 import rietveld 23 import rietveld
28 24
29 25
30 def _api(files): 26 def _api(files):
31 """Mock a rietveld api request.""" 27 """Mock a rietveld api request."""
32 return rietveld.json.dumps({'files': files}) 28 return rietveld.json.dumps({'files': files})
33 29
34 30
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 self.rietveld.post('/api/1234', [('key', 'data')]) 483 self.rietveld.post('/api/1234', [('key', 'data')])
488 self.assertNotEqual(self.sleep_time, 0) 484 self.assertNotEqual(self.sleep_time, 0)
489 485
490 def test_socket_connect_timeout_post(self): 486 def test_socket_connect_timeout_post(self):
491 self.mock(self.rietveld.rpc_server, 'Send', MockSocketConnectTimeout) 487 self.mock(self.rietveld.rpc_server, 'Send', MockSocketConnectTimeout)
492 self.mock(time, 'sleep', self.MockSleep) 488 self.mock(time, 'sleep', self.MockSleep)
493 with self.assertRaises(socket.timeout): 489 with self.assertRaises(socket.timeout):
494 self.rietveld.post('/api/1234', [('key', 'data')]) 490 self.rietveld.post('/api/1234', [('key', 'data')])
495 self.assertNotEqual(self.sleep_time, 0) 491 self.assertNotEqual(self.sleep_time, 0)
496 492
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
521 if __name__ == '__main__': 493 if __name__ == '__main__':
522 logging.basicConfig(level=[ 494 logging.basicConfig(level=[
523 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) 495 logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
524 unittest.main() 496 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