-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#973 Add an html validator #1020
base: master
Are you sure you want to change the base?
Changes from all commits
1f6b712
69b5220
2b03b2f
7cffd04
d267c74
3e6d837
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<html> | ||
<body> | ||
<funny>joke</funny> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>title</title> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src="script.js"></script> | ||
</head> | ||
<body> | ||
<!-- page content --> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need PDD subtask there to fix every html file in templates |
||
def test_templates(self): | ||
for dir, _, filenames in os.walk(settings.TEMPLATE_DIR): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you mean TEMPLATE_ASSETS_DIR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @olegush , y, i meant it, sorry |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you also should test not valid html |
||
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
11