Exemplo n.º 1
0
 def test_create_session_config(self):
     env = LmEnvironment('lm', 'test')
     session_config = env.create_session_config()
     self.assertIsInstance(session_config, LmSessionConfig)
     self.assertEqual(session_config.env, env)
     self.assertEqual(session_config.username, None)
     self.assertEqual(session_config.password, None)
Exemplo n.º 2
0
 def test_is_secure(self):
     insecure_env = LmEnvironment('lm', 'test', 80)
     self.assertFalse(insecure_env.is_secure)
     secure_env = LmEnvironment('lm',
                                'test',
                                80,
                                secure=True,
                                username='******')
     self.assertTrue(secure_env.is_secure)
Exemplo n.º 3
0
 def test_init(self):
     env = LmEnvironment('lm',
                         'test',
                         80,
                         'https',
                         secure=True,
                         username='******',
                         password='******')
     session_config = env.create_session_config()
     session = LmSession(session_config)
     self.assertEqual(session.env, env)
     self.assertEqual(session.username, 'user')
     self.assertEqual(session.password, 'secret')
Exemplo n.º 4
0
 def test_deployment_location_driver(self, deployment_location_driver_init):
     session = LmSession(
         LmSessionConfig(LmEnvironment('lm', 'test', 80, 'https'), None))
     driver = session.deployment_location_driver
     deployment_location_driver_init.assert_called_once_with(
         'https://test:80', None)
     self.assertEqual(driver, deployment_location_driver_init.return_value)
Exemplo n.º 5
0
 def test_init_fails_when_host_is_none(self):
     with self.assertRaises(EnvironmentConfigError) as context:
         config = LmEnvironment('lm', None, 80)
     self.assertEqual(
         str(context.exception),
         'LM environment cannot be configured without property: host (ip_address)'
     )
Exemplo n.º 6
0
 def test_infrastructure_keys_driver(self, infrastructure_keys_driver_init):
     session = LmSession(
         LmSessionConfig(LmEnvironment('lm', 'test', 80, 'https'), None))
     driver = session.infrastructure_keys_driver
     infrastructure_keys_driver_init.assert_called_once_with(
         'https://test:80', None)
     self.assertEqual(driver, infrastructure_keys_driver_init.return_value)
Exemplo n.º 7
0
 def test_init_fails_when_protocol_unsupported(self):
     with self.assertRaises(EnvironmentConfigError) as context:
         config = LmEnvironment('lm', 'test', 80, 'ftp')
     self.assertEqual(
         str(context.exception),
         'LM environment cannot be configured with unsupported protocol \'ftp\'. Must be one of: [\'http\', \'https\']'
     )
Exemplo n.º 8
0
 def test_init_fails_when_secure_and_username_is_none(self):
     with self.assertRaises(EnvironmentConfigError) as context:
         config = LmEnvironment('lm', 'test', 80, secure=True)
     self.assertEqual(
         str(context.exception),
         'Secure LM environment cannot be configured without property: username. If the LM environment is not secure then set \'secure\' to False'
     )
Exemplo n.º 9
0
 def test_auth_address_fails_when_insecure(self):
     env = LmEnvironment('lm', 'test')
     with self.assertRaises(EnvironmentRuntimeError) as context:
         env.auth_address
     self.assertEqual(
         str(context.exception),
         'auth_address cannot be determined for a non-secure LM environment'
     )
Exemplo n.º 10
0
 def test_init_with_password(self):
     config = LmEnvironment('lm',
                            'test',
                            80,
                            secure=True,
                            username='******',
                            password='******')
     self.assertEqual(config.username, 'test')
     self.assertEqual(config.password, 'secret')
Exemplo n.º 11
0
 def test_attributes(self):
     name = 'test'
     description = 'test description'
     lm = LmEnvironment('test', 'host')
     arms =   {'test': ArmEnvironment('test', 'host')}
     config = EnvironmentGroup(name, description, lm, arms)
     self.assertEqual(config.name, name)
     self.assertEqual(config.description, description)
     self.assertEqual(config.lm, lm)
     self.assertEqual(config.arms, arms)
Exemplo n.º 12
0
 def test_kami_address(self):
     env = LmEnvironment('lm',
                         'test',
                         80,
                         'http',
                         secure=True,
                         username='******',
                         auth_host='auth',
                         auth_port=82,
                         auth_protocol='https')
     self.assertEqual(env.kami_address, 'http://test:31289')
Exemplo n.º 13
0
 def test_init(self):
     environments = {
         'groupA':
         EnvironmentGroup(
             'groupA', '', LmEnvironment('alm', 'host'),
             {'defaultrm': ArmEnvironment('defaultrm', 'host')}),
         'groupB':
         EnvironmentGroup(
             'groupB', '', LmEnvironment('alm', 'hostB'),
             {'defaultrm': ArmEnvironment('defaultrm', 'hostB')})
     }
     config = Config(environments)
     ctl = Ctl(config)
     self.assertEqual(len(ctl.environments), 2)
     groupA_env = ctl.environment_group_named('groupA')
     self.assertIsNotNone(groupA_env)
     self.assertIsInstance(groupA_env, EnvironmentGroup)
     groupB_env = ctl.environment_group_named('groupB')
     self.assertIsNotNone(groupB_env)
     self.assertIsInstance(groupB_env, EnvironmentGroup)
