backup-tool/tests/test_skeleton.py

71 lines
1.7 KiB
Python
Raw Normal View History

2021-05-15 13:40:11 +02:00
"""Tests wether the skeleton merge works."""
from app.skeleton import merge_with_skeleton, MissingKeyError, InvalidKeyError
from app.exceptions import InvalidKeyError, MissingKeyError
2021-05-15 13:40:11 +02:00
import pytest
2021-04-26 19:57:54 +02:00
2021-05-15 13:40:11 +02:00
def test_single_invalid_key():
"""Tests wether an InvalidKeyError is correctly thrown for a single key."""
data = {
"test": 1,
"test2": "test"
}
skel = {
"test": None,
2021-04-26 19:57:54 +02:00
}
2021-05-15 13:40:11 +02:00
with pytest.raises(InvalidKeyError) as e_info:
merge_with_skeleton(data, skel)
2021-04-26 19:57:54 +02:00
2021-05-15 13:40:11 +02:00
assert e_info.value.message == "Invalid key(s): test2"
2021-04-26 19:57:54 +02:00
def test_multiple_invalid_keys():
"""Tests wether an InvalidKeyError is thrown for multiple keys."""
data = {
"test": 1,
"test2": "test",
"test3": "test",
}
skel = {
"test": None,
}
with pytest.raises(InvalidKeyError) as e_info:
merge_with_skeleton(data, skel)
assert e_info.value.message == "Invalid key(s): test2, test3"
2021-05-15 13:40:11 +02:00
def test_single_missing_key():
"""Tests wether a MissingKeyError is correctly thrown for a single key."""
data = {
"test": 1,
2021-04-26 19:57:54 +02:00
}
2021-05-15 13:40:11 +02:00
skel = {
"test": None,
"test2": None,
}
with pytest.raises(MissingKeyError) as e_info:
merge_with_skeleton(data, skel)
2021-04-26 19:57:54 +02:00
2021-05-15 13:40:11 +02:00
assert e_info.value.message == "Missing key(s): test2"
def test_multiple_missing_keys():
"""Tests wether a MissingKeyError is correctly thrown for multiple keys."""
data = {
"test": 1,
}
skel = {
"test": None,
"test2": None,
"test3": None,
}
with pytest.raises(MissingKeyError) as e_info:
merge_with_skeleton(data, skel)
assert e_info.value.message == "Missing key(s): test2, test3"