From 7f001267421bb628bdde2ffb4b420a75c3148c66 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Mon, 5 Dec 2022 14:02:22 +0100 Subject: [PATCH] Add test update --- .gitignore | 1 + test/test_update.py | 114 +++++++++++++++++++++++++++++++++++++++++--- todo.org | 2 +- 3 files changed, 109 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 87d5629..0019eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dist/ build/ fiable_db.egg-info/ +/fiabledb.json diff --git a/test/test_update.py b/test/test_update.py index 6d85faf..3b936ed 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -166,27 +166,127 @@ def test_update_table(): "data": {"name": "Antony", "age": 99, "height": 188}, }, ] - + + def test_update_table_not_exists(): """Test update in a table that not exists.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}, table="users") + update(1, {"name": "David"}, table="boo") + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "users", + "data": {"name": "Antony", "age": 77, "height": 188}, + } + ] + def test_update_id_not_exists(): """Test update with an id that not exists.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}, table="users") + update(2, {"name": "David"}, table="users") + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "users", + "data": {"name": "Antony", "age": 77, "height": 188}, + } + ] + def test_update_multiple_values_default(): """Test update multiple values in the default table.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}) + add({"name": "Dolores", "age": 32}) + update(1, {"name": "David", "age": 9}) + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "default", + "data": {"name": "David", "age": 9, "height": 188}, + }, + { + "id": 2, + "rev": 1, + "table": "default", + "data": {"name": "Dolores", "age": 32}, + }, + ] + def test_update_multiple_values_table(): """Test update multiple values in a table.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}, table="users") + add({"name": "Dolores", "age": 32}, table="users") + update(1, {"name": "David", "age": 9}, table="users") + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "users", + "data": {"name": "David", "age": 9, "height": 188}, + }, + { + "id": 2, + "rev": 1, + "table": "users", + "data": {"name": "Dolores", "age": 32}, + }, + ] + def test_update_with_keys_not_exists(): """Test update with keys that not exists.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}) + add({"name": "Dolores", "age": 32}) + update(1, {"is_active": True, "eyes": "blue"}) + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "default", + "data": { + "name": "Antony", + "age": 77, + "height": 188, + "is_active": True, + "eyes": "blue", + }, + }, + { + "id": 2, + "rev": 1, + "table": "default", + "data": {"name": "Dolores", "age": 32}, + }, + ] + def test_update_with_force(): """Test update with force.""" - pass + start() + add({"name": "Antony", "age": 77, "height": 188}) + add({"name": "Dolores", "age": 32}) + update(1, {"name": "David", "age": 9}, force=True) + assert get_database() == [ + { + "id": 1, + "rev": 1, + "table": "default", + "data": {"name": "David", "age": 9}, + }, + { + "id": 2, + "rev": 1, + "table": "default", + "data": {"name": "Dolores", "age": 32}, + }, + ] diff --git a/todo.org b/todo.org index 4bb6150..e42cb95 100644 --- a/todo.org +++ b/todo.org @@ -1,5 +1,5 @@ * Tasks -** DONE Add table in add testing ** IN PROGRESS Test update ** TODO Function update +** DONE Add table in add testing