Exemplo n.º 14
0
 def test_address(self):
     env = LmEnvironment('lm', 'test')
     self.assertEqual(env.address, 'https://test')
     env = LmEnvironment('lm', 'test', 32455)
     self.assertEqual(env.address, 'https://test:32455')
     env = LmEnvironment('lm', 'test', 32455, 'http')
     self.assertEqual(env.address, 'http://test:32455')
     env = LmEnvironment('lm', 'test', None, 'http')
     self.assertEqual(env.address, 'http://test')
     env = LmEnvironment('lm', 'test', None, 'http', path='gateway')
     self.assertEqual(env.address, 'http://test/gateway')
     env = LmEnvironment('lm', 'test', 32455, 'http', path='gateway')
     self.assertEqual(env.address, 'http://test:32455/gateway')
Exemplo n.º 15
0
 def test_infrastructure_keys_driver_with_security(
         self, infrastructure_keys_driver_init, mock_security_ctrl_init):
     session = LmSession(
         LmSessionConfig(
             LmEnvironment('lm',
                           'test',
                           80,
                           'https',
                           secure=True,
                           username='******',
                           auth_host='auth',
                           auth_port=81,
                           auth_protocol='http'), 'user', 'secret'))
     driver = session.infrastructure_keys_driver
     mock_security_ctrl_init.assert_called_once_with(
         'http://auth:81', 'user', 'secret')
     infrastructure_keys_driver_init.assert_called_once_with(
         'https://test:80', mock_security_ctrl_init.return_value)
     self.assertEqual(driver, infrastructure_keys_driver_init.return_value)
Exemplo n.º 16
0
 def test_set_defaults_when_none(self):
     config = LmEnvironment('lm',
                            'test',
                            None,
                            None,
                            path=None,
                            secure=True,
                            username='******',
                            auth_host=None,
                            auth_port=None,
                            auth_protocol=None,
                            brent_name=None)
     self.assertEqual(config.name, 'lm')
     self.assertEqual(config.host, 'test')
     self.assertEqual(config.port, None)
     self.assertEqual(config.protocol, 'https')
     self.assertEqual(config.path, None)
     self.assertEqual(config.secure, True)
     self.assertEqual(config.username, 'user')
     self.assertEqual(config.auth_host, 'test')
     self.assertEqual(config.auth_port, None)
     self.assertEqual(config.auth_protocol, 'https')
     self.assertEqual(config.brent_name, 'brent')
Exemplo n.º 17
0
 def test_init_with_all(self):
     config = LmEnvironment('lm',
                            'test',
                            80,
                            'http',
                            path='gateway',
                            secure=True,
                            username='******',
                            password='******',
                            auth_host='auth',
                            auth_port=81,
                            auth_protocol='https',
                            brent_name='alt_brent')
     self.assertEqual(config.name, 'lm')
     self.assertEqual(config.host, 'test')
     self.assertEqual(config.port, 80)
     self.assertEqual(config.protocol, 'http')
     self.assertEqual(config.path, 'gateway')
     self.assertEqual(config.secure, True)
     self.assertEqual(config.username, 'user')
     self.assertEqual(config.auth_host, 'auth')
     self.assertEqual(config.auth_port, 81)
     self.assertEqual(config.auth_protocol, 'https')
     self.assertEqual(config.brent_name, 'alt_brent')
Exemplo n.º 18
0
 def test_create_session_config_with_default_username_password(self):
     env = LmEnvironment('lm',
                         'test',
                         80,
                         'https',
                         secure=True,
                         username='******')
     session_config = env.create_session_config()
     self.assertEqual(session_config.username, 'user')
     self.assertEqual(session_config.password, None)
     env = LmEnvironment('lm',
                         'test',
                         80,
                         'https',
                         secure=True,
                         username='******',
                         password='******')
     session_config = env.create_session_config()
     self.assertEqual(session_config.username, 'user')
     self.assertEqual(session_config.password, 'secret')
Exemplo n.º 19
0
 def test_init_fails_when_name_is_none(self):
     with self.assertRaises(EnvironmentConfigError) as context:
         config = LmEnvironment(None, '', 80)
     self.assertEqual(
         str(context.exception),
         'LM environment cannot be configured without property: name')
Exemplo n.º 20
0
 def test_init_fails_with_unsupported_kwargs(self):
     with self.assertRaises(TypeError) as context:
         config = LmEnvironment('lm', 'test', 80, not_a_key='test')
     self.assertEqual(
         str(context.exception),
         '__init__() got an unexpected keyword argument \'not_a_key\'')
Exemplo n.º 21
0
 def test_init_auth_defaults_auth_address(self):
     config = LmEnvironment('lm', 'test', 80, secure=True, username='******')
     self.assertEqual(config.auth_host, config.host)
     self.assertEqual(config.auth_port, config.port)
     self.assertEqual(config.auth_protocol, config.auth_protocol)
Exemplo n.º 22
0
 def test_init_defaults_path(self):
     config = LmEnvironment('lm', 'test')
     self.assertEqual(config.path, None)
Exemplo n.º 23
0
 def test_init_defaults_port_and_protocol(self):
     config = LmEnvironment('lm', 'test')
     self.assertEqual(config.port, None)
     self.assertEqual(config.protocol, 'https')
Exemplo n.º 24
0
 def test_behaviour_driver(self, behaviour_driver_init):
     session = LmSession(
         LmSessionConfig(LmEnvironment('lm', 'test', 80, 'https'), None))
     driver = session.behaviour_driver
     behaviour_driver_init.assert_called_once_with('https://test:80', None)
     self.assertEqual(driver, behaviour_driver_init.return_value)