Ejemplo n.º 1
0
 def test_break(self):
     """
     Ensures a BREAK token becomes an <hr/> tag.
     """
     token = Token('BREAK', '----')
     result = get_tag(token)
     self.assertEqual('<hr/>', result)
Ejemplo n.º 2
0
 def test_text(self):
     """
     Ensures a TEXT token is correctly parsed into a <p>...</p> tag.
     """
     token = Token('TEXT', 'This is a test')
     result = get_tag(token)
     self.assertEqual('<p class="help-block">This is a test</p>', result)
Ejemplo n.º 3
0
 def test_heading_token_size_too_big(self):
     """
     Ensure a heading token that is too big is parsed correctly to <h6>.
     """
     token = Token('HEADING', 'A header', size=7)
     result = get_tag(token)
     self.assertEqual('<h6>A header</h6>', result)
Ejemplo n.º 4
0
 def test_heading_token_size1(self):
     """
     Ensure a heading token is parsed correctly to <h1>.
     """
     token = Token('HEADING', 'A header', size=1)
     result = get_tag(token)
     self.assertEqual('<h1>A header</h1>', result)
Ejemplo n.º 5
0
 def test_unknown_token_type(self):
     """
     Ensures an unrecognized token is ignored and results in an empty
     string.
     """
     token = Token('FOO', 'bar')
     result = get_tag(token)
     self.assertEqual('', result)
Ejemplo n.º 6
0
 def test_with_unsafe_value(self):
     """
     Ensure the token's value is sanitized to make it HTML safe (to avoid
     the potential for XSS).
     """
     token = Token('HEADING', '<script>alert("hello");</script>', size=1)
     result = get_tag(token)
     self.assertEqual(result,
         '<h1>&lt;script&gt;alert(&#34;hello&#34;);&lt;/script&gt;</h1>')
Ejemplo n.º 7
0
 def test_or_item_with_roles(self):
     """
     Ensures an OR_ITEM with associated roles is parsed correctly.
     """
     token = Token('OR_ITEM', 'Foo', roles=['bar', 'baz'])
     result = get_tag(token, 'name_value')
     expected = ('<label class="radio">' +
         '<input type="radio" name="name_value" value="Foo">' +
         'Foo</input> <span class="roles">(bar, baz)</span></label><br/>')
     self.assertEqual(expected, result)
Ejemplo n.º 8
0
 def test_or_item(self):
     """
     Ensures an OR_ITEM is parsed to a radiobutton.
     """
     token = Token('OR_ITEM', 'Foo')
     result = get_tag(token, 'name_value')
     expected = ('<label class="radio">'+
         '<input type="radio" name="name_value" value="Foo">' +
         'Foo</input> </label><br/>')
     self.assertEqual(expected, result)
Ejemplo n.º 9
0
 def test_and_item(self):
     """
     Ensures an AND_ITEM is parsed to a checkbox.
     """
     token = Token('AND_ITEM', 'Foo')
     result = get_tag(token, 'name_value')
     expected = ('<label class="checkbox">' +
         '<input type="checkbox" name="name_value" value="Foo">' +
         'Foo</input> </label><br/>')
     self.assertEqual(expected, result)
Ejemplo n.º 10
0
 def test_with_unsafe_roles(self):
     """
     Ensure that any roles associated with a token are sanitized to make
     them HTML safe (to avoid the potential for XSS).
     """
     token = Token('AND_ITEM', 'Foo',
         roles=['<script>alert("hello");</script>', 'baz'])
     result = get_tag(token, 'name_value')
     expected = ('<label class="checkbox">' +
         '<input type="checkbox" name="name_value" value="Foo">' +
         'Foo</input> <span class="roles">(&lt;script&gt;' +
         'alert(&#34;hello&#34;);&lt;/script&gt;, baz)</span></label><br/>')
     self.assertEqual(expected, result)