Moved exceptions to own file; added some more tests
Some checks failed
continuous-integration/drone the build failed

This commit is contained in:
Jef Roosens 2021-05-15 13:46:36 +02:00
parent ad31d9a979
commit 0dc1b3ded4
Signed by: Jef Roosens
GPG key ID: 955C0660072F691F
3 changed files with 73 additions and 35 deletions

View file

@ -1,5 +1,6 @@
"""Tests wether the skeleton merge works."""
from app.skeleton import merge_with_skeleton, MissingKeyError, InvalidKeyError
from app.exceptions import InvalidKeyError, MissingKeyError
import pytest
@ -19,6 +20,23 @@ def test_single_invalid_key():
assert e_info.value.message == "Invalid key(s): test2"
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"
def test_single_missing_key():
"""Tests wether a MissingKeyError is correctly thrown for a single key."""
data = {
@ -33,3 +51,20 @@ def test_single_missing_key():
merge_with_skeleton(data, skel)
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"