Test for page titles in client request fixture

We’re frequently ending up with mismatched page titles on our pages
because:
- they’re hard to spot in the browsers tab bar
- new pages are often created by copy pasting old ones

It would be hard to write some kind of macro that spat out the h1
and the page title because they go into different blocks in the
parent template.

Instead, we can catch these mistakes by testing for them. Going
forward we should be using the `client_request` fixture for testing.
So it makes sense to put the page title test in here so that we
get it for free in every test – same way we do for testing response
codes.

fixup! Test for page titles in client request fixture
This commit is contained in:
Chris Hill Scott
2017-07-04 14:04:46 +01:00
committed by Chris Hill-Scott
parent 7ff6075e0a
commit 17199f0c26

View File

@@ -1757,13 +1757,26 @@ def client_request(logged_in_client):
yield session
@staticmethod
def get(endpoint, _expected_status=200, _follow_redirects=False, **endpoint_kwargs):
def get(
endpoint,
_expected_status=200,
_follow_redirects=False,
_test_page_title=True,
**endpoint_kwargs
):
resp = logged_in_client.get(
url_for(endpoint, **(endpoint_kwargs or {})),
follow_redirects=_follow_redirects,
)
assert resp.status_code == _expected_status
return BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
page = BeautifulSoup(resp.data.decode('utf-8'), 'html.parser')
if _test_page_title:
page_title, h1 = (
normalize_spaces(page.find(selector).text) for selector in ('title', 'h1')
)
if not normalize_spaces(page_title).startswith(h1):
raise AssertionError('Page title {} does not start with H1 {}'.format(page_title, h1))
return page
@staticmethod
def post(endpoint, _data=None, _expected_status=None, _follow_redirects=False, **endpoint_kwargs):