Browse Source

Build HTML Tidy, validate homepage HTML in tests

Adds the HTML Tidy library to the dev version, along with the pytidylib
wrapper for it, and a couple of tests that use it to validate the HTML
of the home page.

Includes a fix to the GitLab "Planned features" link that Tidy considers
invalid because it includes some un-encoded characters.
merge-requests/126/merge
Andrew Shu 4 years ago
committed by Deimos
parent
commit
cb7be83877
  1. 25
      salt/salt/tidy/init.sls
  2. 1
      salt/salt/top.sls
  3. 1
      tildes/requirements-dev.in
  4. 1
      tildes/requirements-dev.txt
  5. 20
      tildes/tests/webtests/test_valid_html5.py
  6. 2
      tildes/tildes/templates/base.jinja2

25
salt/salt/tidy/init.sls

@ -0,0 +1,25 @@
{% set tidy_version = '5.7.28' %}
unpack-tidy:
archive.extracted:
- name: /tmp/tidy-{{ tidy_version }}
- source:
- https://github.com/htacg/tidy-html5/archive/{{ tidy_version }}.tar.gz
- source_hash: sha256=5caa2c769204f506e24ea4986a45abe23f71d14f0fe968314f20065f342ffdba
- unless: /usr/local/bin/tidy --version | grep 'version {{ tidy_version }}'
- options: --strip-components=1
- enforce_toplevel: False
install-tidy:
pkg.installed:
- pkgs:
- build-essential
cmd.run:
- cwd: /tmp/tidy-{{ tidy_version }}/build/cmake
- names:
- cmake ../.. -DCMAKE_BUILD_TYPE=Release
- make
- make install
- ldconfig
- onchanges:
- archive: unpack-tidy

1
salt/salt/top.sls

@ -30,6 +30,7 @@ base:
- development
- prometheus
- nodejs
- tidy
'prod':
- nginx.shortener-config
- nginx.static-sites-config

1
tildes/requirements-dev.in

@ -6,5 +6,6 @@ prospector
pyramid-debugtoolbar
pytest
pytest-mock
pytidylib
testing.redis
webtest

1
tildes/requirements-dev.txt

@ -81,6 +81,7 @@ pytest-mock==3.2.0
pytest==6.0.0
python-dateutil==2.8.1
python-editor==1.0.4 # via alembic
pytidylib==0.3.2
pyyaml==5.3.1
qrcode==6.1
redis==3.5.3

20
tildes/tests/webtests/test_valid_html5.py

@ -0,0 +1,20 @@
# Copyright (c) 2020 Tildes contributors <code@tildes.net>
# SPDX-License-Identifier: AGPL-3.0-or-later
from tidylib import tidy_document
def test_homepage_tidy_loggedout(webtest_loggedout):
"""Validate HTML5 using Tidy on the Tildes homepage, logged out."""
homepage = webtest_loggedout.get("/")
_document, errors = tidy_document(homepage.body)
assert not errors
def test_homepage_tidy_loggedin(webtest):
"""Validate HTML5 using Tidy on the Tildes homepage, logged in."""
homepage = webtest.get("/")
_document, errors = tidy_document(homepage.body)
assert not errors

2
tildes/tildes/templates/base.jinja2

@ -130,7 +130,7 @@
<li class="site-footer-link"><a href="https://blog.tildes.net">Blog</a></li>
<li class="site-footer-link"><a href="https://docs.tildes.net/contact">Contact</a></li>
<li class="site-footer-link"><a href="https://gitlab.com/tildes/tildes">Source code</a></li>
<li class="site-footer-link"><a href="https://gitlab.com/tildes/tildes/issues?label_name[]=Feature+Request&label_name[]=Stage%3A%3AAccepted&scope=all&sort=priority&state=opened">Planned features</a> / <a href="https://gitlab.com/tildes/tildes/issues">All issues</a></li>
<li class="site-footer-link"><a href="https://gitlab.com/tildes/tildes/issues?label_name%5B%5D=Feature+Request&amp;label_name%5B%5D=Stage%3A%3AAccepted&amp;scope=all&amp;sort=priority&amp;state=opened">Planned features</a> / <a href="https://gitlab.com/tildes/tildes/issues">All issues</a></li>
<li class="site-footer-link"><a href="https://docs.tildes.net/policies/privacy-policy">Privacy policy</a></li>
<li class="site-footer-link"><a href="https://docs.tildes.net/policies/terms-of-use">Terms of use</a></li>
</ul>

Loading…
Cancel
Save