Browse Source

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.
merge-requests/126/merge
Andrew Shu 4 years ago
committed by Deimos
parent
commit
87dce83f26
  1. 3
      salt/salt/java.sls
  2. 1
      salt/salt/top.sls
  3. 1
      tildes/requirements-dev.in
  4. 1
      tildes/requirements-dev.txt
  5. 1
      tildes/scss/modules/_nav.scss
  6. 22
      tildes/tests/webtests/test_w3_validator.py
  7. 52
      tildes/tildes/templates/home.jinja2

3
salt/salt/java.sls

@ -0,0 +1,3 @@
java-openjdk:
pkg.installed:
- name: openjdk-8-jre

1
salt/salt/top.sls

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

1
tildes/requirements-dev.in

@ -1,6 +1,7 @@
-r requirements.in
black
freezegun
html5validator
mypy
prospector
pyramid-debugtoolbar

1
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

1
tildes/scss/modules/_nav.scss

@ -12,6 +12,7 @@
.nav {
margin-left: 0;
margin-top: 0;
li {
margin-top: 0.2rem;

22
tildes/tests/webtests/test_w3_validator.py

@ -0,0 +1,22 @@
# Copyright (c) 2020 Tildes contributors <code@tildes.net>
# 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()

52
tildes/tildes/templates/home.jinja2

@ -55,11 +55,13 @@
<li>Groups</li>
{% endif %}
<ul class="nav nav-group-list">
{% for group in groups|sort %}
<li class="nav-item">{{ link_to_group(group) }}</li>
{% endfor %}
</ul>
<li>
<ul class="nav nav-group-list">
{% for group in groups|sort %}
<li class="nav-item">{{ link_to_group(group) }}</li>
{% endfor %}
</ul>
</li>
</ul>
<a href="/groups" class="btn btn-primary">Browse the list of groups</a>
{% endif %}
@ -70,25 +72,27 @@
<ul class="nav">
<li>User settings</li>
<ul class="nav">
{% if not unfiltered %}
<li><details>
<summary>Filtered topic tags ({{ request.user.filtered_topic_tags|length }})</summary>
<ul class="topic-tags">
{% for tag in request.user.filtered_topic_tags %}
<li class="label label-topic-tag">
<a href="/?tag={{tag}}">{{ tag }}</a>
</li>
{% else %}
<li class="label label-topic-tag">No filtered tags</li>
{% endfor %}
</ul>
<a class="btn btn-link" href="/settings/filters">Edit filtered tags</a>
</details></li>
{% endif %}
<li class="nav-item ml-2"><a href="/settings">Settings page</a></li>
</ul>
<li>
<ul class="nav">
{% if not unfiltered %}
<li><details>
<summary>Filtered topic tags ({{ request.user.filtered_topic_tags|length }})</summary>
<ul class="topic-tags">
{% for tag in request.user.filtered_topic_tags %}
<li class="label label-topic-tag">
<a href="/?tag={{tag}}">{{ tag }}</a>
</li>
{% else %}
<li class="label label-topic-tag">No filtered tags</li>
{% endfor %}
</ul>
<a class="btn btn-link" href="/settings/filters">Edit filtered tags</a>
</details></li>
{% endif %}
<li class="nav-item ml-2"><a href="/settings">Settings page</a></li>
</ul>
</li>
</ul>
{% endif %}
{% endblock %}
Loading…
Cancel
Save