mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright Gregory P. Smith, Google Inc 2008 |
| 4 | # Released under the GPL v2 |
| 5 | |
| 6 | """Tests for server.frontend.""" |
| 7 | |
Richard Barnette | b9b3798 | 2016-05-20 19:23:39 -0700 | [diff] [blame] | 8 | #pylint: disable=missing-docstring |
| 9 | |
| 10 | import os, unittest |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 11 | import common |
| 12 | from autotest_lib.client.common_lib import global_config |
| 13 | from autotest_lib.client.common_lib import utils |
| 14 | from autotest_lib.client.common_lib.test_utils import mock |
| 15 | from autotest_lib.frontend.afe import rpc_client_lib |
| 16 | from autotest_lib.server import frontend |
| 17 | |
| 18 | GLOBAL_CONFIG = global_config.global_config |
| 19 | |
| 20 | |
| 21 | class BaseRpcClientTest(unittest.TestCase): |
| 22 | def setUp(self): |
| 23 | self.god = mock.mock_god() |
| 24 | self.god.mock_up(rpc_client_lib, 'rpc_client_lib') |
| 25 | self.god.stub_function(utils, 'send_email') |
mbligh | ed1b021 | 2009-11-21 01:46:39 +0000 | [diff] [blame] | 26 | self._saved_environ = dict(os.environ) |
| 27 | if 'AUTOTEST_WEB' in os.environ: |
| 28 | del os.environ['AUTOTEST_WEB'] |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def tearDown(self): |
| 32 | self.god.unstub_all() |
mbligh | ed1b021 | 2009-11-21 01:46:39 +0000 | [diff] [blame] | 33 | os.environ.clear() |
| 34 | os.environ.update(self._saved_environ) |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | class RpcClientTest(BaseRpcClientTest): |
| 38 | def test_init(self): |
| 39 | os.environ['LOGNAME'] = 'unittest-user' |
| 40 | GLOBAL_CONFIG.override_config_value('SERVER', 'hostname', 'test-host') |
Prathmesh Prabhu | 2892ff6 | 2017-12-19 10:21:31 -0800 | [diff] [blame] | 41 | rpc_client_lib.add_protocol.expect_call('test-host').and_return( |
| 42 | 'http://test-host') |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 43 | rpc_client_lib.get_proxy.expect_call( |
| 44 | 'http://test-host/path', |
| 45 | headers={'AUTHORIZATION': 'unittest-user'}) |
mbligh | ce3f538 | 2009-06-15 21:23:21 +0000 | [diff] [blame] | 46 | frontend.RpcClient('/path', None, None, None, None, None) |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 47 | self.god.check_playback() |
| 48 | |
| 49 | |
Richard Barnette | 08e487d | 2018-03-30 18:39:31 -0700 | [diff] [blame] | 50 | class CrosVersionFormatTestCase(unittest.TestCase): |
| 51 | def test_format_cros_image_name(self): |
| 52 | test_board = 'fubar-board' |
| 53 | test_version = 'R99-20000.15.0' |
| 54 | image_name = frontend.format_cros_image_name( |
| 55 | test_board, test_version) |
| 56 | self.assertIn(test_board, image_name) |
| 57 | self.assertIn(test_version, image_name) |
| 58 | |
| 59 | |
mbligh | 37eceaa | 2008-12-15 22:56:37 +0000 | [diff] [blame] | 60 | if __name__ == '__main__': |
| 61 | unittest.main() |