Commit 9b5902db authored by Luna's avatar Luna 📟

tests: add test_embeds

 - embeds.schemas: add EMBED_FIELD and EMBED_OBJECT.fields to use it
parent 5de64a93
Pipeline #38983099 passed with stage
in 5 minutes and 15 seconds
......@@ -6,8 +6,6 @@ litecord.embed.sanitizer
from typing import Dict, Any
from logbook import Logger
from litecord.embed.schemas import EmbedURL
log = Logger(__name__)
Embed = Dict[str, Any]
......
......@@ -56,6 +56,18 @@ EMBED_AUTHOR = {
}
}
EMBED_FIELD = {
'name': {
'type': 'string', 'minlength': 1, 'maxlength': 128, 'required': True
},
'value': {
'type': 'string', 'minlength': 1, 'maxlength': 128, 'required': True
},
'inline': {
'type': 'boolean', 'required': False, 'default': True,
},
}
EMBED_OBJECT = {
'title': {
'type': 'string', 'minlength': 1, 'maxlength': 128, 'required': False},
......@@ -100,9 +112,10 @@ EMBED_OBJECT = {
'schema': EMBED_AUTHOR,
'required': False,
},
'fields': {
'type': 'list',
'schema': EMBED_AUTHOR,
'schema': {'type': 'dict', 'schema': EMBED_FIELD},
'required': False,
},
}
from litecord.schemas import validate
from litecord.embed.schemas import EMBED_OBJECT
def validate_embed(embed):
return validate(embed, EMBED_OBJECT)
def valid(embed: dict):
try:
validate_embed(embed)
return True
except:
return False
def invalid(embed):
try:
validate_embed(embed)
return False
except:
return True
def test_empty_embed():
valid({})
def test_basic_embed():
assert valid({
'title': 'test',
'description': 'acab',
'url': 'https://www.w3.org',
'color': 123
})
def test_footer_embed():
assert invalid({
'footer': {}
})
assert valid({
'title': 'test',
'footer': {
'text': 'abcdef'
}
})
def test_image():
assert invalid({
'image': {}
})
assert valid({
'image': {
'url': 'https://www.w3.org'
}
})
def test_author():
assert invalid({
'author': {
'name': ''
}
})
assert valid({
'author': {
'name': 'abcdef'
}
})
def test_fields():
assert valid({
'fields': [
{'name': 'a', 'value': 'b'},
{'name': 'c', 'value': 'd', 'inline': False},
]
})
valid({
'fields': [
{'name': 'a'},
]
})
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