diff --git a/.drone.yml b/.drone.yml index eb40e21a..1478f663 100644 --- a/.drone.yml +++ b/.drone.yml @@ -81,7 +81,7 @@ pipeline: - python manage.py excel - python manage.py price - python manage.py collectstatic --noinput - - python manage.py test --parallel --tag fast -k -v 3 + - python manage.py test --tag fast -k -v 3 slow-test: <<: *test 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/settings/base.py b/shopelectro/settings/base.py index f13ca17f..815ededd 100644 --- a/shopelectro/settings/base.py +++ b/shopelectro/settings/base.py @@ -100,10 +100,11 @@ ROOT_URLCONF = 'shopelectro.urls' TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates') +TEMPLATE_ASSETS_DIR = os.path.join(BASE_DIR, 'shopelectro/tests/assets') TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [TEMPLATE_DIR], + 'DIRS': [TEMPLATE_DIR, TEMPLATE_ASSETS_DIR], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/shopelectro/tests/assets/invalid_markup_example.html b/shopelectro/tests/assets/invalid_markup_example.html new file mode 100644 index 00000000..596bd9ce --- /dev/null +++ b/shopelectro/tests/assets/invalid_markup_example.html @@ -0,0 +1,3 @@ + + + joke diff --git a/shopelectro/tests/assets/valid_markup_example.html b/shopelectro/tests/assets/valid_markup_example.html new file mode 100644 index 00000000..cecdf657 --- /dev/null +++ b/shopelectro/tests/assets/valid_markup_example.html @@ -0,0 +1,12 @@ + + + + + title + + + + + + + diff --git a/shopelectro/tests/tests_html.py b/shopelectro/tests/tests_html.py new file mode 100644 index 00000000..31ff18b4 --- /dev/null +++ b/shopelectro/tests/tests_html.py @@ -0,0 +1,37 @@ +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 +from html5lib import html5parser + + +@tag('fast') +class TemplateTests(TestCase): + + @unittest.skip('should fix html templates') + 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): + filepath = os.path.join( + settings.TEMPLATE_ASSETS_DIR, + 'valid_markup_example.html' + ) + validate(render_to_string(filepath)) + + def test_invalid_example(self): + filepath = os.path.join( + settings.TEMPLATE_ASSETS_DIR, + 'invalid_markup_example.html' + ) + with self.assertRaises(html5parser.ParseError): + validate(render_to_string(filepath))