def test_getting_blocks_json_with_no_blocks_returns_empty_list(self): # arrange ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=None) # act blocks = ch.get_blocknames() # assert self.assertEqual(len(blocks), 0)
def test_cannot_modify_default(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) try: ch.save_configuration(DEFAULT_COMPONENT, True) except Exception as err: self.assertEqual(err.message, "Cannot save over default component")
def test_add_ioc(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) ch._add_ioc("TESTIOC1") ioc_details = ch.get_ioc_names() self.assertEqual(len(ioc_details), 1) self.assertTrue("TESTIOC1" in ioc_details)
def test_clear_config(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=None) add_block(ch, "TESTBLOCK1", "PV1", "GROUP1", True) add_block(ch, "TESTBLOCK2", "PV2", "GROUP2", True) add_block(ch, "TESTBLOCK3", "PV3", "GROUP2", True) add_block(ch, "TESTBLOCK4", "PV4", "NONE", True) blocks = ch.get_blocknames() self.assertEquals(len(blocks), 4) ch.clear_config() blocks = ch.get_blocknames() self.assertEquals(len(blocks), 0)
def test_get_config_details_empty(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) details = ch.get_config_details() self.assertEqual(len(details['blocks']), 0) self.assertEqual(len(details['groups']), 0) self.assertEqual(len(details['iocs']), 0) self.assertEqual(len(details['components']), 0) self.assertEqual(details['name'], "") self.assertEqual(details['description'], "") self.assertEqual(details['synoptic'], "")
def test_add_block(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) blk = {"name": "TESTBLOCK1", "pv": "PV1", "local": True, "group": "NONE"} ch.add_block(blk) blk_details = ch.get_block_details() self.assertEqual(len(blk_details), 1) self.assertTrue("TESTBLOCK1".lower() in blk_details) self.assertEqual(blk_details["TESTBLOCK1".lower()].pv, "PV1") self.assertEqual(blk_details["TESTBLOCK1".lower()].local, True)
def test_default_component_is_loaded(self): # Arrange ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) ch.save_configuration("TESTCONFIG", False) ch.clear_config() # Act conf = ch.load_configuration("TESTCONFIG") ch.set_config(conf, False) # Assert comp_count = len(ch.get_component_names()) comp_count_with_default = len(ch.get_component_names(True)) self.assertTrue(comp_count_with_default > comp_count)
def test_get_config_details_add_component(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) comp = create_dummy_component() ch.add_component("TESTCOMPONENT", comp) details = ch.get_config_details() self.assertEqual(len(details['blocks']), 2) blks = [x['name'] for x in details['blocks']] self.assertTrue("COMPBLOCK1" in blks) self.assertTrue("COMPBLOCK2" in blks) self.assertEqual(len(details['groups']), 2) self.assertEqual(details['groups'][0]['blocks'], ["COMPBLOCK1"]) self.assertEqual(details['groups'][1]['blocks'], ["COMPBLOCK2"]) self.assertEqual(len(details['iocs']), 0) iocs = [x['name'] for x in details['iocs']] self.assertFalse("COMPSIMPLE1" in iocs) self.assertEqual(len(details['components']), 1)
def test_set_config_details(self): # Need component ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) ch.save_configuration("TESTCOMPONENT", True) new_details = {"iocs": [{"name": "TESTSIMPLE1", "autostart": True, "restart": True, "macros": [], "pvs": [], "pvsets": [], "component": None}, {"name": "TESTSIMPLE2", "autostart": True, "restart": True, "macros": [], "pvs": [], "pvsets": [], "component": None}], "blocks": [{"name": "TESTBLOCK1", "local": True, "pv": "PV1", "component": None, "visible": True}, {"name": "TESTBLOCK2", "local": True, "pv": "PV2", "component": None, "visible": True}, {"name": "TESTBLOCK3", "local": True, "pv": "PV3", "component": None, "visible": True}], "components": [{"name": "TESTCOMPONENT"}], "groups": [{"blocks": ["TESTBLOCK1"], "name": "Group1", "component": None}, {"blocks": ["TESTBLOCK2"], "name": "Group2", "component": None}, {"blocks": ["TESTBLOCK3"], "name": "NONE", "component": None}], "name": "TESTCONFIG", "description": "Test Description", "synoptic": "TEST_SYNOPTIC" } ch.set_config_details(new_details) details = ch.get_config_details() iocs = [x['name'] for x in details['iocs']] self.assertEqual(len(iocs), 2) self.assertTrue("TESTSIMPLE1" in iocs) self.assertTrue("TESTSIMPLE2" in iocs) self.assertEqual(len(details['blocks']), 3) blks = [x['name'] for x in details['blocks']] self.assertTrue("TESTBLOCK1" in blks) self.assertTrue("TESTBLOCK2" in blks) self.assertTrue("TESTBLOCK3" in blks) self.assertEqual(len(details['groups']), 3) self.assertEqual(details['groups'][0]['blocks'], ["TESTBLOCK1"]) self.assertEqual(details['groups'][1]['blocks'], ["TESTBLOCK2"]) self.assertEqual(details['groups'][2]['blocks'], ["TESTBLOCK3"]) self.assertEqual(len(details['components']), 1) self.assertEqual(details['components'][0]['name'], "TESTCOMPONENT") self.assertEqual(details['name'], "TESTCONFIG") self.assertEqual(details['description'], "Test Description") self.assertEqual(details['synoptic'], "TEST_SYNOPTIC")
def test_get_groups_list_from_empty_repo(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager()) grps = ch.get_group_details() self.assertEqual(len(grps), 0)
def test_save_comp_add_to_config(self): # Create and save a component ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=create_dummy_component()) ch.save_configuration("TESTCOMPONENT", True) ch.clear_config() # Create and save a config that uses the component ch.set_config(create_dummy_config()) comp = ch.load_configuration("TESTCOMPONENT", True) ch.add_component("TESTCOMPONENT", comp) ch.save_configuration("TESTCONFIG", False) ch.clear_config() conf = ch.load_configuration("TESTCONFIG", False) ch.set_config(conf) self.assertEqual(len(ch.get_component_names()), 1)
def test_empty_component_save_and_load(self): ch = ConfigHolder(MACROS, MockVersionControl(), file_manager=MockConfigurationFileManager(), test_config=Configuration(MACROS)) ch.save_configuration("TESTCOMPONENT", True) ch.clear_config() conf = ch.load_configuration("TESTCOMPONENT", True) ch.set_config(conf, True) self.assertEqual(ch.get_config_name(), "TESTCOMPONENT") self.assertEqual(len(ch.get_blocknames()), 0) self.assertEqual(len(ch.get_group_details()), 0) self.assertEqual(len(ch.get_ioc_names()), 0) self.assertEqual(len(ch.get_component_names()), 0)