From 857731b9e8361672cb255dc059aac866a4a2575e Mon Sep 17 00:00:00 2001 From: Eduardo Sousa Date: Thu, 26 Apr 2018 15:55:05 +0100 Subject: [PATCH] Fixing bug in DbMemory.del_list(), where if you passed a filter to delete the whole table it would give index out of bounds. Updated unit test to cover that case. Change-Id: I1282bd637567ca651ffcd201edfc8ff9fd0950d7 Signed-off-by: Eduardo Sousa --- osm_common/dbmemory.py | 2 +- osm_common/tests/test_dbmemory.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osm_common/dbmemory.py b/osm_common/dbmemory.py index d7419f4..6f7e4c4 100644 --- a/osm_common/dbmemory.py +++ b/osm_common/dbmemory.py @@ -64,7 +64,7 @@ class DbMemory(DbBase): for i, _ in self._find(table, self._format_filter(filter)): id_list.append(i) deleted = len(id_list) - for i in id_list: + for i in reversed(id_list): del self.db[table][i] return {"deleted": deleted} except DbException: diff --git a/osm_common/tests/test_dbmemory.py b/osm_common/tests/test_dbmemory.py index 0b62485..f73c317 100644 --- a/osm_common/tests/test_dbmemory.py +++ b/osm_common/tests/test_dbmemory.py @@ -217,7 +217,7 @@ def test_get_one_generic_exception(db_memory_with_data): assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND @pytest.mark.parametrize("table, filter, expected_data", [ -# ("test", {}, []), + ("test", {}, []), ("test", {"_id": 1}, [{"_id": 2, "data": 2}, {"_id": 3, "data": 3}]), ("test", {"_id": 2}, [{"_id": 1, "data": 1}, {"_id": 3, "data": 3}]), ("test", {"_id": 1, "data": 1}, [{"_id": 2, "data": 2}, {"_id": 3, "data": 3}]), -- 2.25.1