#!/bin/python
# -*- coding: utf-8 -*-
"""
Unit tests for gluon.html
"""
import unittest
from fix_path import fix_sys_path
fix_sys_path(__file__)
from html import *
from html import verifyURL
from html import truncate_string
from storage import Storage
from html import XML_pickle, XML_unpickle
from html import TAG_pickler, TAG_unpickler
class TestBareHelpers(unittest.TestCase):
# xmlescape() = covered by other tests
# TODO: def test_call_as_list(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,...')
self.assertEqual(truncate_string('Short text shorter than the length parameter.', length=100),
'Short text shorter than the length parameter.')
# 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
self.assertEqual(URL('a', 'c', 'f'), '/a/c/f')
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response = Storage()
response.static_version = '1.2.3'
from globals import current
current.response = response
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response.static_version_urls = True
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css')
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')
self.assertEqual(URL('a', 'c', '/f'), '/a/c/f')
self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json')
self.assertRaises(SyntaxError, URL, *['a'])
request = Storage()
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.env = {}
from globals import current # Can't be moved with other import
current.request = request
must_return = '/a/c/f'
self.assertEqual(URL(), must_return)
self.assertEqual(URL('f'), must_return)
self.assertEqual(URL('c', 'f'), must_return)
self.assertEqual(URL('a', 'c', 'f'), must_return)
self.assertEqual(URL('a', 'c', 'f', extension='json'), '/a/c/f.json')
def weird():
pass
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')
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')
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'))
self.assertEqual(URL(user_signature=True), '/a/c/f?_signature=c4aed53c08cff08f369dbf8b5ba51889430cf2c2')
# hash_vars combination
rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key')
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f')
rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=True)
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=a32530f0d0caa80964bb92aad2bedf8a4486a31f')
rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=False)
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=0b5a0702039992aad23c82794b8496e5dcd59a5b')
rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars=['p'])
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=5d01b982fd72b39674b012e0288071034e156d7a')
rtn = URL('a', 'c', 'f', args=['x', 'y', 'z'], vars={'p': (1, 3), 'q': 2}, hmac_key='key', hash_vars='p')
self.assertEqual(rtn, '/a/c/f/x/y/z?p=1&p=3&q=2&_signature=5d01b982fd72b39674b012e0288071034e156d7a')
# test CRLF detection
self.assertRaises(SyntaxError, URL, *['a\n', 'c', 'f'])
self.assertRaises(SyntaxError, URL, *['a\r', 'c', 'f'])
def test_verifyURL(self):
r = Storage()
r.application = 'a'
r.controller = 'c'
r.function = 'f'
r.extension = 'html'
r.env = {}
r.get_vars = Storage()
# missing signature as request.get_vars returns False
rtn = verifyURL(r, 'key')
self.assertEqual(rtn, False)
# reverse tests from previous testcase with hash_vars combinations
r.args = ['x', 'y', 'z']
r.get_vars = Storage(p=(1, 3), q=2)
# add signature
r.get_vars['_signature'] = 'a32530f0d0caa80964bb92aad2bedf8a4486a31f'
rtn = verifyURL(r, 'key')
self.assertEqual(rtn, True)
r.get_vars['_signature'] = 'a32530f0d0caa80964bb92aad2bedf8a4486a31f'
rtn = verifyURL(r, 'key', hash_vars=True)
self.assertEqual(rtn, True)
r.get_vars['_signature'] = '0b5a0702039992aad23c82794b8496e5dcd59a5b'
rtn = verifyURL(r, 'key', hash_vars=False)
self.assertEqual(rtn, True)
r.get_vars['_signature'] = '5d01b982fd72b39674b012e0288071034e156d7a'
rtn = verifyURL(r, 'key', hash_vars=['p'])
self.assertEqual(rtn, True)
r.get_vars['_signature'] = '5d01b982fd72b39674b012e0288071034e156d7a'
rtn = verifyURL(r, 'key', hash_vars='p')
self.assertEqual(rtn, True)
# without session, user_signature returns always False
rtn = verifyURL(r, user_signature=True)
self.assertEqual(rtn, False)
# same goes if you don't use an hmac_key
rtn = verifyURL(r)
self.assertEqual(rtn, False)
# emulate user signature
from globals import current
current.session = Storage(auth=Storage(hmac_key='key'))
r.get_vars['_signature'] = 'a32530f0d0caa80964bb92aad2bedf8a4486a31f'
rtn = verifyURL(r, user_signature=True)
self.assertEqual(rtn, True)
# TODO: def test_XmlComponent(self):
def test_XML(self):
# sanitization process
self.assertEqual(XML('
').xml(),
'')
# with sanitize, data-attributes are not permitted
self.assertEqual(XML('', sanitize=True).xml(),
'HelloWorld ')
# stringify by default
self.assertEqual(XML(1.3), '1.3')
self.assertEqual(XML(u'è
').xml(), '\xc3\xa8
')
# you can calc len on the class, that equals the xml() and the str()
self.assertEqual(len(XML('1.3')), len('1.3'))
self.assertEqual(len(XML('1.3').xml()), len('1.3'))
self.assertEqual(len(str(XML('1.3'))), len('1.3'))
# you can concatenate them to strings (check for __add__ and __radd__ methods)
self.assertEqual(XML('a') + 'b', 'ab')
self.assertEqual(XML('a') + XML('b'), 'ab')
self.assertEqual('a' + XML('b'), 'ab')
# you can compare them
self.assertEqual(XML('a') == XML('a'), True)
# beware that the comparison is made on the XML repr
self.assertEqual(XML('', sanitize=True),
XML('HelloWorld '))
# bug check for the sanitizer for closing no-close tags
self.assertEqual(XML('Test
Test
', sanitize=True),
XML('Test
Test
'))
def test_XML_pickle_unpickle(self):
# weird test
self.assertEqual(XML_unpickle(XML_pickle('data to be pickle')[1][0]), 'data to be pickle')
def test_DIV(self):
# Empty DIV()
self.assertEqual(DIV().xml(), '
')
self.assertEqual(DIV('<>', _a='1', _b='2').xml(),
'<>
')
# attributes can be updated like in a dict
div = DIV('<>', _a='1')
div['_b'] = '2'
self.assertEqual(div.xml(),
'<>
')
# also with a mapping
div.update(_b=2, _c=3)
self.assertEqual(div.xml(),
'<>
')
# length of the DIV is the number of components
self.assertEqual(len(DIV('a', 'bc')), 2)
# also if empty, DIV is True in a boolean evaluation
self.assertTrue(True if DIV() else False)
# parent and siblings
a = DIV(SPAN('a'), DIV('b'))
s = a.element('span')
d = s.parent
d['_class'] = 'abc'
self.assertEqual(a.xml(), '')
self.assertEqual([el.xml() for el in s.siblings()], ['b
'])
self.assertEqual(s.sibling().xml(), 'b
')
# siblings with wrong args
self.assertEqual(s.siblings('a'), [])
# siblings with good args
self.assertEqual(s.siblings('div')[0].xml(), 'b
')
# Check for siblings with wrong kargs and value
self.assertEqual(s.siblings(a='d'), [])
# Check for siblings with good kargs and value
# Can't figure this one out what is a right value here??
# Commented for now...
# self.assertEqual(s.siblings(div='b
'), ???)
# No other sibling should return None
self.assertEqual(DIV(P('First element')).element('p').sibling(), None)
# --------------------------------------------------------------------------------------------------------------
# This use unicode to hit xmlescape() line :
# """
# elif isinstance(data, unicode):
# data = data.encode('utf8', 'xmlcharrefreplace')
# """
self.assertEqual(DIV(u'Texte en français avec des caractères accentués...').xml(),
'Texte en fran\xc3\xa7ais avec des caract\xc3\xa8res accentu\xc3\xa9s...
')
# --------------------------------------------------------------------------------------------------------------
self.assertEqual(DIV('Test with an ID', _id='id-of-the-element').xml(),
'Test with an ID
')
self.assertEqual(DIV().element('p'), None)
# Corner case for raise coverage of one line
# I think such assert fail cause of python 2.6
# Work under python 2.7
# with self.assertRaises(SyntaxError) as cm:
# DIV(BR('<>')).xml()
# self.assertEqual(cm.exception[0], ' tags cannot have components')
def test_CAT(self):
# Empty CAT()
self.assertEqual(CAT().xml(), '')
# CAT('')
self.assertEqual(CAT('').xml(), '')
# CAT(' ')
self.assertEqual(CAT(' ').xml(), ' ')
def test_TAG_pickler_unpickler(self):
# weird test
self.assertEqual(TAG_unpickler(TAG_pickler(TAG.div('data to be pickle'))[1][0]).xml(),
'data to be pickle
')
def test_TAG(self):
self.assertEqual(TAG.first(TAG.second('test'), _key=3).xml(),
'test ')
# ending in underscore "triggers" style
self.assertEqual(TAG.first_(TAG.second('test'), _key=3).xml(),
' ')
# unicode test for TAG
self.assertEqual(TAG.div(u'Texte en français avec des caractères accentués...').xml(),
'Texte en fran\xc3\xa7ais avec des caract\xc3\xa8res accentu\xc3\xa9s...
')
def test_HTML(self):
self.assertEqual(HTML('<>', _a='1', _b='2').xml(),
'\n<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='strict').xml(),
'\n<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='transitional').xml(),
'\n<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='frameset').xml(),
'\n<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='html5').xml(),
'\n<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='').xml(),
'<>')
self.assertEqual(HTML('<>', _a='1', _b='2', doctype='CustomDocType').xml(),
'CustomDocType\n<>')
def test_XHTML(self):
# Empty XHTML test
self.assertEqual(XHTML().xml(),
'\n')
# Not Empty XHTML test
self.assertEqual(XHTML('<>', _a='1', _b='2').xml(),
'\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', doctype='').xml(),
'\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', doctype='strict').xml(),
'\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', doctype='transitional').xml(),
'\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', doctype='frameset').xml(),
'\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', doctype='xmlns').xml(),
'xmlns\n<>')
self.assertEqual(XHTML('<>', _a='1', _b='2', _xmlns='xmlns').xml(),
'\n<>')
def test_HEAD(self):
self.assertEqual(HEAD('<>', _a='1', _b='2').xml(),
'<>')
def test_TITLE(self):
self.assertEqual(TITLE('<>', _a='1', _b='2').xml(),
'<> ')
def test_META(self):
self.assertEqual(META(_a='1', _b='2').xml(),
' ')
def test_LINK(self):
self.assertEqual(LINK(_a='1', _b='2').xml(),
' ')
def test_SCRIPT(self):
self.assertEqual(SCRIPT('<>', _a='1', _b='2').xml(),
'''''')
self.assertEqual(SCRIPT('<>').xml(),
'''''')
self.assertEqual(SCRIPT().xml(), '')
def test_STYLE(self):
self.assertEqual(STYLE('<>', _a='1', _b='2').xml(),
'')
# Try to hit : return DIV.xml(self)
self.assertEqual(STYLE().xml(), '')
def test_IMG(self):
self.assertEqual(IMG(_a='1', _b='2').xml(),
' ')
def test_SPAN(self):
self.assertEqual(SPAN('<>', _a='1', _b='2').xml(),
'<> ')
def test_BODY(self):
self.assertEqual(BODY('<>', _a='1', _b='2').xml(),
'<>')
def test_H1(self):
self.assertEqual(H1('<>', _a='1', _b='2').xml(),
'<> ')
def test_H2(self):
self.assertEqual(H2('<>', _a='1', _b='2').xml(),
'<> ')
def test_H3(self):
self.assertEqual(H3('<>', _a='1', _b='2').xml(),
'<> ')
def test_H4(self):
self.assertEqual(H4('<>', _a='1', _b='2').xml(),
'<> ')
def test_H5(self):
self.assertEqual(H5('<>', _a='1', _b='2').xml(),
'<> ')
def test_H6(self):
self.assertEqual(H6('<>', _a='1', _b='2').xml(),
'<> ')
def test_P(self):
self.assertEqual(P('<>', _a='1', _b='2').xml(),
'<>
')
# test cr2br
self.assertEqual(P('a\nb').xml(), 'a\nb
')
self.assertEqual(P('a\nb', cr2br=True).xml(), 'a b
')
def test_STRONG(self):
self.assertEqual(STRONG('<>', _a='1', _b='2').xml(),
'<> ')
def test_B(self):
self.assertEqual(B('<>', _a='1', _b='2').xml(),
'<> ')
def test_BR(self):
# empty BR()
self.assertEqual(BR().xml(), ' ')
self.assertEqual(BR(_a='1', _b='2').xml(), ' ')
def test_HR(self):
self.assertEqual(HR(_a='1', _b='2').xml(), ' ')
def test_A(self):
self.assertEqual(
A('<>', _a='1', _b='2').xml(),
'<> '
)
self.assertEqual(
A('a', cid='b').xml(),
'a '
)
self.assertEqual(
A('a', callback='b', _id='c').xml(),
'a '
)
# Callback with no id trigger web2py_uuid() call
from html import web2pyHTMLParser
a = A('a', callback='b').xml()
for tag in web2pyHTMLParser(a).tree.elements('a'):
uuid_generated = tag.attributes['_id']
self.assertEqual(a,
'a '.format(id=uuid_generated))
self.assertEqual(
A('a', delete='tr').xml(),
'a '
)
self.assertEqual(
A('a', _id='b', target='').xml(),
'a '
)
self.assertEqual(
A('a', component='b').xml(),
'a '
)
self.assertEqual(
A('a', _id='b', callback='c', noconfirm=True).xml(),
'a '
)
self.assertEqual(
A('a', cid='b').xml(),
'a '
)
self.assertEqual(
A('a', cid='b', _disable_with='processing...').xml(),
'a '
)
self.assertEqual(
A('a', callback='b', delete='tr', noconfirm=True, _id='c').xml(),
'a '
)
self.assertEqual(
A('a', callback='b', delete='tr', confirm='Are you sure?', _id='c').xml(),
'a '
)
def test_BUTTON(self):
self.assertEqual(BUTTON('test', _type='button').xml(),
'test ')
def test_EM(self):
self.assertEqual(EM('<>', _a='1', _b='2').xml(),
'<> ')
def test_EMBED(self):
self.assertEqual(EMBED(_a='1', _b='2').xml(),
' ')
def test_TT(self):
self.assertEqual(TT('<>', _a='1', _b='2').xml(),
'<> ')
def test_PRE(self):
self.assertEqual(PRE('<>', _a='1', _b='2').xml(),
'<> ')
def test_CENTER(self):
self.assertEqual(CENTER('<>', _a='1', _b='2').xml(),
'<> ')
def test_CODE(self):
self.assertEqual(CODE("print 'hello world'",
language='python',
link=None,
counter=1,
styles={},
highlight_line=None).xml(),
'')
def test_LABEL(self):
self.assertEqual(LABEL('<>', _a='1', _b='2').xml(),
'<> ')
def test_LI(self):
self.assertEqual(LI('<>', _a='1', _b='2').xml(),
'<> ')
def test_UL(self):
self.assertEqual(UL('<>', _a='1', _b='2').xml(),
'')
def test_OL(self):
self.assertEqual(OL('<>', _a='1', _b='2').xml(),
'<> ')
def test_TD(self):
self.assertEqual(TD('<>', _a='1', _b='2').xml(),
'<> ')
def test_TH(self):
self.assertEqual(TH('<>', _a='1', _b='2').xml(),
'<> ')
def test_TR(self):
self.assertEqual(TR('<>', _a='1', _b='2').xml(),
'<> ')
def test_THEAD(self):
self.assertEqual(THEAD('<>', _a='1', _b='2').xml(),
'<> ')
# self.assertEqual(THEAD(TRHEAD('<>'), _a='1', _b='2').xml(),
# '<> ')
self.assertEqual(THEAD(TR('<>'), _a='1', _b='2').xml(),
'<> ')
def test_TBODY(self):
self.assertEqual(TBODY('<>', _a='1', _b='2').xml(),
'<> ')
def test_TFOOT(self):
self.assertEqual(TFOOT('<>', _a='1', _b='2').xml(),
'<> ')
def test_COL(self):
# Empty COL test
self.assertEqual(COL().xml(), ' ')
# Not Empty COL test
self.assertEqual(COL(_span='2').xml(), ' ')
# Commented for now not so sure how to make it pass properly was passing locally
# I think this test is interesting and add value
# This fail relate to python 2.6 limitation I think
# Failing COL test
# with self.assertRaises(SyntaxError) as cm:
# COL('<>').xml()
# self.assertEqual(cm.exception[0], ' tags cannot have components')
# For now
self.assertRaises(SyntaxError, COL, '<>')
def test_COLGROUP(self):
# Empty COLGROUP test
self.assertEqual(COLGROUP().xml(), ' ')
# Not Empty COLGROUP test
self.assertEqual(COLGROUP('<>', _a='1', _b='2').xml(), '<> ')
def test_TABLE(self):
self.assertEqual(TABLE('<>', _a='1', _b='2').xml(),
'')
def test_I(self):
self.assertEqual(I('<>', _a='1', _b='2').xml(),
'<> ')
def test_IFRAME(self):
self.assertEqual(IFRAME('<>', _a='1', _b='2').xml(),
'')
def test_INPUT(self):
self.assertEqual(INPUT(_a='1', _b='2').xml(), ' ')
# list value
self.assertEqual(INPUT(_value=[1, 2, 3]).xml(), ' ')
def test_TEXTAREA(self):
self.assertEqual(TEXTAREA('<>', _a='1', _b='2').xml(),
'')
# override _rows and _cols
self.assertEqual(TEXTAREA('<>', _a='1', _b='2', _rows=5, _cols=20).xml(),
'')
self.assertEqual(TEXTAREA('<>', value='bla bla bla...', _rows=10, _cols=40).xml(),
'')
def test_OPTION(self):
self.assertEqual(OPTION('<>', _a='1', _b='2').xml(),
'<>' +
' ')
def test_OBJECT(self):
self.assertEqual(OBJECT('<>', _a='1', _b='2').xml(),
'<> ')
def test_OPTGROUP(self):
# Empty OPTGROUP test
self.assertEqual(OPTGROUP().xml(),
' ')
# Not Empty OPTGROUP test
self.assertEqual(OPTGROUP('<>', _a='1', _b='2').xml(),
'<> ')
# With an OPTION
self.assertEqual(OPTGROUP(OPTION('Option 1', _value='1'), _label='Group 1').xml(),
'Option 1 ')
def test_SELECT(self):
self.assertEqual(SELECT('<>', _a='1', _b='2').xml(),
'' +
'<> ')
self.assertEqual(SELECT(OPTION('option 1', _value='1'),
OPTION('option 2', _value='2')).xml(),
'option 1 option 2 ')
self.assertEqual(SELECT(OPTION('option 1', _value='1', _selected='selected'),
OPTION('option 2', _value='2'),
_multiple='multiple').xml(),
'option 1 option 2 ')
# More then one select with mutilple
self.assertEqual(SELECT(OPTION('option 1', _value='1', _selected='selected'),
OPTION('option 2', _value='2', _selected='selected'),
_multiple='multiple').xml(),
'option 1 option 2 '
)
# OPTGROUP
self.assertEqual(SELECT(OPTGROUP(OPTION('option 1', _value='1'),
OPTION('option 2', _value='2'),
_label='Group 1',)).xml(),
'option 1 option 2 ')
# List
self.assertEqual(SELECT([1, 2, 3, 4, 5]).xml(),
'1 2 3 4 5 ')
# Tuple
self.assertEqual(SELECT((1, 2, 3, 4, 5)).xml(),
'1 2 3 4 5 ')
# String value
self.assertEqual(SELECT('Option 1', 'Option 2').xml(),
'Option 1 Option 2 ')
# list as a value
self.assertEqual(SELECT(OPTION('option 1', _value=[1, 2, 3]),
OPTION('option 2', _value=[4, 5, 6], _selected='selected'),
_multiple='multiple').xml(),
'option 1 option 2 ')
def test_FIELDSET(self):
self.assertEqual(FIELDSET('<>', _a='1', _b='2').xml(),
'<> ')
def test_LEGEND(self):
self.assertEqual(LEGEND('<>', _a='1', _b='2').xml(),
'<> ')
def test_FORM(self):
self.assertEqual(FORM('<>', _a='1', _b='2').xml(),
'')
# These 2 crash AppVeyor and Travis with: "ImportError: No YAML serializer available"
# self.assertEqual(FORM('<>', _a='1', _b='2').as_yaml(),
# "accepted: null\nattributes: {_a: '1', _action: '#', _b: '2', _enctype: multipart/form-data, _method: post}\ncomponents: [<>]\nerrors: {}\nlatest: {}\nparent: null\nvars: {}\n")
# self.assertEqual(FORM('<>', _a='1', _b='2').as_xml(),
# 'None <_enctype>multipart/form-data<_action>#<_b>2<_a>1<_method>post - <>
None ')
def test_BEAUTIFY(self):
self.assertEqual(BEAUTIFY(['a', 'b', {'hello': 'world'}]).xml(),
'')
# unicode
self.assertEqual(BEAUTIFY([P(u'àéèûôç'), 'a', 'b', {'hello': 'world'}]).xml(),
'\xc3\xa0\xc3\xa9\xc3\xa8\xc3\xbb\xc3\xb4\xc3\xa7
a
b
')
def test_MENU(self):
self.assertEqual(MENU([('Home', False, '/welcome/default/index', [])]).xml(),
'')
# Multiples entries menu
self.assertEqual(MENU([('Home', False, '/welcome/default/index', []),
('Item 1', False, '/welcome/default/func_one', []),
('Item 2', False, '/welcome/default/func_two', []),
('Item 3', False, '/welcome/default/func_three', []),
('Item 4', False, '/welcome/default/func_four', [])]).xml(),
''
)
# mobile=True
self.assertEqual(MENU([('Home', False, '/welcome/default/index', [])], mobile=True).xml(),
'')
# Multiples entries menu for mobile
self.assertEqual(MENU([('Home', False, '/welcome/default/index', []),
('Item 1', False, '/welcome/default/func_one', []),
('Item 2', False, '/welcome/default/func_two', []),
('Item 3', False, '/welcome/default/func_three', []),
('Item 4', False, '/welcome/default/func_four', [])], mobile=True).xml(),
'')
# TODO: def test_embed64(self):
# TODO: def test_web2pyHTMLParser(self):
# TODO: def test_markdown_serializer(self):
# TODO: def test_markmin_serializer(self):
def test_MARKMIN(self):
# This test pass with python 2.7 but expected to fail under 2.6
# with self.assertRaises(TypeError) as cm:
# MARKMIN().xml()
# self.assertEqual(cm.exception[0], '__init__() takes at least 2 arguments (1 given)')
# For now
self.assertRaises(TypeError, MARKMIN)
self.assertEqual(MARKMIN('').xml(), '')
self.assertEqual(MARKMIN('<>').xml(),
'<>
')
self.assertEqual(MARKMIN("``hello_world = 'Hello World!'``:python").xml(),
'hello_world = \'Hello World!\'')
self.assertEqual(MARKMIN('<>').flatten(), '<>')
def test_ASSIGNJS(self):
# empty assignation
self.assertEqual(ASSIGNJS().xml(), '')
# text assignation
self.assertEqual(ASSIGNJS(var1='1', var2='2').xml(), 'var var1 = "1";\nvar var2 = "2";\n')
# int assignation
self.assertEqual(ASSIGNJS(var1=1, var2=2).xml(), 'var var1 = 1;\nvar var2 = 2;\n')
class TestData(unittest.TestCase):
def test_Adata(self):
self.assertEqual(A('<>', data=dict(abc='', cde='standard'), _a='1', _b='2').xml(),
'<> ')
if __name__ == '__main__':
unittest.main()