Commit 454f368f authored by Luna's avatar Luna 😻

tests.test_embeds: add tests for path_exists

 - embed.sanitizer: better error handling when fetching the key
parent 1061eda0
Pipeline #58676024 passed with stages
in 9 minutes and 20 seconds
......@@ -71,8 +71,9 @@ def path_exists(embed: Embed, components_in: Union[List[str], str]):
# (via recursion)
return path_exists(embed[current], components[1:])
except KeyError:
# if the current component doesn't exist, return False
except (KeyError, TypeError, ValueError):
# if the current component doesn't exist or we can't do a
# key fetch, return False
return False
......@@ -19,6 +19,7 @@ along with this program. If not, see <>.
from litecord.schemas import validate
from litecord.embed.schemas import EMBED_OBJECT
from litecord.embed.sanitizer import path_exists
def validate_embed(embed):
return validate(embed, EMBED_OBJECT)
......@@ -95,8 +96,14 @@ def test_fields():
assert invalid({
'fields': [
{'name': 'a'},
def test_path_exists():
"""Test the path_exists() function for embed sanitization."""
assert path_exists({'a': {'b': 2}}, 'a.b')
assert not path_exists({'a': 'b'}, 'a.b')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment