Reputation: 1
test_data = [{'field1': 'value1',
'field2': 1},
{'field1': 'value3',
'field2': 2}
]
schema = Schema([
{Required('field1'): 'value1',
Required('field2'): int},
{Required('field1'): 'value3',
Required('field2'): int}
])
assert schema(test_data)
How to check that the list contains 2 dictionaries with the structure shown above? When I try to check for a full match, I get an error: voluptuous.error.MultipleInvalid: not a valid value for dictionary value @ data[1]['field1']
Upvotes: 0
Views: 217
Reputation: 769
I am not very familiar with voluptuous, but seems like it's not meant for parsing such schema without voluptuous.ExactSequence
Your schema would look like:
schema = Schema(
ExactSequence(
[
{Required('field1'): 'value1', Required('field2'): int},
{Required('field1'): 'value3', Required('field2'): int}
]
))
Upvotes: 0