mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2008 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | """Test for the rpc proxy class.""" |
| 6 | |
| 7 | import unittest, os |
| 8 | import common |
| 9 | from autotest_lib.cli import rpc |
mbligh | f8d456f | 2008-12-22 14:46:52 +0000 | [diff] [blame] | 10 | from autotest_lib.client.common_lib import global_config |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 11 | from autotest_lib.frontend.afe import rpc_client_lib |
| 12 | from autotest_lib.frontend.afe.json_rpc import proxy |
| 13 | |
mbligh | f8d456f | 2008-12-22 14:46:52 +0000 | [diff] [blame] | 14 | GLOBAL_CONFIG = global_config.global_config |
| 15 | |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 16 | |
| 17 | class rpc_unittest(unittest.TestCase): |
| 18 | def setUp(self): |
mbligh | f8d456f | 2008-12-22 14:46:52 +0000 | [diff] [blame] | 19 | self.old_environ = os.environ.copy() |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 20 | if 'AUTOTEST_WEB' in os.environ: |
| 21 | del os.environ['AUTOTEST_WEB'] |
| 22 | |
| 23 | |
| 24 | def tearDown(self): |
mbligh | f8d456f | 2008-12-22 14:46:52 +0000 | [diff] [blame] | 25 | os.environ.clear() |
| 26 | os.environ.update(self.old_environ) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def test_get_autotest_server_specific(self): |
| 30 | self.assertEqual('http://foo', rpc.get_autotest_server('foo')) |
| 31 | |
| 32 | |
| 33 | def test_get_autotest_server_none(self): |
mbligh | f8d456f | 2008-12-22 14:46:52 +0000 | [diff] [blame] | 34 | GLOBAL_CONFIG.override_config_value('SERVER', 'hostname', 'Prince') |
| 35 | self.assertEqual('http://Prince', rpc.get_autotest_server(None)) |
mbligh | be630eb | 2008-08-01 16:41:48 +0000 | [diff] [blame] | 36 | |
| 37 | |
| 38 | def test_get_autotest_server_environ(self): |
| 39 | os.environ['AUTOTEST_WEB'] = 'foo-dev' |
| 40 | self.assertEqual('http://foo-dev', rpc.get_autotest_server(None)) |
| 41 | del os.environ['AUTOTEST_WEB'] |
| 42 | |
| 43 | |
| 44 | def test_get_autotest_server_environ_precedence(self): |
| 45 | os.environ['AUTOTEST_WEB'] = 'foo-dev' |
| 46 | self.assertEqual('http://foo', rpc.get_autotest_server('foo')) |
| 47 | del os.environ['AUTOTEST_WEB'] |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | unittest.main() |