blob: 739173e033cf50b5df1d3b2337908800d11f4c35 [file] [log] [blame]
mbligh37eceaa2008-12-15 22:56:37 +00001#!/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 Barnetteb9b37982016-05-20 19:23:39 -07008#pylint: disable=missing-docstring
9
10import os, unittest
mbligh37eceaa2008-12-15 22:56:37 +000011import 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')
mblighed1b0212009-11-21 01:46:39 +000026 self._saved_environ = dict(os.environ)
27 if 'AUTOTEST_WEB' in os.environ:
28 del os.environ['AUTOTEST_WEB']
mbligh37eceaa2008-12-15 22:56:37 +000029
30
31 def tearDown(self):
32 self.god.unstub_all()
mblighed1b0212009-11-21 01:46:39 +000033 os.environ.clear()
34 os.environ.update(self._saved_environ)
mbligh37eceaa2008-12-15 22:56:37 +000035
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')
Prathmesh Prabhu2892ff62017-12-19 10:21:31 -080041 rpc_client_lib.add_protocol.expect_call('test-host').and_return(
42 'http://test-host')
mbligh37eceaa2008-12-15 22:56:37 +000043 rpc_client_lib.get_proxy.expect_call(
44 'http://test-host/path',
45 headers={'AUTHORIZATION': 'unittest-user'})
mblighce3f5382009-06-15 21:23:21 +000046 frontend.RpcClient('/path', None, None, None, None, None)
mbligh37eceaa2008-12-15 22:56:37 +000047 self.god.check_playback()
48
49
Richard Barnette08e487d2018-03-30 18:39:31 -070050class 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
mbligh37eceaa2008-12-15 22:56:37 +000060if __name__ == '__main__':
61 unittest.main()