From 1f6b712cedb9a76d20ddd07c42cc9cc27f7af2b4 Mon Sep 17 00:00:00 2001 From: olegush Date: Sat, 30 Nov 2019 07:01:45 +0300 Subject: [PATCH 1/6] #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 + + + + + + + From 69b522006c303aa3694477c8cdeac7ffa62de753 Mon Sep 17 00:00:00 2001 From: olegush Date: Sun, 1 Dec 2019 08:20:30 +0300 Subject: [PATCH 2/6] #973 Add an html validator --- shopelectro/settings/base.py | 3 ++- shopelectro/tests/tests_html.py | 16 ++++++++++++++-- templates/valid_example.html | 12 ------------ 3 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 templates/valid_example.html 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/tests_html.py b/shopelectro/tests/tests_html.py index c6780934..a55b4f0c 100644 --- a/shopelectro/tests/tests_html.py +++ b/shopelectro/tests/tests_html.py @@ -11,7 +11,7 @@ @tag('fast') class TemplateTests(TestCase): - @unittest.skip + @unittest.skip('should fix html templates') def test_templates(self): for dir, _, filenames in os.walk(settings.TEMPLATE_DIR): for filename in filenames: @@ -21,4 +21,16 @@ def test_templates(self): validate(render_to_string(filepath)) def test_valid_example(self): - validate(render_to_string('/usr/app/src/templates/valid_example.html')) + filepath = os.path.join( + settings.TEMPLATE_ASSETS_DIR, + 'valid_markup_example.html' + ) + validate(render_to_string(filepath)) + + @unittest.expectedFailure + def test_invalid_example(self): + filepath = os.path.join( + settings.TEMPLATE_ASSETS_DIR, + 'invalid_markup_example.html' + ) + validate(render_to_string(filepath)) diff --git a/templates/valid_example.html b/templates/valid_example.html deleted file mode 100644 index cecdf657..00000000 --- a/templates/valid_example.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - - title - - - - - - - From 2b03b2fa2f637b440f9a979c1aaf4b050e6132c0 Mon Sep 17 00:00:00 2001 From: olegush Date: Sun, 1 Dec 2019 08:31:01 +0300 Subject: [PATCH 3/6] #973 change fats tests in drone --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 7cffd042b979215fb81d81ba397898ab26253566 Mon Sep 17 00:00:00 2001 From: olegush Date: Sun, 1 Dec 2019 09:25:10 +0300 Subject: [PATCH 4/6] #973 move html examples --- shopelectro/tests/assets/invalid_markup_example.html | 3 +++ shopelectro/tests/assets/valid_markup_example.html | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 shopelectro/tests/assets/invalid_markup_example.html create mode 100644 shopelectro/tests/assets/valid_markup_example.html 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 + + + + + + + From d267c740bd18b34cbe85ffcb25054d61452ac945 Mon Sep 17 00:00:00 2001 From: olegush Date: Tue, 3 Dec 2019 08:02:43 +0300 Subject: [PATCH 5/6] #973 added assertRaises --- shopelectro/tests/tests_html.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shopelectro/tests/tests_html.py b/shopelectro/tests/tests_html.py index a55b4f0c..3376e27e 100644 --- a/shopelectro/tests/tests_html.py +++ b/shopelectro/tests/tests_html.py @@ -6,6 +6,7 @@ from django.template.loader import render_to_string from html5validate import validate +from html5lib import html5parser @tag('fast') @@ -27,10 +28,11 @@ def test_valid_example(self): ) validate(render_to_string(filepath)) - @unittest.expectedFailure + #@unittest.expectedFailure def test_invalid_example(self): filepath = os.path.join( settings.TEMPLATE_ASSETS_DIR, 'invalid_markup_example.html' ) - validate(render_to_string(filepath)) + with self.assertRaises(html5parser.ParseError): + validate(render_to_string(filepath)) From 3e6d837da1791812aa194b04aacbf59865607ed5 Mon Sep 17 00:00:00 2001 From: olegush Date: Tue, 3 Dec 2019 08:49:00 +0300 Subject: [PATCH 6/6] #973 comment removed --- shopelectro/tests/tests_html.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shopelectro/tests/tests_html.py b/shopelectro/tests/tests_html.py index 3376e27e..31ff18b4 100644 --- a/shopelectro/tests/tests_html.py +++ b/shopelectro/tests/tests_html.py @@ -28,7 +28,6 @@ def test_valid_example(self): ) validate(render_to_string(filepath)) - #@unittest.expectedFailure def test_invalid_example(self): filepath = os.path.join( settings.TEMPLATE_ASSETS_DIR,