From 6af275506e747670ac1c60b2d57f617c03abb5d0 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Mon, 28 Nov 2022 16:55:39 +0100 Subject: [PATCH] Update load test --- test/test_save.py | 47 -------------------------------------- test/test_save_and_load.py | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 test/test_save_and_load.py diff --git a/test/test_save.py b/test/test_save.py index 44a4e1c..e69de29 100644 --- a/test/test_save.py +++ b/test/test_save.py @@ -1,47 +0,0 @@ -import os -from fiable_db import start, add, save, get_database, load - -filename = "fiabledb.json" - -def delete_file(): - """Delete the database file.""" - if os.path.exists(filename): - os.remove(filename) - -def test_save_empty(): - """Test that save() works when the database is empty.""" - delete_file() - start() - save() - global database - database = [] - load() - assert get_database() == [] - - -def test_save_one(): - """Test that save() works when the database has one entry.""" - delete_file() - start() - add({"name": "John", "age": 30}) - save() - global database - database = [] - load() - assert get_database() == [{"id": 1, "rev": 1, "data": {"name": "John", "age": 30}}] - - -def test_save_two(): - """Test that save() works when the database has two entries.""" - delete_file() - start() - add({"name": "John", "age": 30}) - add({"name": "Jane", "age": 28}) - save() - global database - database = [] - load() - assert get_database() == [ - {"id": 1, "rev": 1, "data": {"name": "John", "age": 30}}, - {"id": 2, "rev": 1, "data": {"name": "Jane", "age": 28}}, - ] diff --git a/test/test_save_and_load.py b/test/test_save_and_load.py new file mode 100644 index 0000000..ae961c4 --- /dev/null +++ b/test/test_save_and_load.py @@ -0,0 +1,41 @@ +import os +from fiable_db import start, add, save, get_database, load + +filename = "fiabledb.json" + +def delete_file(): + """Delete the database file.""" + if os.path.exists(filename): + os.remove(filename) + +def test_empty(): + """Test that save() works when the database is empty.""" + delete_file() + start() + save() + load() + assert get_database() == [] + + +def test_one(): + """Test that save() works when the database has one entry.""" + delete_file() + start() + add({"name": "John", "age": 30}) + save() + load() + assert get_database() == [{"id": 1, "rev": 1, "data": {"name": "John", "age": 30}}] + + +def test_two(): + """Test that save() works when the database has two entries.""" + delete_file() + start() + add({"name": "John", "age": 30}) + add({"name": "Jane", "age": 28}) + save() + load() + assert get_database() == [ + {"id": 1, "rev": 1, "data": {"name": "John", "age": 30}}, + {"id": 2, "rev": 1, "data": {"name": "Jane", "age": 28}}, + ]