grappa
grappa copied to clipboard
"From a list of objects, assert on how many objects contain a specific key/value pair"
Say I have a list
[{"foo" : "bar"}, {"foo: "bar2"}, {"foo" : "bar"},{"random":"1"}]
Is there a way of asserting that the list contains exactly 2 occurrences of {"foo":"bar"}
Can't seem to find anything in the docs.
I would do this
items = [{"foo" : "bar"}, {"foo": "bar2"}, {"foo" : "bar"},{"random":"1"}]
search = {"foo" : "bar"}
matches = [x for x in items if x == search]
matches | should.have.length(2)