There are a few things in this, but I thought one issue would be useful as a jumping off point for other issues and thoughts.
The problem
At the moment it's too easy to make a mistake that causes invalid HTML to make it to production. It's sometimes hard to review PRs for valid HTML due to the nature of the commits, and even if you can parse the HTML in a diff, Django logic or loops might result in invalid HTML when rendered.
The solution(s)
pytest fixture for validating HTML5
https://pypi.org/project/pytidylib/ is a library that wraps tidy — a tool for validating (and indenting, but that's a different thing) HTML documents.
We can include this in a pytest helper function that works a bit like:
Once we have a nice testing interface, let's set up lists of testing URLs in each project that uses DC Utils and implement this test. We might not need to test 100% of URLs on a project, but a decent sample of the most complex or common pages should help us catch a load of errors.
There are a few things in this, but I thought one issue would be useful as a jumping off point for other issues and thoughts.
The problem
At the moment it's too easy to make a mistake that causes invalid HTML to make it to production. It's sometimes hard to review PRs for valid HTML due to the nature of the commits, and even if you can parse the HTML in a diff, Django logic or loops might result in invalid HTML when rendered.
The solution(s)
pytest fixture for validating HTML5
https://pypi.org/project/pytidylib/ is a library that wraps
tidy
— a tool for validating (and indenting, but that's a different thing) HTML documents.We can include this in a pytest helper function that works a bit like:
This is untested, but should more or less work.
Add as a feature to DC Django Utils
The above test can be packaged up in to a reusable test that we can add to DC Django Utils. This would all each project to do something like:
Implement
Once we have a nice testing interface, let's set up lists of testing URLs in each project that uses DC Utils and implement this test. We might not need to test 100% of URLs on a project, but a decent sample of the most complex or common pages should help us catch a load of errors.