def test_find_found(self, fetch_device_and_config, to_model): device, config = fetch_device_and_config.return_value = (Mock(), Mock()) model = to_model.return_value = Mock(Device) result = device_dao.find(self.deviceid) assert_that(result, same_instance(model)) fetch_device_and_config.assert_called_once_with(self.deviceid) to_model.assert_called_once_with(device, config)
def test_find_not_found(self, fetch_device_and_config, to_model): fetch_device_and_config.return_value = None, None to_model.return_value = Mock(Device) result = device_dao.find(self.deviceid) fetch_device_and_config.assert_called_once_with(self.deviceid) assert_that(to_model.call_count, equal_to(0)) assert_that(result, none())
def _delete_line_from_device(line): if hasattr(line, 'device_id') and line.device_id: device = device_dao.find(line.device_id) if device: device_services.remove_line_from_device(device, line)
def _update_device(line): if hasattr(line, 'device_id') and line.device_id: device = device_dao.find(line.device_id) if device: device_services.rebuild_device_config(device)