1
+ from bs4 import BeautifulSoup
1
2
from django .test import TestCase , override_settings
2
3
from django .http import HttpRequest
3
4
from translation_manager .models import TranslationEntry
4
5
from wagtail .core .models import Site
6
+ from wagtail_factories import SiteFactory , PageFactory
5
7
from wagtail_localize .operations import TranslationCreator
6
8
7
9
from home .wagtail_hooks import limit_page_chooser
8
- from home .factories import SectionFactory , ArticleFactory , HomePageFactory , MediaFactory , LocaleFactory , SiteSettingsFactory
9
- from wagtail_factories import SiteFactory , PageFactory
10
- from bs4 import BeautifulSoup
10
+ from home .factories import (
11
+ SectionFactory ,
12
+ ArticleFactory ,
13
+ HomePageFactory ,
14
+ MediaFactory ,
15
+ LocaleFactory ,
16
+ SiteSettingsFactory
17
+ )
11
18
12
19
13
20
class LimitPageChooserHookTests (TestCase ):
@@ -109,7 +116,7 @@ def setUp(self):
109
116
110
117
def test_default_image_within_preset (self ):
111
118
response = self .client .get (self .article .url )
112
- parsed_response = BeautifulSoup (response .content )
119
+ parsed_response = parse_html (response .content )
113
120
rendered_image = parsed_response .find ("img" , {"class" : "article__lead-img-featured" })
114
121
image_rendition = self .article .lead_image .get_rendition ('width-360' )
115
122
@@ -122,7 +129,7 @@ def test_default_image_within_preset(self):
122
129
123
130
def test_half_default_image_within_preset (self ):
124
131
response = self .client .get (self .section .url )
125
- parsed_response = BeautifulSoup (response .content )
132
+ parsed_response = parse_html (response .content )
126
133
rendered_image = parsed_response .find ("div" , {"class" : "article-card" }).find ("img" )
127
134
image_rendition = self .article .lead_image .get_rendition ('width-180' )
128
135
@@ -135,7 +142,7 @@ def test_half_default_image_within_preset(self):
135
142
@override_settings (IMAGE_SIZE_PRESET = 750 )
136
143
def test_custom_image_within_preset (self ):
137
144
response = self .client .get (self .article .url )
138
- parsed_response = BeautifulSoup (response .content )
145
+ parsed_response = parse_html (response .content )
139
146
rendered_image = parsed_response .find ("img" , {"class" : "article__lead-img-featured" })
140
147
image_rendition = self .article .lead_image .get_rendition ('width-750' )
141
148
@@ -148,7 +155,7 @@ def test_custom_image_within_preset(self):
148
155
@override_settings (IMAGE_SIZE_PRESET = 750 )
149
156
def test_half_custom_image_within_preset (self ):
150
157
response = self .client .get (self .section .url )
151
- parsed_response = BeautifulSoup (response .content )
158
+ parsed_response = parse_html (response .content )
152
159
rendered_image = parsed_response .find ("div" , {"class" : "article-card" }).find ("img" )
153
160
image_rendition = self .article .lead_image .get_rendition ('width-375' )
154
161
@@ -157,3 +164,7 @@ def test_half_custom_image_within_preset(self):
157
164
self .assertEqual (int (rendered_image .get ('width' )), image_rendition .width )
158
165
self .assertEqual (int (rendered_image .get ('height' )), image_rendition .height )
159
166
self .assertEqual (rendered_image .get ('src' ), image_rendition .url )
167
+
168
+
169
+ def parse_html (html : str ) -> BeautifulSoup :
170
+ return BeautifulSoup (html , 'lxml' )
0 commit comments