def test_read_settings_from_file(self): current_folder = os.getcwd() local_folder_filename = os.path.join(current_folder, JenkinsCli.SETTINGS_FILE_NAME) home_folder_filename = os.path.join(os.path.expanduser("~"), JenkinsCli.SETTINGS_FILE_NAME) self.assertFalse(os.path.exists(local_folder_filename)) self.assertFalse(os.path.exists(home_folder_filename)) self.fs.CreateFile(home_folder_filename, contents=self.HOME_FILE_CONTENT) self.assertTrue(os.path.exists(home_folder_filename)) settings_dict = JenkinsCli.read_settings_from_file() self.assertEqual(settings_dict, {"host": 'https://jenkins.host.com', "username": "******", "some weird settings": "value = value" }) self.fs.CreateFile(local_folder_filename, contents=self.LOCAL_FILE_CONTENT) self.assertTrue(os.path.exists(local_folder_filename)) settings_dict = JenkinsCli.read_settings_from_file() self.assertEqual(settings_dict, {"host": 'http://jenkins.localhosthost.ua', "username": "******", "password": "******", "other_setting": "some_value" })
def test_read_settings_from_file(self): current_folder = os.getcwd() local_folder_filename = os.path.join(current_folder, JenkinsCli.SETTINGS_FILE_NAME) home_folder_filename = os.path.join(os.path.expanduser("~"), JenkinsCli.SETTINGS_FILE_NAME) self.assertFalse(os.path.exists(local_folder_filename)) self.assertFalse(os.path.exists(home_folder_filename)) self.fs.CreateFile(home_folder_filename, contents=self.HOME_FILE_CONTENT) self.assertTrue(os.path.exists(home_folder_filename)) settings_dict = JenkinsCli.read_settings_from_file() self.assertEqual( settings_dict, { "host": 'https://jenkins.host.com', "username": "******", "some weird settings": "value = value" }) self.fs.CreateFile(local_folder_filename, contents=self.LOCAL_FILE_CONTENT) self.assertTrue(os.path.exists(local_folder_filename)) settings_dict = JenkinsCli.read_settings_from_file() self.assertEqual( settings_dict, { "host": 'http://jenkins.localhosthost.ua', "username": "******", "password": "******", "other_setting": "some_value" })
def test_read_settings_from_file_alt_environment(self): # make sure we are in the fake fs current_folder = os.getcwd() local_folder_filename = os.path.join(current_folder, JenkinsCli.SETTINGS_FILE_NAME) self.assertFalse(os.path.exists(local_folder_filename)) # create the fake config file self.fs.CreateFile(local_folder_filename, contents=self.MULTIENV_FILE_CONTENT) self.assertTrue(os.path.exists(local_folder_filename)) # read the config from the file settings_dict = JenkinsCli.read_settings_from_file(environment='alternative') # test and that the alternative environment is used, with the missing # values being provided from the DEFAULT environmtne self.assertEqual(settings_dict, {"host": 'http://jenkins.localhosthost.ua', "username": "******", "password": "******", "other_setting": "some_value", 'some default settings': 'value = value' })