def test_that_add_states_to_pmds(self): self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 0) states = {0: get_example_state(), 1: get_example_state()} pms = PropertyManagerService() pms.add_states_to_pmds(states) self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 2) self._remove_all_property_managers()
def test_that_add_states_to_pmds(self): self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 0) states = {0: get_example_state(), 1: get_example_state()} pms = PropertyManagerService() pms.add_states_to_pmds(states) self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 2) self._remove_all_property_managers()
def test_that_removes_sans_property_managers_from_pmds(self): self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 0) states = {0: get_example_state(), 1: get_example_state()} pms = PropertyManagerService() pms.add_states_to_pmds(states) pms.remove_sans_property_managers() self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 0) self._remove_all_property_managers()
def test_that_can_retrieve_states_from_pmds(self): self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 0) states = {0: get_example_state(), 1: get_example_state()} pms = PropertyManagerService() pms.add_states_to_pmds(states) retrieved_states = pms.get_states_from_pmds() self.assertEqual(len(retrieved_states), 2) self.assertTrue(isinstance(retrieved_states[0], type(states[0]))) self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 2) self._remove_all_property_managers()
def test_that_can_retrieve_states_from_pmds(self): self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 0) states = {0: get_example_state(), 1: get_example_state()} pms = PropertyManagerService() pms.add_states_to_pmds(states) retrieved_states = pms.get_states_from_pmds() self.assertTrue(len(retrieved_states) == 2) self.assertTrue(isinstance(retrieved_states[0], type(states[0]))) self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 2) self._remove_all_property_managers()
def test_that_does_not_delete_pms_which_are_not_sans(self): property_manager = self._get_property_manager() PropertyManagerDataService.addOrReplace("test", property_manager) pms = PropertyManagerService() pms.remove_sans_property_managers() self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 1) self._remove_all_property_managers()
def test_that_it_adds_nothing_when_empty_list_is_passed_in(self): pms = PropertyManagerService() number_of_elements_on_pmds_after = len( PropertyManagerDataService.getObjectNames()) pms.add_states_to_pmds({}) self.assertEqual(number_of_elements_on_pmds_after, 0) self._remove_all_property_managers()
def test_that_does_not_delete_pms_which_are_not_sans(self): property_manager = self._get_property_manager() PropertyManagerDataService.addOrReplace("test", property_manager) pms = PropertyManagerService() pms.remove_sans_property_managers() self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 1) self._remove_all_property_managers()
def remove_sans_property_managers(self): property_manager_names_to_delete = [] for name in PropertyManagerDataService.getObjectNames(): if name.startswith(self.sans_property_manager_prefix): property_manager_names_to_delete.append(name) for element in property_manager_names_to_delete: PropertyManagerDataService.remove(element)
def get_states_from_pmds(self): # 1. Find all sans state names sans_property_managers = {} for name in PropertyManagerDataService.getObjectNames(): if name.startswith(self.sans_property_manager_prefix): property_manager = PropertyManagerDataService.retrieve(name) index = self._get_index_from_name(name) sans_property_managers.update({index: property_manager}) # 2. Convert property managers to states states_map = self._convert_property_manager_to_state(sans_property_managers) # 3. Create a sequence container return self._get_states_list(states_map)
def test_that_populates_the_property_manager_data_service_when_processing_is_called(self): # Arrange self._clear_property_manager_data_service() batch_file_path, user_file_path, presenter, _ = self._get_files_and_mock_presenter(BATCH_FILE_TEST_CONTENT_2) # This is not the nicest of tests, but better to test this functionality than not presenter.on_user_file_load() presenter.on_batch_file_load() # Act presenter.on_processed_clicked() # Assert # We should have two states in the PropertyManagerDataService self.assertTrue(len(PropertyManagerDataService.getObjectNames()) == 2) # clean up self._remove_files(user_file_path=user_file_path, batch_file_path=batch_file_path) self._clear_property_manager_data_service()
def test_that_populates_the_property_manager_data_service_when_processing_is_called(self): # Arrange self._clear_property_manager_data_service() batch_file_path, user_file_path, presenter, _ = self._get_files_and_mock_presenter(BATCH_FILE_TEST_CONTENT_2) # This is not the nicest of tests, but better to test this functionality than not presenter.on_user_file_load() presenter.on_batch_file_load() # Act presenter.on_processed_clicked() # Assert # We should have two states in the PropertyManagerDataService self.assertEqual(len(PropertyManagerDataService.getObjectNames()), 2) # clean up self._remove_files(user_file_path=user_file_path, batch_file_path=batch_file_path) self._clear_property_manager_data_service()
def _remove_all_property_managers(): for element in PropertyManagerDataService.getObjectNames(): PropertyManagerDataService.remove(element)
def _clear_property_manager_data_service(): for element in PropertyManagerDataService.getObjectNames(): if PropertyManagerDataService.doesExist(element): PropertyManagerDataService.remove(element)
def _remove_all_property_managers(): for element in PropertyManagerDataService.getObjectNames(): PropertyManagerDataService.remove(element)
def test_that_it_adds_nothing_when_empty_list_is_passed_in(self): pms = PropertyManagerService() number_of_elements_on_pmds_after = len(PropertyManagerDataService.getObjectNames()) pms.add_states_to_pmds({}) self.assertTrue(number_of_elements_on_pmds_after == 0) self._remove_all_property_managers()
def _clear_property_manager_data_service(): for element in PropertyManagerDataService.getObjectNames(): if PropertyManagerDataService.doesExist(element): PropertyManagerDataService.remove(element)