Add `WagtailTestUtils.get_soup()` method to get a `BeautifulSoup` object

pull/10708/head
Storm B. Heg 2023-07-20 17:32:41 +02:00 zatwierdzone przez Sage Abdullah
rodzic f0cfa62bda
commit 1c12d96457
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: EB1A33CC51CC0217
4 zmienionych plików z 18 dodań i 5 usunięć

Wyświetl plik

@ -14,6 +14,7 @@ Changelog
* Maintenance: Remove unused WorkflowStatus view, urlpattern, and workflow-status.js (Storm Heg)
* Maintenance: Add support for options/attrs in Telepath widgets so that attrs render on the created DOM (Storm Heg)
* Maintenance: Update pre-commit hooks to be in sync with latest changes to Eslint & Prettier for client-side changes (Storm Heg)
* Maintenance: Add `WagtailTestUtils.get_soup()` method to get a `BeautifulSoup` object from an `HttpResponse` object (Storm Heg)
5.1.1 (xx.xx.xxxx) - IN DEVELOPMENT

Wyświetl plik

@ -34,6 +34,7 @@ depth: 1
* Remove unused WorkflowStatus view, urlpattern, and workflow-status.js (Storm Heg)
* Add support for options/attrs in Telepath widgets so that attrs render on the created DOM (Storm Heg)
* Update pre-commit hooks to be in sync with latest changes to Eslint & Prettier for client-side changes (Storm Heg)
* Add `WagtailTestUtils.get_soup()` method to get a `BeautifulSoup` object from an `HttpResponse` object (Storm Heg)
## Upgrade considerations - changes affecting all projects

Wyświetl plik

@ -364,11 +364,16 @@ class TestPrivacyIndicators(WagtailTestUtils, TestCase):
# Check the response
self.assertEqual(response.status_code, 200)
# Check the privacy indicator is private
self.assertContains(response, '<div class="" data-privacy-sidebar-private>')
self.assertContains(
response, '<div class="w-hidden" data-privacy-sidebar-public>'
)
soup = self.get_soup(response)
# Check the private privacy indicator is visible
private_indicator = soup.select_one("[data-privacy-sidebar-private]")
# There should not be any classes applied
self.assertEqual(private_indicator["class"], [])
# Privacy indicator should be hidden
public_indicator = soup.select_one("[data-privacy-sidebar-public].w-hidden")
self.assertIsNotNone(public_indicator)
def test_explorer_private_child(self):
"""

Wyświetl plik

@ -1,12 +1,18 @@
import warnings
from contextlib import contextmanager
from bs4 import BeautifulSoup
from django import VERSION as DJANGO_VERSION
from django.contrib.auth import get_user_model
from django.http import HttpRequest
from django.test.testcases import assert_and_parse_html
class WagtailTestUtils:
@staticmethod
def get_soup(request: HttpRequest, parser="html.parser") -> BeautifulSoup:
return BeautifulSoup(request.content, parser)
@staticmethod
def create_test_user():
"""