mirror of https://gitlab.com/litecord/litecord.git
tests.test_embeds: add tests for path_exists
- embed.sanitizer: better error handling when fetching the key
This commit is contained in:
parent
1061eda096
commit
454f368f94
|
|
@ -71,8 +71,9 @@ def path_exists(embed: Embed, components_in: Union[List[str], str]):
|
|||
# (via recursion)
|
||||
try:
|
||||
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 <http://www.gnu.org/licenses/>.
|
|||
|
||||
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():
|
|||
]
|
||||
})
|
||||
|
||||
valid({
|
||||
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')
|
||||
|
|
|
|||
Loading…
Reference in New Issue