def test_purge_unwanted_modules_not_requested(self): mock_conduit = Mock() config = Mock() config.get_boolean = Mock(side_effect={constants.CONFIG_REMOVE_MISSING: False}.get) mock_inventory = Mock() # test method = SynchronizeWithDirectory(mock_conduit, config) method._purge_unwanted_modules(mock_inventory, []) # validation self.assertFalse(mock_inventory.unwanted_modules.called) self.assertFalse(mock_conduit.remove_unit.called) self.assertFalse(mock_conduit.remove_unit.called)
def test_purge_unwanted_modules_default(self): mock_conduit = Mock() config = Mock() config.get_boolean = Mock(side_effect={}.get) mock_inventory = Mock() # test method = SynchronizeWithDirectory(mock_conduit, config) method._purge_unwanted_modules(mock_inventory, []) # validation self.assertFalse(mock_inventory.unwanted_modules.called) self.assertFalse(mock_conduit.remove_unit.called) self.assertFalse(mock_conduit.remove_unit.called)
def test_purge_unwanted_modules_canceled(self): mock_conduit = Mock() config = Mock() config.get_boolean = Mock(side_effect={constants.CONFIG_REMOVE_MISSING: True}.get) mock_inventory = Mock() mock_inventory.unwanted_modules = Mock(return_value=['A', 'B']) # test method = SynchronizeWithDirectory(mock_conduit, config) method.canceled = True method._purge_unwanted_modules(mock_inventory, []) # validation self.assertFalse(mock_conduit.remove_unit.called) self.assertFalse(mock_conduit.remove_unit.called)
def test_purge_unwanted_modules(self): imported_modules = [{'A': 1}, {'B': 2}] unwanted_modules = [{'A': 3}, {'B': 4}] mock_conduit = Mock() config = Mock() config.get_boolean = Mock(side_effect={constants.CONFIG_REMOVE_MISSING: True}.get) mock_inventory = Mock() mock_inventory.unwanted_modules = Mock(return_value=unwanted_modules) # test method = SynchronizeWithDirectory(mock_conduit, config) method._purge_unwanted_modules(mock_inventory, imported_modules) # validation mock_inventory.unwanted_modules.assert_called_with(imported_modules) mock_conduit.remove_unit.assert_any_with(unwanted_modules[0]) mock_conduit.remove_unit.assert_any_with(unwanted_modules[1]) self.assertEqual(mock_conduit.remove_unit.call_count, 2)