0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Change WagtailTestUtils.get_soup() to accept str/bytes instead of HttpResponse

This commit is contained in:
Sage Abdullah 2023-08-17 17:19:53 +01:00
parent cfa4b7ca69
commit ad070af8fd
No known key found for this signature in database
GPG Key ID: EB1A33CC51CC0217
4 changed files with 6 additions and 6 deletions

View File

@ -18,7 +18,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)
* Maintenance: Add `WagtailTestUtils.get_soup()` method for testing HTML content (Storm Heg, Sage Abdullah)
* Maintenance: Allow `ViewSet` subclasses to customise `url_prefix` and `url_namespace` logic (Matt Westcott)
* Maintenance: Simplify `SnippetViewSet` registration code (Sage Abdullah)

View File

@ -37,7 +37,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)
* Add `WagtailTestUtils.get_soup()` method for testing HTML content (Storm Heg, Sage Abdullah)
* Allow `ViewSet` subclasses to customise `url_prefix` and `url_namespace` logic (Matt Westcott)
* Simplify `SnippetViewSet` registration code (Sage Abdullah)

View File

@ -364,7 +364,7 @@ class TestPrivacyIndicators(WagtailTestUtils, TestCase):
# Check the response
self.assertEqual(response.status_code, 200)
soup = self.get_soup(response)
soup = self.get_soup(response.content)
# Check the private privacy indicator is visible
private_indicator = soup.select_one("[data-privacy-sidebar-private]")

View File

@ -1,17 +1,17 @@
import warnings
from contextlib import contextmanager
from typing import Union
from bs4 import BeautifulSoup
from django import VERSION as DJANGO_VERSION
from django.contrib.auth import get_user_model
from django.http import HttpResponse
from django.test.testcases import assert_and_parse_html
class WagtailTestUtils:
@staticmethod
def get_soup(response: HttpResponse, parser="html.parser") -> BeautifulSoup:
return BeautifulSoup(response.content, parser)
def get_soup(markup: Union[str, bytes], parser="html.parser") -> BeautifulSoup:
return BeautifulSoup(markup, parser)
@staticmethod
def create_test_user():