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 8#pylint: disable=missing-docstring 9 10import os, unittest 11import common 12from autotest_lib.client.common_lib import global_config 13from autotest_lib.client.common_lib import utils 14from autotest_lib.client.common_lib.test_utils import mock 15from autotest_lib.frontend.afe import rpc_client_lib 16from autotest_lib.server import frontend 17 18GLOBAL_CONFIG = global_config.global_config 19 20 21class 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') 26 self._saved_environ = dict(os.environ) 27 if 'AUTOTEST_WEB' in os.environ: 28 del os.environ['AUTOTEST_WEB'] 29 30 31 def tearDown(self): 32 self.god.unstub_all() 33 os.environ.clear() 34 os.environ.update(self._saved_environ) 35 36 37class RpcClientTest(BaseRpcClientTest): 38 def test_init(self): 39 os.environ['LOGNAME'] = 'unittest-user' 40 GLOBAL_CONFIG.override_config_value('SERVER', 'hostname', 'test-host') 41 rpc_client_lib.add_protocol.expect_call('test-host').and_return( 42 'http://test-host') 43 rpc_client_lib.get_proxy.expect_call( 44 'http://test-host/path', 45 headers={'AUTHORIZATION': 'unittest-user'}) 46 frontend.RpcClient('/path', None, None, None, None, None) 47 self.god.check_playback() 48 49 50class 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 60if __name__ == '__main__': 61 unittest.main() 62