From 1f6b712cedb9a76d20ddd07c42cc9cc27f7af2b4 Mon Sep 17 00:00:00 2001 From: olegush Date: Sat, 30 Nov 2019 07:01:45 +0300 Subject: [PATCH] #973 Add an html validator --- requirements.txt | 2 ++ shopelectro/tests/tests_html.py | 24 ++++++++++++++++++++++++ templates/valid_example.html | 12 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 shopelectro/tests/tests_html.py create mode 100644 templates/valid_example.html diff --git a/requirements.txt b/requirements.txt index c0e9ab9e..bca7f6f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,3 +26,5 @@ python-telegram-bot==11.1.0 sentry-sdk==0.7.2 https://github.com/selwin/django-user_agents/archive/master.zip https://github.com/fidals/refarm-site/archive/0.7.2.zip +html5validate +html5lib diff --git a/shopelectro/tests/tests_html.py b/shopelectro/tests/tests_html.py new file mode 100644 index 00000000..c6780934 --- /dev/null +++ b/shopelectro/tests/tests_html.py @@ -0,0 +1,24 @@ +import os +import unittest + +from django.test import TestCase, tag +from django.conf import settings +from django.template.loader import render_to_string + +from html5validate import validate + + +@tag('fast') +class TemplateTests(TestCase): + + @unittest.skip + def test_templates(self): + for dir, _, filenames in os.walk(settings.TEMPLATE_DIR): + for filename in filenames: + filepath = os.path.join(dir, filename) + filename, file_ext = os.path.splitext(filepath) + if file_ext == '.html': + validate(render_to_string(filepath)) + + def test_valid_example(self): + validate(render_to_string('/usr/app/src/templates/valid_example.html')) diff --git a/templates/valid_example.html b/templates/valid_example.html new file mode 100644 index 00000000..cecdf657 --- /dev/null +++ b/templates/valid_example.html @@ -0,0 +1,12 @@ + + + + + title + + + + + + +