Mercurial > genshi > genshi-test
annotate genshi/filters/tests/html.py @ 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.
author | cmlenz |
---|---|
date | Mon, 10 May 2010 14:02:55 +0000 |
parents | 0d9e87c6cf6e |
children | 585fdbd30e05 |
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 |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
117 def test_fill_input_checkbox_no_value(self): |
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 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
199 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
|
200 html = HTML("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
201 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
202 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
203 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
204 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
205 </select> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
206 </p></form>""") | HTMLFormFiller() |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
207 self.assertEquals("""<form><p> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
208 <select name="foo"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
209 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
210 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
211 <option>3</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
212 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
213 </p></form>""", html.render()) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
214 |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
215 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
|
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 value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
219 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
220 <option value="3">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 value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
226 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
227 <option value="3">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_single_value_auto(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>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
235 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
236 <option>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(data={'foo': '1'}) |
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 selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
242 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
243 <option>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_defined(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 value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
251 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
252 <option value="3">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 value="1" selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
258 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
259 <option value="3">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_multi_value_auto(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" multiple> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
266 <option>1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
267 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
268 <option>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', '3']}) |
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" multiple="multiple"> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
273 <option selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
274 <option>2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
275 <option selected="selected">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_defined(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 value="1">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
283 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
284 <option value="3">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 value="1" selected="selected">1</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
290 <option value="2">2</option> |
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
291 <option value="3" 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 |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
295 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
|
296 html = MarkupTemplate("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
297 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
298 <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
|
299 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
300 </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
|
301 self.assertEquals("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
302 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
303 <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
|
304 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
305 </form>""", html.render()) |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
306 |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
307 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
|
308 html = MarkupTemplate("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
309 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
310 <option>foo $x bar</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
311 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
312 </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
|
313 self.assertEquals("""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
314 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
315 <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
|
316 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
317 </form>""", html.render()) |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
318 |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
319 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
|
320 html = HTML("""<form> |
584
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
321 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
322 <option value="ö">foo</option> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
323 </select> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
324 </form>""") | HTMLFormFiller(data={'foo': u'ö'}) |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
325 self.assertEquals(u"""<form> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
326 <select name="foo"> |
84137a71a4ca
Fixed a few cases where HTMLFormFiller didn't work well with option elements:
jonas
parents:
571
diff
changeset
|
327 <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
|
328 </select> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
329 </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
|
330 |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
331 def test_fill_input_password_disabled(self): |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
332 html = HTML("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
333 <input type="password" name="pass" /> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
334 </p></form>""") | HTMLFormFiller(data={'pass': 'bar'}) |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
335 self.assertEquals("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
336 <input type="password" name="pass"/> |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
337 </p></form>""", html.render()) |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
338 |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
339 def test_fill_input_password_enabled(self): |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
340 html = HTML("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
341 <input type="password" name="pass" /> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
342 </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
|
343 self.assertEquals("""<form><p> |
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
344 <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
|
345 </p></form>""", html.render()) |
841
67ec9a402bdc
Added an option to the `HTMLFiller` to also populate password fields.
cmlenz
parents:
840
diff
changeset
|
346 |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
347 |
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
|
348 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
|
349 |
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
|
350 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
|
351 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
|
352 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
|
353 (html | HTMLSanitizer()).render()) |
837 | 354 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
|
355 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
|
356 (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
|
357 |
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
|
358 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
|
359 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
|
360 self.assertEquals('<a href="#">fo&</a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
361 (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
|
362 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
|
363 self.assertEquals('<a href="#"><foo></a>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
364 (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
|
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_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
|
367 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
|
368 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
|
369 (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
|
370 |
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
|
371 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
|
372 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
|
373 self.assertEquals('<div title="<foo>"/>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
374 (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
|
375 |
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
|
376 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
|
377 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
|
378 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
|
379 (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
|
380 |
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 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
|
382 html = HTML('&junk;') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
383 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
|
384 |
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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 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
|
392 '<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
|
393 |
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
|
394 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
|
395 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
|
396 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
|
397 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
398 def test_sanitize_remove_input_password(self): |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
399 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
|
400 self.assertEquals('<form/>', (html | HTMLSanitizer()).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
401 |
571
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
402 def test_sanitize_remove_comments(self): |
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
403 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
|
404 self.assertEquals('<div/>', (html | HTMLSanitizer()).render()) |
571
5815ad5f75a4
* Cleaned up the implementation of the `HTMLSanitizer`.
cmlenz
parents:
556
diff
changeset
|
405 |
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 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
|
407 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
|
408 # 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
|
409 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
|
410 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
|
411 # 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
|
412 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
|
413 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
|
414 # 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
|
415 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
|
416 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
|
417 # 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 'color: #fff\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
424 self.assertEquals('<div style="color: #fff"/>', |
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
425 (html | sanitizer).render()) |
431
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
426 # 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
|
427 # escapes |
747baa1cd597
* Don't allow `style` attributes by default in the `HTMLSanitizer`. Closes #97.
cmlenz
parents:
363
diff
changeset
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
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 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
439 def test_sanitize_remove_style_phishing(self): |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
440 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
|
441 # The position property is not allowed |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
442 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
|
443 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
|
444 # Normal margins get passed through |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
445 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
|
446 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
|
447 (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
448 # But not negative margins |
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
449 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
|
450 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
451 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
|
452 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
453 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
|
454 self.assertEquals('<div/>', (html | sanitizer).render()) |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
455 |
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
|
456 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
|
457 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
|
458 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
|
459 # 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
|
460 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
|
461 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
|
462 # 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
|
463 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
|
464 '<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
|
465 # 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
|
466 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
|
467 'pt:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
468 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
|
469 # 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
|
470 # (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
|
471 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
|
472 '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
|
473 ':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 # 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
|
476 # (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
|
477 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
|
478 'pt:alert("foo")\'>') |
854
0d9e87c6cf6e
More work on reducing the size of the diff produced by 2to3.
cmlenz
parents:
841
diff
changeset
|
479 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
|
480 # 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
|
481 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
|
482 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
|
483 # 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
|
484 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
|
485 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
|
486 |
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 |
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 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
|
489 suite = unittest.TestSuite() |
446
90f5908cd10a
Add basic I18n/L10n functionality, based on GenshiRecipes/Localization.
cmlenz
parents:
431
diff
changeset
|
490 suite.addTest(doctest.DocTestSuite(HTMLFormFiller.__module__)) |
275
7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
cmlenz
parents:
258
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 |
840
878306a5b465
Ported some of the HTML sanitization improvements from Trac (see [T7658]).
cmlenz
parents:
837
diff
changeset
|
495 |
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 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
|
497 unittest.main(defaultTest='suite') |