Merge pull request #1223 from BuhtigithuB/add-missing-helpers-test
Add missing helpers test
This commit is contained in:
@@ -12,6 +12,7 @@ fix_sys_path(__file__)
|
||||
|
||||
from html import *
|
||||
from html import verifyURL
|
||||
from html import truncate_string
|
||||
from storage import Storage
|
||||
|
||||
|
||||
@@ -19,8 +20,15 @@ class TestBareHelpers(unittest.TestCase):
|
||||
|
||||
# TODO: def test_xmlescape(self):
|
||||
# TODO: def test_call_as_list(self):
|
||||
# TODO: def test_truncate_string(self):
|
||||
# TODO: def test_truncate_string(self):
|
||||
|
||||
def test_truncate_string(self):
|
||||
# Ascii text
|
||||
self.assertEqual(truncate_string('Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
|
||||
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
|
||||
length=30), 'Lorem ipsum dolor sit amet,...')
|
||||
# French text
|
||||
self.assertEqual(truncate_string('Un texte en français avec des accents et des caractères bizarre.', length=30),
|
||||
'Un texte en français avec d...')
|
||||
|
||||
def test_StaticURL(self):
|
||||
# test response.static_version coupled with response.static_version_urls
|
||||
@@ -34,7 +42,7 @@ class TestBareHelpers(unittest.TestCase):
|
||||
response.static_version_urls = True
|
||||
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css')
|
||||
|
||||
def testURL(self):
|
||||
def test_URL(self):
|
||||
self.assertEqual(URL('a', 'c', 'f', args='1'), '/a/c/f/1')
|
||||
self.assertEqual(URL('a', 'c', 'f', args=('1', '2')), '/a/c/f/1/2')
|
||||
self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2')
|
||||
@@ -63,17 +71,13 @@ class TestBareHelpers(unittest.TestCase):
|
||||
self.assertEqual(URL('a', 'c', weird), '/a/c/weird')
|
||||
self.assertRaises(SyntaxError, URL, *['a', 'c', 1])
|
||||
# test signature
|
||||
rtn = URL(
|
||||
a='a', c='c', f='f', args=['x', 'y', 'z'],
|
||||
vars={'p': (1, 3), 'q': 2}, anchor='1', hmac_key='key'
|
||||
)
|
||||
rtn = URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
|
||||
vars={'p': (1, 3), 'q': 2}, anchor='1', hmac_key='key')
|
||||
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f#1')
|
||||
# test _signature exclusion
|
||||
rtn = URL(
|
||||
a='a', c='c', f='f', args=['x', 'y', 'z'],
|
||||
vars={'p': (1, 3), 'q': 2, '_signature': 'abc'},
|
||||
anchor='1', hmac_key='key'
|
||||
)
|
||||
rtn = URL(a='a', c='c', f='f', args=['x', 'y', 'z'],
|
||||
vars={'p': (1, 3), 'q': 2, '_signature': 'abc'},
|
||||
anchor='1', hmac_key='key')
|
||||
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f#1')
|
||||
# emulate user_signature
|
||||
current.session = Storage(auth=Storage(hmac_key='key'))
|
||||
@@ -220,7 +224,13 @@ class TestBareHelpers(unittest.TestCase):
|
||||
self.assertEqual(HTML('<>', _a='1', _b='2').xml(),
|
||||
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html a="1" b="2" lang="en"><></html>')
|
||||
|
||||
# TODO: def test_XHTML(self):
|
||||
def test_XHTML(self):
|
||||
# Empty XHTML test
|
||||
self.assertEqual(XHTML().xml(),
|
||||
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"></html>')
|
||||
# Not Empty XHTML test
|
||||
self.assertEqual(XHTML('<>', _a='1', _b='2').xml(),
|
||||
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html a="1" b="2" lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"><></html>')
|
||||
|
||||
def test_HEAD(self):
|
||||
self.assertEqual(HEAD('<>', _a='1', _b='2').xml(),
|
||||
@@ -435,9 +445,23 @@ class TestBareHelpers(unittest.TestCase):
|
||||
self.assertEqual(TFOOT('<>', _a='1', _b='2').xml(),
|
||||
'<tfoot a="1" b="2"><tr><td><></td></tr></tfoot>')
|
||||
|
||||
# TODO: def test_COL(self):
|
||||
def test_COL(self):
|
||||
# Empty COL test
|
||||
self.assertEqual(COL().xml(), '<col />')
|
||||
# Not Empty COL test
|
||||
self.assertEqual(COL(_span='2').xml(), '<col span="2" />')
|
||||
# Commented for now not so sure how to make it pass properly was passing locally
|
||||
# I think this test is interesting and add value
|
||||
# Failing COL test
|
||||
# with self.assertRaises(SyntaxError) as cm:
|
||||
# COL('<>').xml()
|
||||
# self.assertEqual(cm.exception[0], '<col/> tags cannot have components')
|
||||
|
||||
# TODO: def test_COLGROUP(self):
|
||||
def test_COLGROUP(self):
|
||||
# Empty COLGROUP test
|
||||
self.assertEqual(COLGROUP().xml(), '<colgroup></colgroup>')
|
||||
# Not Empty COLGROUP test
|
||||
self.assertEqual(COLGROUP('<>', _a='1', _b='2').xml(), '<colgroup a="1" b="2"><></colgroup>')
|
||||
|
||||
def test_TABLE(self):
|
||||
self.assertEqual(TABLE('<>', _a='1', _b='2').xml(),
|
||||
@@ -474,7 +498,13 @@ class TestBareHelpers(unittest.TestCase):
|
||||
self.assertEqual(OBJECT('<>', _a='1', _b='2').xml(),
|
||||
'<object a="1" b="2"><></object>')
|
||||
|
||||
# TODO: def test_OPTGROUP(self):
|
||||
def test_OPTGROUP(self):
|
||||
# Empty OPTGROUP test
|
||||
self.assertEqual(OPTGROUP().xml(),
|
||||
'<optgroup></optgroup>')
|
||||
# Not Empty OPTGROUP test
|
||||
self.assertEqual(OPTGROUP('<>', _a='1', _b='2').xml(),
|
||||
'<optgroup a="1" b="2"><option value="<>"><></option></optgroup>')
|
||||
|
||||
def test_SELECT(self):
|
||||
self.assertEqual(SELECT('<>', _a='1', _b='2').xml(),
|
||||
@@ -485,7 +515,9 @@ class TestBareHelpers(unittest.TestCase):
|
||||
self.assertEqual(FIELDSET('<>', _a='1', _b='2').xml(),
|
||||
'<fieldset a="1" b="2"><></fieldset>')
|
||||
|
||||
# TODO: def test_LEGEND(self):
|
||||
def test_LEGEND(self):
|
||||
self.assertEqual(LEGEND('<>', _a='1', _b='2').xml(),
|
||||
'<legend a="1" b="2"><></legend>')
|
||||
|
||||
def test_FORM(self):
|
||||
self.assertEqual(FORM('<>', _a='1', _b='2').xml(),
|
||||
|
||||
Reference in New Issue
Block a user