def setUp(self): # Make directory and fill with fake content FILEPATH_MANAGER.initialise(os.path.abspath(CONFIG_PATH), os.path.abspath(SCHEMA_PATH)) # Find the schema directory dir = os.path.join(".") while SCHEMA_FOLDER not in os.listdir(dir): dir = os.path.join(dir, "..") self.bs = MockBlockServer() self.file_io = MockDevicesFileIO() self.dm = DevicesManager(self.bs, os.path.join(dir, SCHEMA_FOLDER), MockVersionControl(), self.file_io)
class TestDevicesManagerSequence(unittest.TestCase): def setUp(self): # Make directory and fill with fake content FILEPATH_MANAGER.initialise(os.path.abspath(CONFIG_PATH), os.path.abspath(SCHEMA_PATH)) # Find the schema directory dir = os.path.join(".") while SCHEMA_FOLDER not in os.listdir(dir): dir = os.path.join(dir, "..") self.bs = MockBlockServer() self.file_io = MockDevicesFileIO() self.dm = DevicesManager(self.bs, os.path.join(dir, SCHEMA_FOLDER), MockVersionControl(), self.file_io) def tearDown(self): pass def test_get_devices_filename_returns_correct_file_name(self): # Arrange expected = get_expected_devices_file_path() # Act result = self.dm.get_devices_filename() # Assert self.assertEquals(expected, result) def test_when_devices_screens_file_does_not_exist_then_current_uses_blank_devices_data(self): # Arrange self.dm.initialise() # Assert self.assertTrue(len(self.file_io.files) == 0) self.assertEquals(self.bs.pvs[GET_SCREENS], compress_and_hex(self.dm.get_blank_devices())) def test_given_invalid_devices_data_when_device_xml_saved_then_not_saved(self): # Arrange: self.dm.initialise() # Act: Save invalid new data to file self.dm.save_devices_xml(INVALID_DEVICES) # Assert # Should stay as blank (i.e. the previous value) self.assertEquals(self.dm.get_blank_devices(), dehex_and_decompress(self.bs.pvs[GET_SCREENS])) def test_given_valid_devices_data_when_device_xml_saved_then_saved(self): # Arrange: self.dm.initialise() # Act: Save the new data to file self.dm.save_devices_xml(EXAMPLE_DEVICES) # Assert: # Device screens in blockserver should have been updated with value written to device manager self.assertEquals(EXAMPLE_DEVICES, dehex_and_decompress(self.bs.pvs[GET_SCREENS]))