Beispiel #1
0
 def test_request(self):
     request = TestRequest(form={'field.foo.0.bar': u'Hello world!',
                                 'field.foo.count': u'1'})
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     self.assert_(widget.hasInput())
     self.assertEquals(widget.getInputValue(), (u'Hello world!',))
Beispiel #2
0
 def test_new(self):
     request = TestRequest()
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     self.failIf(widget.hasInput())
     self.assertRaises(MissingInputError, widget.getInputValue)
     check_list = ('input', 'name="field.foo.add"')
     self.verifyResult(widget(), check_list)
Beispiel #3
0
 def test_max(self):
     request = TestRequest()
     self.field.max_length = 1
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     widget.setRenderedValue((u'existing',))
     self.assertRaises(MissingInputError, widget.getInputValue)
     s = widget()
     self.assertEquals(s.find('field.foo.add'), -1)
Beispiel #4
0
 def test_add(self):
     request = TestRequest(form={'field.foo.add': u'Add bar',
                                 'field.foo.count': u'0'})
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     self.assert_(widget.hasInput())
     self.assertRaises(WidgetInputError, widget.getInputValue)
     check_list = (
         'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
         'submit', 'submit', 'field.foo.add'
     )
     self.verifyResult(widget(), check_list, inorder=True)
Beispiel #5
0
    def test_usererror(self):
        self.field = Tuple(__name__=u'foo', value_type=TextLine(__name__='bar'))
        request = TestRequest(form={
            'field.foo.0.bar': u'', 'field.foo.1.bar': u'nonempty',
            'field.foo.count': u'2'})
        widget = TupleSequenceWidget(
            self.field, self.field.value_type, request)
        s = widget()
        # Rendering a widget should not raise errors!
        result = widget()

        data = widget._generateSequence()
        self.assertEquals(data, [None, u'nonempty'])
Beispiel #6
0
 def test_anonymousfield(self):
     self.field = Tuple(__name__=u'foo', value_type=TextLine())
     request = TestRequest()
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     widget.setRenderedValue((u'existing',))
     s = widget()
     check_list = (
         'input', '"field.foo.0."', 'existing',
         'submit', 'submit', 'field.foo.add'
     )
     s = widget()
     self.verifyResult(s, check_list, inorder=True)
Beispiel #7
0
 def test_min(self):
     request = TestRequest()
     self.field.min_length = 2
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     widget.setRenderedValue((u'existing',))
     self.assertRaises(MissingInputError, widget.getInputValue)
     check_list = (
         'input', 'field.foo.0.bar', 'existing',
         'input', 'field.foo.1.bar', 'value=""',
         'submit', 'field.foo.add'
     )
     s = widget()
     self.verifyResult(s, check_list, inorder=True)
     self.assertEquals(s.find('checkbox'), -1)
Beispiel #8
0
 def test_existing(self):
     request = TestRequest()
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     widget.setRenderedValue((u'existing',))
     self.failIf(widget.hasInput())
     self.assertRaises(MissingInputError, widget.getInputValue)
     check_list = (
         'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
             'existing',
         'submit', 'submit', 'field.foo.add',
         'field.foo.count" value="1"',
     )
     self.verifyResult(widget(), check_list, inorder=True)
     widget.setRenderedValue((u'existing', u'second'))
     self.failIf(widget.hasInput())
     self.assertRaises(MissingInputError, widget.getInputValue)
     check_list = (
         'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
             'existing',
         'checkbox', 'field.foo.remove_1', 'input', 'field.foo.1.bar',
             'second',
         'submit', 'submit', 'field.foo.add',
         'field.foo.count" value="2"',
     )
     self.verifyResult(widget(), check_list, inorder=True)
Beispiel #9
0
 def test_remove(self):
     request = TestRequest(form={
         'field.foo.remove_0': u'1',
         'field.foo.0.bar': u'existing', 'field.foo.1.bar': u'second',
         'field.foo.remove': u'Remove selected items',
         'field.foo.count': u'2'})
     widget = TupleSequenceWidget(
         self.field, self.field.value_type, request)
     widget.setRenderedValue((u'existing', u'second'))
     self.assertEquals(widget.getInputValue(), (u'second',))
     check_list = (
         'checkbox', 'field.foo.remove_0', 'input', 'field.foo.0.bar',
             'existing',
         'checkbox', 'field.foo.remove_1', 'input', 'field.foo.1.bar',
             'second',
         'submit', 'submit', 'field.foo.add',
         'field.foo.count" value="2"',
     )
     self.verifyResult(widget(), check_list, inorder=True)