Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a test for Pylons/deform#81

  • Loading branch information...
commit 740ae1f786e1d9f1ee9331c21cb886a2ff6ec380 1 parent b7ba8c9
@dnouri dnouri authored
Showing with 60 additions and 0 deletions.
  1. +18 −0 deformdemo/__init__.py
  2. +42 −0 deformdemo/test.py
View
18 deformdemo/__init__.py
@@ -967,6 +967,24 @@ class Schema(colander.Schema):
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)
+ @view_config(renderer='templates/form.pt', name='select_integer')
+ @demonstrate('Select Widget (with Integer values)')
+ def select_integer(self):
+ choices = (
+ ('', '- Select -'),
+ (0, 'Zero'),
+ (1, 'One'),
+ (2, 'Two')
+ )
+ class Schema(colander.Schema):
+ number = colander.SchemaNode(
+ colander.Integer(),
+ widget=deform.widget.SelectWidget(values=choices)
+ )
+ schema = Schema()
+ form = deform.Form(schema, buttons=('submit',))
+ return self.render_form(form)
+
@view_config(renderer='templates/form.pt', name='checkboxchoice')
@demonstrate('Checkbox Choice Widget')
def checkboxchoice(self):
View
42 deformdemo/test.py
@@ -1872,6 +1872,48 @@ def test_submit_selected(self):
captured,
"{'pepper': u'habanero'}")
+class SelectWidgetIntegerTests(Base, unittest.TestCase):
+ url = '/select_integer/'
+ def test_render_default(self):
+ browser.open(self.url)
+ browser.wait_for_page_to_load("30000")
+ self.assertTrue(browser.is_text_present("Number"))
+ self.assertEqual(browser.get_attribute("deformField1@name"), 'number')
+ self.assertEqual(browser.get_selected_index('deformField1'), '0')
+ options = browser.get_select_options('deformField1')
+ self.assertEqual(
+ options,
+ [u'- Select -', u'Zero', u'One', u'Two'])
+ self.assertEqual(browser.get_text('css=.req'), '*')
+ self.assertEqual(browser.get_text('css=#captured'), 'None')
+
+ def test_submit_default(self):
+ browser.open(self.url)
+ browser.wait_for_page_to_load("30000")
+ browser.click('submit')
+ browser.wait_for_page_to_load("30000")
+ self.assertTrue(browser.is_text_present("Number"))
+ self.assertEqual(browser.get_attribute("deformField1@name"), 'number')
+ self.assertEqual(browser.get_selected_index('deformField1'), '0')
+ self.assertEqual(browser.get_text('css=#error-deformField1'),
+ 'Required')
+ captured = browser.get_text('css=#captured')
+ self.assertEqual(captured, 'None')
+ self.assertEqual(browser.get_text('css=#captured'), 'None')
+
+ def test_submit_selected(self):
+ browser.open(self.url)
+ browser.wait_for_page_to_load("30000")
+ browser.select('deformField1', 'index=1')
+ browser.click('submit')
+ browser.wait_for_page_to_load("30000")
+ self.assertFalse(browser.is_element_present('css=.errorMsgLbl'))
+ self.assertEqual(browser.get_selected_index('deformField1'), '1')
+ captured = browser.get_text('css=#captured')
+ self.assertSimilarRepr(
+ captured,
+ "{'number': 0}")
+
class SelectWidgetWithSizeTests(SelectWidgetTests):
url = "/select_with_size/"
Please sign in to comment.
Something went wrong with that request. Please try again.