verbose error with wrong options
This commit is contained in:
parent
fe3dad39b5
commit
c6dbcda947
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = yamlhttpforms
|
||||
version = 0.0.3
|
||||
version = 0.0.4
|
||||
author = Daniil F.
|
||||
author_email = mail@placeholder123.to
|
||||
description = HTTP forms defined in YAML
|
||||
|
@ -45,9 +45,19 @@ def check_select_field_options(field_tag: Tag, field_interface: 'FormField', che
|
||||
`FieldInterfaceWrong`
|
||||
if the `default` is not equal to the value of the <option> tag which has the `selected` attribute
|
||||
"""
|
||||
options = {tag[VALUE]: tag.get_text(strip=True) for tag in field_tag.find_all(OPTION)}
|
||||
if options != field_interface.options:
|
||||
raise SelectOptionsWrong(f"Wrong options in {field_interface}")
|
||||
html_options = {(tag[VALUE], tag.get_text(strip=True)) for tag in field_tag.find_all(OPTION)}
|
||||
interface_options = set(field_interface.options.items())
|
||||
missing_in_interface = html_options - interface_options
|
||||
not_in_html = interface_options - html_options
|
||||
s = ""
|
||||
if missing_in_interface:
|
||||
s += "\nThe following <options> HTML tags were not found in the interface:\n"
|
||||
s += "\n".join(str(tup) for tup in missing_in_interface)
|
||||
if not_in_html:
|
||||
s += "\nThe following options were defined, but are not present in the HTML:\n"
|
||||
s += "\n".join(str(tup) for tup in not_in_html)
|
||||
if s:
|
||||
raise SelectOptionsWrong(f"Wrong options in field '{field_interface.name}'." + s)
|
||||
if check_defaults:
|
||||
default = field_tag.find(lambda tag: tag.name == OPTION and tag.has_attr(SELECTED))[VALUE]
|
||||
if default != field_interface.default:
|
||||
|
Loading…
Reference in New Issue
Block a user