Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] EB-124910 Adding pointer to extra key error dictionary field #79

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions conformity/fields/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ def errors(self, value): # type: (AnyType) -> ListType[Error]
# Check for extra keys
extra_keys = set(value.keys()) - set(self.contents.keys())
if extra_keys and not self.allow_extra_keys:
result.append(
Error(
'Extra keys present: {}'.format(', '.join(six.text_type(key) for key in sorted(extra_keys))),
for extra_key in sorted(extra_keys):
result.append(Error(
'Extra key present: {}'.format(six.text_type(extra_key)),
code=ERROR_CODE_UNKNOWN,
),
)
pointer=six.text_type(extra_key),
))

if not result and self.additional_validator:
return self.additional_validator.errors(value)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def test_complex(self): # type: () -> None
sorted([
Error('Not an integer', pointer='child_ids.2'),
Error('Missing key: address', code=ERROR_CODE_MISSING, pointer='address'),
Error('Extra keys present: another_bad, unsolicited_item', code=ERROR_CODE_UNKNOWN),
Error('Extra key present: another_bad', code=ERROR_CODE_UNKNOWN, pointer='another_bad'),
Error('Extra key present: unsolicited_item', code=ERROR_CODE_UNKNOWN, pointer='unsolicited_item'),
Error('Not a set or frozenset', pointer='unique_things'),
]),
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_validation(self):
},
})

assert '- inner_qux: Extra keys present: not_defined' in error_context.value.args[0]
assert '- inner_qux.not_defined: Extra key present: not_defined' in error_context.value.args[0]

with pytest.raises(Settings.ImproperlyConfigured) as error_context:
SettingsTwo({
Expand Down