Skip to content
Snippets Groups Projects
Commit dd1e747c authored by Jonas's avatar Jonas
Browse files

configparser test, refactor custom conf generation

parent 2836d9f7
No related branches found
No related tags found
1 merge request!29Resolve "Initial Publish uptime of CS instance to IS"
...@@ -29,12 +29,6 @@ class TestConfigHolder(unittest.TestCase): ...@@ -29,12 +29,6 @@ class TestConfigHolder(unittest.TestCase):
self.assertEquals(self.templateName, cfg.FileName) self.assertEquals(self.templateName, cfg.FileName)
def test_it_should_save_IS_parameters(self): def test_it_should_save_IS_parameters(self):
cfgTemplateFile = open(self.cfgTemplatePath, "r")
# I make a new file
cfgTest = open(self.cfgTest_path, "w")
# And I copy the content and replaces the directories with my own dirs
custom_cfg_lines = { custom_cfg_lines = {
"IS_enabled: ": "IS_enabled: {}\n".format(True), "IS_enabled: ": "IS_enabled: {}\n".format(True),
"IS_partition: ": "IS_partition: \'{}\'\n".format("testPartition"), "IS_partition: ": "IS_partition: \'{}\'\n".format("testPartition"),
...@@ -42,21 +36,46 @@ class TestConfigHolder(unittest.TestCase): ...@@ -42,21 +36,46 @@ class TestConfigHolder(unittest.TestCase):
"IS_publication_period: ": "IS_publication_period: {}\n".format(200), "IS_publication_period: ": "IS_publication_period: {}\n".format(200),
} }
# And I copy the content and replaces the directories with my own dirs make_custom_config(self.cfgTemplatePath, self.cfgTest_path, custom_cfg_lines)
cfg = ConfigHolder(self.cfgTest_path)
self.assertEquals(True, cfg.IS_enabled)
self.assertEquals("testPartition", cfg.IS_partition)
self.assertEquals("testServer", cfg.IS_server)
self.assertEquals(200, cfg.IS_publication_period)
def test_it_should_save_IS_default_parameters_if_none_configured(self):
custom_cfg_lines = {
"IS_enabled: ": "\n",
"IS_partition: ": "\n",
"IS_server: ": "\n",
"IS_publication_period: ": "\n",
}
make_custom_config(self.cfgTemplatePath, self.cfgTest_path, custom_cfg_lines)
cfg = ConfigHolder(self.cfgTest_path)
self.assertEquals(False, cfg.IS_enabled)
self.assertEquals("initial", cfg.IS_partition)
self.assertEquals("RunParams", cfg.IS_server)
self.assertEquals(5, cfg.IS_publication_period)
def make_custom_config(original_conf_path, custom_conf_path, modifications):
cfgTest = open(custom_conf_path, "w")
cfgTemplateFile = open(original_conf_path, "r")
# And I copy the content and add my own modifications
for line in cfgTemplateFile: for line in cfgTemplateFile:
for key, value in custom_cfg_lines.iteritems(): for key, value in modifications.iteritems():
if line.find(key) is not -1: if line.find(key) is not -1:
line = value line = value
cfgTest.write(line) cfgTest.write(line)
## close files
cfgTest.close() cfgTest.close()
cfgTemplateFile.close() cfgTemplateFile.close()
cfg = ConfigHolder(self.cfgTest_path)
self.assertEquals(True, cfg.IS_enabled)
self.assertEquals("testPartition", cfg.IS_partition)
self.assertEquals("testServer", cfg.IS_server)
self.assertEquals(200, cfg.IS_publication_period)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment