示例#1
0
文件: html.py 项目: azazel75/pulsar
 def test_ancor(self):
     a = wsgi.Html('a', 'kaput', cn='bla', href='/abc/')
     self.assertEqual(a.attr('href'), '/abc/')
     ht = a.render()
     self.assertTrue('>kaput</a>' in ht)
     a = wsgi.Html('a', xxxx='ciao')
     self.assertTrue('xxxx' in a.attr())
示例#2
0
 def test_html_repr(self):
     c = wsgi.Html('div', cn='bla', charset='utf-16')
     self.assertEqual(c.content_type, 'text/html; charset=utf-16')
     self.assertEqual(str(c), "<div class='bla'>")
     c = wsgi.Html(None, cn='bla')
     self.assertEqual(c.tag, None)
     self.assertEqual(str(c), "Html")
示例#3
0
 def test_remove_all(self):
     root = wsgi.Html('div')
     child1 = wsgi.Html('div')
     root.append(child1)
     root.append('ciao')
     self.assertEqual(len(root.children), 2)
     root.remove_all()
     self.assertEqual(len(root.children), 0)
示例#4
0
文件: html.py 项目: azazel75/pulsar
 def testClass(self):
     c = wsgi.Html('div').addClass('ciao').addClass('pippo')
     self.assertTrue(c.hasClass('ciao'))
     self.assertTrue(c.hasClass('pippo'))
     f = c.flatatt()
     self.assertTrue(f in (" class='ciao pippo'", " class='pippo ciao'"))
     c = wsgi.Html('div').addClass('ciao pippo bla')
     self.assertTrue(c.hasClass('bla'))
示例#5
0
文件: html.py 项目: azazel75/pulsar
 def testList(self):
     ul = wsgi.Html('ul')
     self.assertEqual(ul.tag, 'ul')
     self.assertEqual(len(ul.children), 0)
     ul = wsgi.Html('ul', 'a list item', 'another one')
     self.assertEqual(len(ul.children), 2)
     ht = ul.render()
     self.assertTrue('<ul>' in ht)
     self.assertTrue('</ul>' in ht)
     self.assertTrue('<li>a list item</li>' in ht)
     self.assertTrue('<li>another one</li>' in ht)
示例#6
0
文件: manage.py 项目: robgil/pulsar
 def home_page(self, request):
     doc = wsgi.HtmlDocument(media_path='/media/',
                             known_libraries=media_libraries)
     doc.head.scripts.append('require')
     doc.head.scripts.require('jquery', 'd3', 'philosophers.js')
     doc.head.links.append('bootstrap')
     doc.body.append(wsgi.Html('div', cn='philosophers'))
     return doc.http_response(request)
示例#7
0
文件: html.py 项目: azazel75/pulsar
 def testRemoveClass(self):
     c = wsgi.Html('div', cn=['ciao', 'pippo', 'ciao', 'foo'])
     self.assertEqual(len(c._classes), 3)
     c.removeClass('sdjkcbhjsd smdhcbjscbsdcsd')
     self.assertEqual(len(c._classes), 3)
     c.removeClass('ciao sdjkbsjc')
     self.assertEqual(len(c._classes), 2)
     c.removeClass('pippo foo')
     self.assertEqual(len(c._classes), 0)
示例#8
0
文件: html.py 项目: azazel75/pulsar
 def testData(self):
     c = wsgi.Html('div')
     c.data('food', 'pasta').data('city', 'Rome')
     self.assertEqual(c.data('food'), 'pasta')
     self.assertEqual(c.data('city'), 'Rome')
     f = c.flatatt()
     self.assertTrue(f in (" data-food='pasta' data-city='Rome'",
                           " data-city='Rome' data-food='pasta'"))
     c.data('food', 'risotto')
     self.assertEqual(c.data('food'), 'risotto')
示例#9
0
 def test_document(self):
     m = wsgi.HtmlDocument(title='test')
     m.body.append(wsgi.Html('div', 'this is a test'))
     txt = m.to_string()
     self.assertEqual(
         txt, '\n'.join([
             '<!DOCTYPE html>', '<html>', '<head>', '<title>test</title>',
             "<meta charset='utf-8'>", '</head>', '<body>',
             '<div>this is a test</div>', '</body>', '</html>', ''
         ]))
示例#10
0
文件: html.py 项目: azazel75/pulsar
 def testEmptyAttr(self):
     c = wsgi.Html('input', type='text')
     c.attr('value', None)
     self.assertEqual(c.attr('value'), None)
     self.assertEqual(c.flatatt(), " type='text'")
     c.attr('value', '')
     self.assertEqual(c.attr('value'), '')
     self.assertTrue(" value=''" in c.flatatt())
     c.attr('value', 0)
     self.assertTrue(" value='0'" in c.flatatt())
     self.assertEqual(c.attr('value'), 0)
示例#11
0
文件: html.py 项目: azazel75/pulsar
 def testNestedData(self):
     random = ['bla', 3, 'foo']
     table = {'name': 'path', 'resizable': True}
     c = wsgi.Html('div')
     r = c.data({'table': table, 'random': random})
     self.assertEqual(r, c)
     self.assertEqual(c.data('table')['name'], 'path')
     self.assertEqual(c.data('table')['resizable'], True)
     self.assertEqual(c.data('random')[0], 'bla')
     attr = c.flatatt()
     self.assertTrue('data-table' in attr)
     c.data('table', {'resizable': False, 'rows': 40})
     self.assertEqual(c.data('table')['name'], 'path')
     self.assertEqual(c.data('table')['resizable'], False)
     self.assertEqual(c.data('table')['rows'], 40)
示例#12
0
 def test_true_attribute(self):
     txt = wsgi.Html('div', bla=True).render()
     self.assertEqual(txt, '<div bla></div>')
示例#13
0
 def test_true_attribute(self):
     txt = wsgi.Html('div', bla=True).to_string()
     self.assertEqual(txt, '<div bla></div>\n')
示例#14
0
文件: html.py 项目: azazel75/pulsar
 def test_option_empty_attribute(self):
     opt = wsgi.Html('option', '--------', value='')
     self.assertEqual(opt.attr('value'), '')
     text = opt.render()
     self.assertTrue(" value=''" in text)
示例#15
0
文件: html.py 项目: azazel75/pulsar
 def testClassList(self):
     c = wsgi.Html('div', cn=['ciao', 'pippo', 'ciao'])
     self.assertEqual(len(c._classes), 2)
     self.assertTrue('ciao' in c._classes)
     self.assertTrue('pippo' in c._classes)
     self.assertTrue(c.hasClass('pippo'))
示例#16
0
文件: html.py 项目: azazel75/pulsar
 def testEmpty(self):
     c = wsgi.Html('div')
     self.assertEqual(c._attr, None)
     self.assertEqual(c._classes, None)
     self.assertEqual(c._data, None)
     self.assertEqual(c._css, None)
示例#17
0
文件: html.py 项目: azazel75/pulsar
 def test_textarea_value_attribute(self):
     opt = wsgi.Html('textarea', 'Hello World!')
     self.assertEqual(opt.attr('value'), None)
     self.assertEqual(opt.get_form_value(), 'Hello World!')
     text = opt.render()
     self.assertTrue("Hello World!" in text)
示例#18
0
文件: html.py 项目: azazel75/pulsar
 def testHide(self):
     c = wsgi.Html('div', 'foo').hide()
     self.assertEqual(c.flatatt(), " style='display:none;'")
     c.show()
     self.assertEqual(c.flatatt(), "")