Skip to content

Instantly share code, notes, and snippets.

@morlandi
Created January 7, 2021 11:50
Show Gist options
  • Save morlandi/898f355b70a2845d2dd66e4bc686ff71 to your computer and use it in GitHub Desktop.
Save morlandi/898f355b70a2845d2dd66e4bc686ff71 to your computer and use it in GitHub Desktop.
Parsing HTML in a Django unit test with BeatifulSoap
from bs4 import BeautifulSoup
def check_diary_table_disabled(self, response):
"""
Parse #diary-table from HTML, and check for 'disabled' class
"""
html = BeautifulSoup(response.content, features="lxml")
diary_table = html.find('table', {'id': 'diary-table', }, recursive=True)
diary_table_attrs = diary_table.attrs
self.assertIn('class', diary_table_attrs)
disabled = 'disabled' in diary_table_attrs['class']
return disabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment