sachet-server/tests/test_models.py

28 lines
975 B
Python
Raw Normal View History

2023-03-28 21:48:09 -04:00
from sachet.server.models import patch
2023-03-30 20:20:09 -04:00
2023-03-28 21:48:09 -04:00
def test_patch():
"""Tests sachet/server/models.py's patch() method for dicts."""
2023-03-30 20:20:09 -04:00
assert patch(dict(), dict()) == dict()
2023-03-28 21:48:09 -04:00
2023-03-30 20:20:09 -04:00
assert patch(dict(key="value"), dict()) == dict(key="value")
2023-03-28 21:48:09 -04:00
2023-03-30 20:20:09 -04:00
assert patch(dict(key="value"), dict(key="newvalue")) == dict(key="newvalue")
2023-03-28 21:48:09 -04:00
2023-03-30 20:20:09 -04:00
assert patch(dict(key="value"), dict(key="newvalue")) == dict(key="newvalue")
2023-03-28 21:48:09 -04:00
2023-03-30 20:20:09 -04:00
assert patch(dict(key="value"), dict(key2="other_value")) == dict(
key="value", key2="other_value"
2023-03-28 21:48:09 -04:00
)
assert patch(
2023-03-30 20:20:09 -04:00
dict(nest=dict(key="value", key2="other_value")),
dict(top_key="newvalue", nest=dict(key2="new_other_value")),
) == dict(top_key="newvalue", nest=dict(key="value", key2="new_other_value"))
2023-03-28 21:48:09 -04:00
assert patch(
2023-03-30 20:20:09 -04:00
dict(nest=dict(key="value", list=[1, 2, 3, 4, 5])),
dict(top_key="newvalue", nest=dict(list=[3, 1, 4, 1, 5])),
) == dict(top_key="newvalue", nest=dict(key="value", list=[3, 1, 4, 1, 5]))