def test_no_override(self): """Establish that the environment variables do not override explicitly passed in values.""" settings = Settings() with mock.patch.dict(os.environ, {'TOWER_HOST': 'myhost'}): with settings.runtime_values(host='yourhost'): self.assertEqual(settings.host, 'yourhost')
def test_read_from_env(self): """Establish that the environment variables are correctly parsed and the values are set in the settings.""" settings = Settings() mock_env = {'TOWER_HOST': 'myhost', 'TOWER_PASSWORD': '******', 'TOWER_USERNAME': '******', 'TOWER_VERIFY_SSL': 'False'} with mock.patch.dict(os.environ, mock_env): with settings.runtime_values(): self.assertEqual(settings.host, 'myhost') self.assertEqual(settings.username, 'myuser') self.assertEqual(settings.password, 'mypass') self.assertEqual(settings.verify_ssl, False)
def test_error_etc_awx(self): """Establish that if /etc/awx/ exists but isn't readable, that we properly catch it and whine about it. """ with mock.patch.object(warnings, 'warn') as warn: with mock.patch.object(os.path, 'isdir') as isdir: isdir.return_value = True with mock.patch.object(os, 'listdir') as listdir: listdir.side_effect = OSError settings = Settings() warn.assert_called_once_with( '/etc/awx/ is present, but not readable with current ' 'permissions. Any settings defined in ' '/etc/awx/tower_cli.cfg will not be honored.', RuntimeWarning, )