Mercurial > genshi > genshi-test
annotate genshi/filters/tests/html.py @ 909:585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
author | cmlenz |
---|---|
date | Mon, 10 May 2010 15:03:22 +0000 |
parents | 5fd4a1e28351 |
children |
rev | line source |
---|---|
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
2 # |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
3 # Copyright (C) 2006-2009 Edgewall Software |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
4 # All rights reserved. |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
5 # |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
6 # This software is licensed as described in the file COPYING, which |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
7 # you should have received as part of this distribution. The terms |
230 | 8 # are also available at http://genshi.edgewall.org/wiki/License. |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
9 # |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
10 # This software consists of voluntary contributions made by many |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
11 # individuals. For the exact contribution history, see the revision |
230 | 12 # history and logs, available at http://genshi.edgewall.org/log/. |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
13 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
14 import doctest |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
15 import unittest |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
16 |
230 | 17 from genshi.input import HTML, ParseError |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
431
diff
changeset
|
18 from genshi.filters.html import HTMLFormFiller, HTMLSanitizer |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
19 from genshi.template import MarkupTemplate |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
20 |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
21 class HTMLFormFillerTestCase(unittest.TestCase): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
22 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
23 def test_fill_input_text_no_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
24 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
25 <input type="text" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
26 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
27 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
28 <input type="text" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
29 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
30 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
31 def test_fill_input_text_single_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
32 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
33 <input type="text" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
34 </p></form>""") | HTMLFormFiller(data={'foo': 'bar'}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
35 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
36 <input type="text" name="foo" value="bar"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
37 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
38 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
39 def test_fill_input_text_multi_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
40 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
41 <input type="text" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
42 </p></form>""") | HTMLFormFiller(data={'foo': ['bar']}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
43 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
44 <input type="text" name="foo" value="bar"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
45 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
46 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
47 def test_fill_input_hidden_no_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
48 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
49 <input type="hidden" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
50 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
51 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
52 <input type="hidden" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
53 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
54 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
55 def test_fill_input_hidden_single_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
56 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
57 <input type="hidden" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
58 </p></form>""") | HTMLFormFiller(data={'foo': 'bar'}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
59 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
60 <input type="hidden" name="foo" value="bar"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
61 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
62 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
63 def test_fill_input_hidden_multi_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
64 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
65 <input type="hidden" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
66 </p></form>""") | HTMLFormFiller(data={'foo': ['bar']}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
67 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
68 <input type="hidden" name="foo" value="bar"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
69 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
70 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
71 def test_fill_textarea_no_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
72 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
73 <textarea name="foo"></textarea> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
74 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
75 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
76 <textarea name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
77 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
78 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
79 def test_fill_textarea_single_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
80 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
81 <textarea name="foo"></textarea> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
82 </p></form>""") | HTMLFormFiller(data={'foo': 'bar'}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
83 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
84 <textarea name="foo">bar</textarea> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
85 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
86 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
87 def test_fill_textarea_multi_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
88 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
89 <textarea name="foo"></textarea> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
90 </p></form>""") | HTMLFormFiller(data={'foo': ['bar']}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
91 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
92 <textarea name="foo">bar</textarea> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
93 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
94 |
908
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
95 def test_fill_textarea_multiple(self): |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
96 # Ensure that the subsequent textarea doesn't get the data from the |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
97 # first |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
98 html = HTML("""<form><p> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
99 <textarea name="foo"></textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
100 <textarea name="bar"></textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
101 </p></form>""") | HTMLFormFiller(data={'foo': 'Some text'}) |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
102 self.assertEquals("""<form><p> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
103 <textarea name="foo">Some text</textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
104 <textarea name="bar"/> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
105 </p></form>""", html.render()) |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
106 |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
107 def test_fill_textarea_preserve_original(self): |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
108 html = HTML("""<form><p> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
109 <textarea name="foo"></textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
110 <textarea name="bar">Original value</textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
111 </p></form>""") | HTMLFormFiller(data={'foo': 'Some text'}) |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
112 self.assertEquals("""<form><p> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
113 <textarea name="foo">Some text</textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
114 <textarea name="bar">Original value</textarea> |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
115 </p></form>""", html.render()) |
5fd4a1e28351
Fix for bug with the `HTMLFormFiller` in the handling of textareas. Thanks to Trevor Morgan for pointing this out on the mailing list.
cmlenz
parents:
854
diff
changeset
|
116 |
909
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
117 def test_fill_input_checkbox_single_value_auto_no_value(self): |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
118 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
119 <input type="checkbox" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
120 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
121 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
122 <input type="checkbox" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
123 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
124 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
125 def test_fill_input_checkbox_single_value_auto(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
126 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
127 <input type="checkbox" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
128 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
129 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
130 <input type="checkbox" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
131 </p></form>""", (html | HTMLFormFiller(data={'foo': ''})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
132 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
133 <input type="checkbox" name="foo" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
134 </p></form>""", (html | HTMLFormFiller(data={'foo': 'on'})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
135 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
136 def test_fill_input_checkbox_single_value_defined(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
137 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
138 <input type="checkbox" name="foo" value="1" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
139 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
140 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
141 <input type="checkbox" name="foo" value="1" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
142 </p></form>""", (html | HTMLFormFiller(data={'foo': '1'})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
143 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
144 <input type="checkbox" name="foo" value="1"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
145 </p></form>""", (html | HTMLFormFiller(data={'foo': '2'})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
146 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
147 def test_fill_input_checkbox_multi_value_auto(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
148 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
149 <input type="checkbox" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
150 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
151 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
152 <input type="checkbox" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
153 </p></form>""", (html | HTMLFormFiller(data={'foo': []})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
154 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
155 <input type="checkbox" name="foo" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
156 </p></form>""", (html | HTMLFormFiller(data={'foo': ['on']})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
157 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
158 def test_fill_input_checkbox_multi_value_defined(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
159 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
160 <input type="checkbox" name="foo" value="1" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
161 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
162 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
163 <input type="checkbox" name="foo" value="1" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
164 </p></form>""", (html | HTMLFormFiller(data={'foo': ['1']})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
165 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
166 <input type="checkbox" name="foo" value="1"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
167 </p></form>""", (html | HTMLFormFiller(data={'foo': ['2']})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
168 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
169 def test_fill_input_radio_no_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
170 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
171 <input type="radio" name="foo" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
172 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
173 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
174 <input type="radio" name="foo"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
175 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
176 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
177 def test_fill_input_radio_single_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
178 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
179 <input type="radio" name="foo" value="1" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
180 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
181 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
182 <input type="radio" name="foo" value="1" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
183 </p></form>""", (html | HTMLFormFiller(data={'foo': '1'})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
184 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
185 <input type="radio" name="foo" value="1"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
186 </p></form>""", (html | HTMLFormFiller(data={'foo': '2'})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
187 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
188 def test_fill_input_radio_multi_value(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
189 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
190 <input type="radio" name="foo" value="1" /> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
191 </p></form>""") |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
192 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
193 <input type="radio" name="foo" value="1" checked="checked"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
194 </p></form>""", (html | HTMLFormFiller(data={'foo': ['1']})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
195 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
196 <input type="radio" name="foo" value="1"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
197 </p></form>""", (html | HTMLFormFiller(data={'foo': ['2']})).render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
198 |
909
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
199 def test_fill_input_radio_empty_string(self): |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
200 html = HTML("""<form><p> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
201 <input type="radio" name="foo" value="" /> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
202 </p></form>""") |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
203 self.assertEquals("""<form><p> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
204 <input type="radio" name="foo" value="" checked="checked"/> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
205 </p></form>""", (html | HTMLFormFiller(data={'foo': ''})).render()) |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
206 |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
207 def test_fill_input_radio_multi_empty_string(self): |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
208 html = HTML("""<form><p> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
209 <input type="radio" name="foo" value="" /> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
210 </p></form>""") |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
211 self.assertEquals("""<form><p> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
212 <input type="radio" name="foo" value="" checked="checked"/> |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
213 </p></form>""", (html | HTMLFormFiller(data={'foo': ['']})).render()) |
585fdbd30e05
Fix handling of checkboxes and radio buttons with an empty value attribute in `HTMLFormFiller`. Thanks to Benoit Hirbec for pointing out the problem and providing a patch.
cmlenz
parents:
908
diff
changeset
|
214 |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
215 def test_fill_select_no_value_auto(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
216 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
217 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
218 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
219 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
220 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
221 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
222 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
223 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
224 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
225 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
226 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
227 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
228 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
229 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
230 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
231 def test_fill_select_no_value_defined(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
232 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
233 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
234 <option value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
235 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
236 <option value="3">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
237 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
238 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
239 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
240 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
241 <option value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
242 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
243 <option value="3">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
244 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
245 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
246 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
247 def test_fill_select_single_value_auto(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
248 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
249 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
250 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
251 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
252 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
253 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
254 </p></form>""") | HTMLFormFiller(data={'foo': '1'}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
255 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
256 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
257 <option selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
258 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
259 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
260 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
261 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
262 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
263 def test_fill_select_single_value_defined(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
264 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
265 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
266 <option value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
267 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
268 <option value="3">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
269 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
270 </p></form>""") | HTMLFormFiller(data={'foo': '1'}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
271 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
272 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
273 <option value="1" selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
274 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
275 <option value="3">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
276 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
277 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
278 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
279 def test_fill_select_multi_value_auto(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
280 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
281 <select name="foo" multiple> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
282 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
283 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
284 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
285 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
286 </p></form>""") | HTMLFormFiller(data={'foo': ['1', '3']}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
287 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
288 <select name="foo" multiple="multiple"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
289 <option selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
290 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
291 <option selected="selected">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
292 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
293 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
294 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
295 def test_fill_select_multi_value_defined(self): |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
296 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
297 <select name="foo" multiple> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
298 <option value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
299 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
300 <option value="3">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
301 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
302 </p></form>""") | HTMLFormFiller(data={'foo': ['1', '3']}) |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
303 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
304 <select name="foo" multiple="multiple"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
305 <option value="1" selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
306 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
307 <option value="3" selected="selected">3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
308 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
309 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
310 |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
311 def test_fill_option_segmented_text(self): |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
312 html = MarkupTemplate("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
313 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
314 <option value="1">foo $x</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
315 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
316 </form>""").generate(x=1) | HTMLFormFiller(data={'foo': '1'}) |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
317 self.assertEquals("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
318 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
319 <option value="1" selected="selected">foo 1</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
320 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
321 </form>""", html.render()) |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
322 |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
323 def test_fill_option_segmented_text_no_value(self): |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
324 html = MarkupTemplate("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
325 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
326 <option>foo $x bar</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
327 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
328 </form>""").generate(x=1) | HTMLFormFiller(data={'foo': 'foo 1 bar'}) |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
329 self.assertEquals("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
330 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
331 <option selected="selected">foo 1 bar</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
332 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
333 </form>""", html.render()) |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
334 |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
335 def test_fill_option_unicode_value(self): |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
336 html = HTML("""<form> |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
337 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
338 <option value="ö">foo</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
339 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
340 </form>""") | HTMLFormFiller(data={'foo': u'ö'}) |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
341 self.assertEquals(u"""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
342 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
343 <option value="ö" selected="selected">foo</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
344 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
345 </form>""", html.render(encoding=None)) |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
346 |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
347 def test_fill_input_password_disabled(self): |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
348 html = HTML("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
349 <input type="password" name="pass" /> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
350 </p></form>""") | HTMLFormFiller(data={'pass': 'bar'}) |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
351 self.assertEquals("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
352 <input type="password" name="pass"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
353 </p></form>""", html.render()) |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
354 |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
355 def test_fill_input_password_enabled(self): |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
356 html = HTML("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
357 <input type="password" name="pass" /> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
358 </p></form>""") | HTMLFormFiller(data={'pass': '1234'}, passwords=True) |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
359 self.assertEquals("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
360 <input type="password" name="pass" value="1234"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
361 </p></form>""", html.render()) |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
362 |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
363 |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
364 class HTMLSanitizerTestCase(unittest.TestCase): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
365 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
366 def test_sanitize_unchanged(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
367 html = HTML('<a href="#">fo<br />o</a>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
368 self.assertEquals('<a href="#">fo<br/>o</a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
369 (html | HTMLSanitizer()).render()) |
837 | 370 html = HTML('<a href="#with:colon">foo</a>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
371 self.assertEquals('<a href="#with:colon">foo</a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
372 (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
373 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
374 def test_sanitize_escape_text(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
375 html = HTML('<a href="#">fo&</a>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
376 self.assertEquals('<a href="#">fo&</a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
377 (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
378 html = HTML('<a href="#"><foo></a>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
379 self.assertEquals('<a href="#"><foo></a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
380 (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
381 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
382 def test_sanitize_entityref_text(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
383 html = HTML('<a href="#">foö</a>') |
144
28b56f09a7e1
* Coalesce adjacent text events that the parsers would produce when text crossed the buffer boundaries. Fixes #26.
cmlenz
parents:
115
diff
changeset
|
384 self.assertEquals(u'<a href="#">foö</a>', |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
385 (html | HTMLSanitizer()).render(encoding=None)) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
386 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
387 def test_sanitize_escape_attr(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
388 html = HTML('<div title="<foo>"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
389 self.assertEquals('<div title="<foo>"/>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
390 (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
391 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
392 def test_sanitize_close_empty_tag(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
393 html = HTML('<a href="#">fo<br>o</a>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
394 self.assertEquals('<a href="#">fo<br/>o</a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
395 (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
396 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
397 def test_sanitize_invalid_entity(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
398 html = HTML('&junk;') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
399 self.assertEquals('&junk;', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
400 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
401 def test_sanitize_remove_script_elem(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
402 html = HTML('<script>alert("Foo")</script>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
403 self.assertEquals('', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
404 html = HTML('<SCRIPT SRC="http://example.com/"></SCRIPT>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
405 self.assertEquals('', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
406 self.assertRaises(ParseError, HTML, '<SCR\0IPT>alert("foo")</SCR\0IPT>') |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
407 self.assertRaises(ParseError, HTML, |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
408 '<SCRIPT&XYZ SRC="http://example.com/"></SCRIPT>') |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
409 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
410 def test_sanitize_remove_onclick_attr(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
411 html = HTML('<div onclick=\'alert("foo")\' />') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
412 self.assertEquals('<div/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
413 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
414 def test_sanitize_remove_input_password(self): |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
415 html = HTML('<form><input type="password" /></form>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
416 self.assertEquals('<form/>', (html | HTMLSanitizer()).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
417 |
571
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
418 def test_sanitize_remove_comments(self): |
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
419 html = HTML('''<div><!-- conditional comment crap --></div>''') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
420 self.assertEquals('<div/>', (html | HTMLSanitizer()).render()) |
571
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
421 |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
422 def test_sanitize_remove_style_scripts(self): |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
423 sanitizer = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
424 # Inline style with url() using javascript: scheme |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
425 html = HTML('<DIV STYLE=\'background: url(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
426 self.assertEquals('<div/>', (html | sanitizer).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
427 # Inline style with url() using javascript: scheme, using control char |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
428 html = HTML('<DIV STYLE=\'background: url(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
429 self.assertEquals('<div/>', (html | sanitizer).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
430 # Inline style with url() using javascript: scheme, in quotes |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
431 html = HTML('<DIV STYLE=\'background: url("javascript:alert(foo)")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
432 self.assertEquals('<div/>', (html | sanitizer).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
433 # IE expressions in CSS not allowed |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
434 html = HTML('<DIV STYLE=\'width: expression(alert("foo"));\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
435 self.assertEquals('<div/>', (html | sanitizer).render()) |
556
d5cb5c200045
The HTML sanitizer now strips any CSS comments in style attributes, which could previously be used to hide malicious property values.
cmlenz
parents:
446
diff
changeset
|
436 html = HTML('<DIV STYLE=\'width: e/**/xpression(alert("foo"));\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
437 self.assertEquals('<div/>', (html | sanitizer).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
438 html = HTML('<DIV STYLE=\'background: url(javascript:alert("foo"));' |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
439 'color: #fff\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
440 self.assertEquals('<div style="color: #fff"/>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
441 (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
442 # Inline style with url() using javascript: scheme, using unicode |
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
443 # escapes |
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
444 html = HTML('<DIV STYLE=\'background: \\75rl(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
445 self.assertEquals('<div/>', (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
446 html = HTML('<DIV STYLE=\'background: \\000075rl(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
447 self.assertEquals('<div/>', (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
448 html = HTML('<DIV STYLE=\'background: \\75 rl(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
449 self.assertEquals('<div/>', (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
450 html = HTML('<DIV STYLE=\'background: \\000075 rl(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
451 self.assertEquals('<div/>', (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
452 html = HTML('<DIV STYLE=\'background: \\000075\r\nrl(javascript:alert("foo"))\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
453 self.assertEquals('<div/>', (html | sanitizer).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
454 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
455 def test_sanitize_remove_style_phishing(self): |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
456 sanitizer = HTMLSanitizer(safe_attrs=HTMLSanitizer.SAFE_ATTRS | set(['style'])) |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
457 # The position property is not allowed |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
458 html = HTML('<div style="position:absolute;top:0"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
459 self.assertEquals('<div style="top:0"/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
460 # Normal margins get passed through |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
461 html = HTML('<div style="margin:10px 20px"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
462 self.assertEquals('<div style="margin:10px 20px"/>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
463 (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
464 # But not negative margins |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
465 html = HTML('<div style="margin:-1000px 0 0"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
466 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
467 html = HTML('<div style="margin-left:-2000px 0 0"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
468 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
469 html = HTML('<div style="margin-left:1em 1em 1em -4000px"></div>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
470 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
471 |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
472 def test_sanitize_remove_src_javascript(self): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
473 html = HTML('<img src=\'javascript:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
474 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
475 # Case-insensitive protocol matching |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
476 html = HTML('<IMG SRC=\'JaVaScRiPt:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
477 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
478 # Grave accents (not parsed) |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
479 self.assertRaises(ParseError, HTML, |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
480 '<IMG SRC=`javascript:alert("RSnake says, \'foo\'")`>') |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
481 # Protocol encoded using UTF-8 numeric entities |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
482 html = HTML('<IMG SRC=\'javascri' |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
483 'pt:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
484 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
485 # Protocol encoded using UTF-8 numeric entities without a semicolon |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
486 # (which is allowed because the max number of digits is used) |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
487 html = HTML('<IMG SRC=\'java' |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
488 'script' |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
489 ':alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
490 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
491 # Protocol encoded using UTF-8 numeric hex entities without a semicolon |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
492 # (which is allowed because the max number of digits is used) |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
493 html = HTML('<IMG SRC=\'javascri' |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
494 'pt:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
495 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
496 # Embedded tab character in protocol |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
497 html = HTML('<IMG SRC=\'jav\tascript:alert("foo");\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
498 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
499 # Embedded tab character in protocol, but encoded this time |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
500 html = HTML('<IMG SRC=\'jav	ascript:alert("foo");\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
501 self.assertEquals('<img/>', (html | HTMLSanitizer()).render()) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
502 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
503 |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
504 def suite(): |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
505 suite = unittest.TestSuite() |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
431
diff
changeset
|
506 suite.addTest(doctest.DocTestSuite(HTMLFormFiller.__module__)) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
507 suite.addTest(unittest.makeSuite(HTMLFormFillerTestCase, 'test')) |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
508 suite.addTest(unittest.makeSuite(HTMLSanitizerTestCase, 'test')) |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
509 return suite |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
510 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
511 |
113
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
512 if __name__ == '__main__': |
e815c2c07572
Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
cmlenz
parents:
diff
changeset
|
513 unittest.main(defaultTest='suite') |