From 87dce83f26e8694e39b9641ce7c621b25f91dea5 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Sat, 1 Aug 2020 16:47:38 -0700 Subject: [PATCH] Install html5validator, validate HTML in tests Installs the Nu Html Checker and starts using it to validate the home page's HTML: https://validator.github.io/validator/ Also includes fixes to some lists that were nested in an invalid way. --- salt/salt/java.sls | 3 ++ salt/salt/top.sls | 1 + tildes/requirements-dev.in | 1 + tildes/requirements-dev.txt | 1 + tildes/scss/modules/_nav.scss | 1 + tildes/tests/webtests/test_w3_validator.py | 22 +++++++++ tildes/tildes/templates/home.jinja2 | 52 ++++++++++++---------- 7 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 salt/salt/java.sls create mode 100644 tildes/tests/webtests/test_w3_validator.py diff --git a/salt/salt/java.sls b/salt/salt/java.sls new file mode 100644 index 0000000..2faa64f --- /dev/null +++ b/salt/salt/java.sls @@ -0,0 +1,3 @@ +java-openjdk: + pkg.installed: + - name: openjdk-8-jre diff --git a/salt/salt/top.sls b/salt/salt/top.sls index 9f6cb0a..5c10676 100644 --- a/salt/salt/top.sls +++ b/salt/salt/top.sls @@ -30,6 +30,7 @@ base: - development - prometheus - nodejs + - java 'prod': - nginx.shortener-config - nginx.static-sites-config diff --git a/tildes/requirements-dev.in b/tildes/requirements-dev.in index 2a508df..fee5842 100644 --- a/tildes/requirements-dev.in +++ b/tildes/requirements-dev.in @@ -1,6 +1,7 @@ -r requirements.in black freezegun +html5validator mypy prospector pyramid-debugtoolbar diff --git a/tildes/requirements-dev.txt b/tildes/requirements-dev.txt index 9c01b6f..90ddaa8 100644 --- a/tildes/requirements-dev.txt +++ b/tildes/requirements-dev.txt @@ -21,6 +21,7 @@ flake8==3.8.3 # via flake8-polyfill freezegun==0.3.15 gunicorn==20.0.4 html5lib==1.1 +html5validator==0.3.3 hupper==1.10.2 # via pyramid idna==2.10 # via requests iniconfig==1.0.0 # via pytest diff --git a/tildes/scss/modules/_nav.scss b/tildes/scss/modules/_nav.scss index 7eeeb85..05af473 100644 --- a/tildes/scss/modules/_nav.scss +++ b/tildes/scss/modules/_nav.scss @@ -12,6 +12,7 @@ .nav { margin-left: 0; + margin-top: 0; li { margin-top: 0.2rem; diff --git a/tildes/tests/webtests/test_w3_validator.py b/tildes/tests/webtests/test_w3_validator.py new file mode 100644 index 0000000..35ef752 --- /dev/null +++ b/tildes/tests/webtests/test_w3_validator.py @@ -0,0 +1,22 @@ +# Copyright (c) 2020 Tildes contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +import subprocess + + +def test_homepage_html_loggedout(webtest_loggedout): + """Validate HTML5 on the Tildes homepage, logged out.""" + homepage = webtest_loggedout.get("/") + _run_html5validator(homepage.body) + + +def test_homepage_html_loggedin(webtest): + """Validate HTML5 on the Tildes homepage, logged in.""" + homepage = webtest.get("/") + _run_html5validator(homepage.body) + + +def _run_html5validator(html): + """Raises CalledProcessError on validation error.""" + result = subprocess.run(["html5validator", "-"], input=html) + result.check_returncode() diff --git a/tildes/tildes/templates/home.jinja2 b/tildes/tildes/templates/home.jinja2 index f8c1892..ac7737a 100644 --- a/tildes/tildes/templates/home.jinja2 +++ b/tildes/tildes/templates/home.jinja2 @@ -55,11 +55,13 @@
  • Groups
  • {% endif %} - +
  • + +
  • Browse the list of groups {% endif %} @@ -70,25 +72,27 @@ {% endif %} {% endblock %}