fiableDB/test/test_start.py

49 lines
1.5 KiB
Python
Raw Normal View History

2022-11-21 16:37:43 +01:00
import os
import shutil
from fiable_db import start, get_database
2022-11-20 22:15:20 +01:00
def test_create_new_file():
"""Create a new file with a different name"""
2022-11-21 16:37:43 +01:00
filename = "test.json"
2022-11-20 22:15:20 +01:00
start(filename)
2022-11-21 16:37:43 +01:00
assert os.path.isfile(filename), "The file does not exist"
2022-11-20 22:15:20 +01:00
# Remove the file
os.remove(filename)
2022-11-21 16:37:43 +01:00
2022-11-20 22:15:20 +01:00
def test_create_default_file():
"""Create a new file with the default name"""
2022-11-21 16:37:43 +01:00
filename = "fiabledb.json"
2022-11-20 22:15:20 +01:00
start()
2022-11-21 16:37:43 +01:00
assert os.path.isfile(filename), "The file does not exist"
2022-11-20 22:15:20 +01:00
# Remove the file
os.remove(filename)
2022-11-21 16:37:43 +01:00
2022-11-20 22:15:20 +01:00
def test_read_file_default():
"""Read the default file"""
2022-11-21 16:37:43 +01:00
input_file = "test/example.json"
output_file = "fiabledb.json"
shutil.copy(input_file, output_file)
2022-11-20 22:15:20 +01:00
start()
2022-11-21 16:37:43 +01:00
data = get_database()
2022-11-20 22:15:20 +01:00
assert data == [
{"id": 2, "rev": 1, "data": {"name": "Noelia", "age": 34, "height": 165}},
{"id": 3, "rev": 1, "data": {"name": "Juan", "age": 41, "height": 187}},
{"id": 4, "rev": 1, "data": {"name": "Valentina", "age": 12, "height": 142}},
2022-11-21 16:37:43 +01:00
], "The data is not the same: " + str(data)
os.remove(output_file)
2022-11-20 22:15:20 +01:00
def test_read_file_custom_name():
"""Read a file with a custom name"""
2022-11-21 16:37:43 +01:00
filename = "test/example.json"
2022-11-20 22:15:20 +01:00
start(filename)
2022-11-21 16:37:43 +01:00
data = get_database()
2022-11-20 22:15:20 +01:00
assert data == [
{"id": 2, "rev": 1, "data": {"name": "Noelia", "age": 34, "height": 165}},
{"id": 3, "rev": 1, "data": {"name": "Juan", "age": 41, "height": 187}},
{"id": 4, "rev": 1, "data": {"name": "Valentina", "age": 12, "height": 142}},
2022-11-21 16:37:43 +01:00
], "The data is not the same: " + str(data)