Skip to content

Commit 530353e

Browse files
committed
Add unit test for reading different config section
1 parent fa96fd3 commit 530353e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ class TestCliFileUsing(fake_filesystem_unittest.TestCase):
8686
"password=myPassword\n"
8787
"other_setting=some_value")
8888

89+
MULTIENV_FILE_CONTENT = ("[DEFAULT]\n"
90+
"host =https://jenkins.host.com\n"
91+
"username= username\n"
92+
"some default settings = value = value\n"
93+
"\n"
94+
"[alternative]\n"
95+
"host=http://jenkins.localhosthost.ua\n"
96+
"username=Denys\n"
97+
"password=myPassword\n"
98+
"other_setting=some_value"
99+
)
100+
89101
def setUp(self):
90102
self.setUpPyfakefs()
91103

@@ -117,6 +129,30 @@ def test_read_settings_from_file(self):
117129
"other_setting": "some_value"
118130
})
119131

132+
def test_read_settings_from_file_alt_environment(self):
133+
# make sure we are in the fake fs
134+
current_folder = os.getcwd()
135+
local_folder_filename = os.path.join(current_folder, JenkinsCli.SETTINGS_FILE_NAME)
136+
self.assertFalse(os.path.exists(local_folder_filename))
137+
138+
# create the fake config file
139+
self.fs.CreateFile(local_folder_filename,
140+
contents=self.MULTIENV_FILE_CONTENT)
141+
self.assertTrue(os.path.exists(local_folder_filename))
142+
143+
# read the config from the file
144+
settings_dict = JenkinsCli.read_settings_from_file(environment='alternative')
145+
146+
# test and that the alternative environment is used, with the missing
147+
# values being provided from the DEFAULT environmtne
148+
self.assertEqual(settings_dict,
149+
{"host": 'http://jenkins.localhosthost.ua',
150+
"username": "Denys",
151+
"password": "myPassword",
152+
"other_setting": "some_value",
153+
'some default settings': 'value = value'
154+
})
155+
120156

121157
class TestCliCommands(unittest.TestCase):
122158

0 commit comments

Comments
 (0)