Skip to content

Commit

Permalink
add test for min-length sequences that have subitems with a default; c…
Browse files Browse the repository at this point in the history
…loses #15
  • Loading branch information
mcdonc committed Sep 25, 2012
1 parent f7fc7db commit 46f225d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
24 changes: 24 additions & 0 deletions deformdemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,30 @@ class Schema(colander.Schema):
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)

@view_config(renderer='templates/form.pt',
name='sequence_of_defaulted_selects_with_initial_item')
@demonstrate('Sequence of Defaulted Selects (With Initial Item)')
def sequence_of_defaulted_selects_with_initial_item(self):
# See https://github.com/Pylons/deformdemo/pull/15
choices = (('habanero', 'Habanero'), ('jalapeno', 'Jalapeno'),
('chipotle', 'Chipotle'))
class Peppers(colander.SequenceSchema):
pepper = colander.SchemaNode(
colander.String(),
default='jalapeno',
validator=colander.OneOf([x[0] for x in choices]),
widget=deform.widget.SelectWidget(values=choices),
title='Pepper Chooser',
description='Select a Pepper')
class Schema(colander.Schema):
peppers = Peppers()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
# raison d'etre below (1-length sequence widget means initial item
# rendered)
form['peppers'].widget = deform.widget.SequenceWidget(min_len=1)
return self.render_form(form)

@view_config(renderer='templates/form.pt',
name='sequence_of_constrained_len')
@demonstrate('Sequence of Constrained Min and Max Lengths')
Expand Down
27 changes: 26 additions & 1 deletion deformdemo/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,32 @@ def test_submit_two_filled(self):
browser.wait_for_page_to_load("30000")
self.assertFalse(browser.is_element_present('css=.errorMsgLbl'))
captured = browser.get_text('css=#captured')
self.assertEqual(eval(captured), # should be default values
self.assertEqual(eval(captured), # should be 2 values, both defaults
{'peppers': ['jalapeno', 'jalapeno']})

class SequenceOfDefaultedSelectsWithInitialItem(Base, unittest.TestCase):
url = "/sequence_of_defaulted_selects_with_initial_item/"
def test_submit_none_added(self):
browser.open(self.url)
browser.wait_for_page_to_load("30000")
browser.click("submit")
browser.wait_for_page_to_load("30000")
self.assertEqual(browser.get_text('deformField1-addtext'),
'Add Pepper Chooser')
captured = browser.get_text('css=#captured')
self.assertEqual(eval(captured), # should be 1 value (min_len 1)
{'peppers': ['jalapeno']})
self.assertFalse(browser.is_element_present('css=.errorMsgLbl'))

def test_submit_one_added(self):
browser.open(self.url)
browser.wait_for_page_to_load("30000")
browser.click('deformField1-seqAdd')
browser.click("submit")
browser.wait_for_page_to_load("30000")
self.assertFalse(browser.is_element_present('css=.errorMsgLbl'))
captured = browser.get_text('css=#captured')
self.assertEqual(eval(captured), # should be 2 values, both defaults
{'peppers': ['jalapeno', 'jalapeno']})

class SequenceOfFileUploads(Base, unittest.TestCase):
Expand Down

0 comments on commit 46f225d

Please sign in to comment.