63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from fiable_db import add, get_database
|
|
|
|
|
|
def test_add_one():
|
|
"""Add one item to the database."""
|
|
add({"name": "John", "age": 42})
|
|
assert get_database() == [{"id": 1, "rev": 1, "data": {"name": "John", "age": 42}}]
|
|
|
|
|
|
def test_add_two():
|
|
"""Add two items to the database."""
|
|
add({"name": "John", "age": 12})
|
|
add({"name": "Jane", "age": 34})
|
|
print(get_database())
|
|
assert get_database() == [
|
|
{"id": 1, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
{"id": 2, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 3, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
]
|
|
|
|
|
|
def test_add_list():
|
|
"""Add a list of items to the database."""
|
|
add(
|
|
[
|
|
{"name": "John", "age": 12},
|
|
{"name": "Jane", "age": 34},
|
|
]
|
|
)
|
|
assert get_database() == [
|
|
{"id": 1, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
{"id": 2, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 3, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
{"id": 4, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 5, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
]
|
|
|
|
|
|
def test_add_list_with_one():
|
|
"""Add a list with one item to the database."""
|
|
add([{"name": "John", "age": 42}])
|
|
assert get_database() == [
|
|
{"id": 1, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
{"id": 2, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 3, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
{"id": 4, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 5, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
{"id": 6, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
]
|
|
|
|
|
|
def test_add_empty():
|
|
"""Add an empty list to the database."""
|
|
add([])
|
|
assert get_database() == [
|
|
{"id": 1, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
{"id": 2, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 3, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
{"id": 4, "rev": 1, "data": {"name": "John", "age": 12}},
|
|
{"id": 5, "rev": 1, "data": {"name": "Jane", "age": 34}},
|
|
{"id": 6, "rev": 1, "data": {"name": "John", "age": 42}},
|
|
]
|