"in" support
Is your feature request related to a problem? Please describe.
I'd like to use gazpacho for testing the HTML output of my Django application. A natural way to do this would be to search for a given HTML chunk. Therefore I'd like to be able to use the in operator on a Soup to check for that HTML chunk. This probably has utility outside of tests.
Describe the solution you'd like
I imagine this working something like:
response = self.client.get('/') # django's test client
assert response.status_code == HTTPStatus.OK
body = response.content.decode()
assert '<h1><a href="/">Home page</a></h1>' in Soup(body)
Describe alternatives you've considered
It's possible to reproduce this with find() and making assertions on the contents of the found node, but much more complicated since it requires assertions for each node in the tree.
Additional information
Django already supports a similar assertion called assertInHTML. However this relies on normalizing the HTML text and making text assertions, so it's clunky around matching the actual elements.
Interesting idea!
I don't think I fully understand, though, why would:
assert '<h1><a href="/">Home page</a></h1>' in str(Soup(body))
Not work?
If there are two attributes in the HTML, what order will they come out of Soup ? What about whitespace, etc.?