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

"in" support #59

Open
adamchainz opened this issue Jan 12, 2021 · 2 comments
Open

"in" support #59

adamchainz opened this issue Jan 12, 2021 · 2 comments

Comments

@adamchainz
Copy link

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.

@maxhumber
Copy link
Owner

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?

@adamchainz
Copy link
Author

If there are two attributes in the HTML, what order will they come out of Soup ? What about whitespace, etc.?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants