Home | History | Annotate | Download | only in server
      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 
     10 import os, unittest
     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')
     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 
     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')
     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 
     50 if __name__ == '__main__':
     51     unittest.main()
     52