Tests for html_declarations

This commit is contained in:
Karl Hobley 2015-02-06 12:59:01 +00:00
parent c0f74d5a5f
commit 18a4722b51

View file

@ -201,6 +201,20 @@ class TestStructBlock(unittest.TestCase):
self.assertIn('<div class="field url_field">', html)
self.assertIn('<input id="mylink-link" name="mylink-link" type="url" value="http://www.torchbox.com" />', html)
def test_render_form_uses_default_value(self):
class LinkBlock(blocks.StructBlock):
title = blocks.FieldBlock(forms.CharField(), default="Torchbox")
link = blocks.FieldBlock(forms.URLField(), default="http://www.torchbox.com")
block = LinkBlock()
html = block.render_form({}, prefix='mylink')
self.assertIn('<div class="struct-block">', html)
self.assertIn('<div class="field char_field">', html)
self.assertIn('<input id="mylink-title" name="mylink-title" type="text" value="Torchbox" />', html)
self.assertIn('<div class="field url_field">', html)
self.assertIn('<input id="mylink-link" name="mylink-link" type="url" value="http://www.torchbox.com" />', html)
class TestListBlock(unittest.TestCase):
def test_initialise_with_class(self):
@ -261,7 +275,7 @@ class TestListBlock(unittest.TestCase):
html = self.render_form()
self.assertIn('<label for=links-0-value-title>Title</label>', html)
self.assertIn('<label for=links-1-value-link>Link</label>', html)
self.assertIn('<label for=links-0-value-link>Link</label>', html)
def test_render_form_values(self):
html = self.render_form()
@ -271,6 +285,28 @@ class TestListBlock(unittest.TestCase):
self.assertIn('<input id="links-1-value-title" name="links-1-value-title" type="text" value="Django" />', html)
self.assertIn('<input id="links-1-value-link" name="links-1-value-link" type="url" value="http://www.djangoproject.com" />', html)
def test_html_declarations(self):
class LinkBlock(blocks.StructBlock):
title = blocks.FieldBlock(forms.CharField())
link = blocks.FieldBlock(forms.URLField())
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertIn('<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" type="text" />', html)
self.assertIn('<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" type="url" />', html)
def test_html_declarations_uses_default(self):
class LinkBlock(blocks.StructBlock):
title = blocks.FieldBlock(forms.CharField(), default="Github")
link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com")
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertIn('<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" type="text" value="Github" />', html)
self.assertIn('<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" type="url" value="http://www.github.com" />', html)
class TestStreamBlock(unittest.TestCase):
def test_initialisation(self):
@ -426,3 +462,54 @@ class TestStreamBlock(unittest.TestCase):
self.assertIn('<input id="myarticle-0-value" name="myarticle-0-value" type="text" value="My title" />', html)
self.assertIn('<input id="myarticle-1-value" name="myarticle-1-value" type="text" value="My first paragraph" />', html)
self.assertIn('<input id="myarticle-2-value" name="myarticle-2-value" type="text" value="My second paragraph" />', html)
def test_render_form_uses_default_value(self):
class ArticleBlock(blocks.StreamBlock):
heading = blocks.FieldBlock(forms.CharField(), )
paragraph = blocks.FieldBlock(forms.CharField())
default = [
{
'type': 'heading',
'value': "My title",
}
]
block = ArticleBlock()
value = block.to_python([
{
'type': 'heading',
'value': "My title",
},
{
'type': 'paragraph',
'value': 'My first paragraph',
},
{
'type': 'paragraph',
'value': 'My second paragraph',
},
])
return block.render_form(value, prefix='myarticle')
def test_html_declarations(self):
class LinkBlock(blocks.StructBlock):
title = blocks.FieldBlock(forms.CharField())
link = blocks.FieldBlock(forms.URLField())
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertIn('<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" type="text" />', html)
self.assertIn('<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" type="url" />', html)
def test_html_declarations_uses_default(self):
class LinkBlock(blocks.StructBlock):
title = blocks.FieldBlock(forms.CharField(), default="Github")
link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com")
block = blocks.ListBlock(LinkBlock)
html = block.html_declarations()
self.assertIn('<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" type="text" value="Github" />', html)
self.assertIn('<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" type="url" value="http://www.github.com" />', html)