Ticket #3262: forms-tests.2.diff

File forms-tests.2.diff, 4.7 KB (added by dummy@…, 9 years ago)

update: I found an error in the test for SelectMultipleGrouped widget

  • tests/regressiontests/forms/tests.py

     
    33>>> from django.newforms import *
    44>>> import datetime
    55>>> import re
     6>>> from django.newforms.widgets import SelectGrouped, SelectMultipleGrouped
    67
    78###########
    89# Widgets #
     
    403404>>> w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')])
    404405u'<select multiple="multiple" name="nums">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" selected="selected">\u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</option>\n<option value="\u0107\u017e\u0161\u0111">abc\u0107\u017e\u0161\u0111</option>\n</select>'
    405406
     407### SelectGrouped Widget
     408
     409>>> choices = []
     410>>> choices.append(('label for group 1', [('value1', 'label1'), ('value2', 'label2')]))
     411>>> choices.append(('label for group 2', [('value3', 'label3'), ('value4', 'label4')]))
     412>>> w = SelectGrouped(choices=choices)
     413>>> print w.render('name','value1')
     414<select name="name">
     415<optgroup label="label for group 1">
     416<option value="value1" selected="selected">label1</option>
     417<option value="value2">label2</option>
     418</optgroup>
     419<optgroup label="label for group 2">
     420<option value="value3">label3</option>
     421<option value="value4">label4</option>
     422</optgroup>
     423</select>
     424
     425>>> choices = []
     426>>> choices.append(('label for group 1', [['value1', 'label1'], ['value2', 'label2']]))
     427>>> choices.append(('label for group 2', [['value3', 'label3'], ['value4', 'label4']]))
     428>>> w = SelectGrouped(choices=choices)
     429>>> print w.render('name','value1')
     430<select name="name">
     431<optgroup label="label for group 1">
     432<option value="value1" selected="selected">label1</option>
     433<option value="value2">label2</option>
     434</optgroup>
     435<optgroup label="label for group 2">
     436<option value="value3">label3</option>
     437<option value="value4">label4</option>
     438</optgroup>
     439</select>
     440
     441>>> choices = []
     442>>> choices.append(['label for group 1', [['value1', 'label1'], ['value2', 'label2']]])
     443>>> choices.append(['label for group 2', [['value3', 'label3'], ['value4', 'label4']]])
     444>>> w = SelectGrouped(choices=choices)
     445>>> print w.render('name','value1')
     446<select name="name">
     447<optgroup label="label for group 1">
     448<option value="value1" selected="selected">label1</option>
     449<option value="value2">label2</option>
     450</optgroup>
     451<optgroup label="label for group 2">
     452<option value="value3">label3</option>
     453<option value="value4">label4</option>
     454</optgroup>
     455</select>
     456
     457### SelectMultipleGrouped Widget
     458>>> choices = []
     459>>> choices.append(('label for group 1', [('value1', 'label1'), ('value2', 'label2')]))
     460>>> choices.append(('label for group 2', [('value3', 'label3'), ('value4', 'label4')]))
     461>>> w = SelectMultipleGrouped(choices=choices)
     462>>> print w.render('name',['value1','value3'])
     463<select multiple="multiple" name="name">
     464<optgroup label="label for group 1">
     465<option value="value1" selected="selected">label1</option>
     466<option value="value2">label2</option>
     467</optgroup>
     468<optgroup label="label for group 2">
     469<option value="value3" selected="selected">label3</option>
     470<option value="value4">label4</option>
     471</optgroup>
     472</select>
     473
     474>>> choices = []
     475>>> choices.append(('label for group 1', [['value1', 'label1'], ['value2', 'label2']]))
     476>>> choices.append(('label for group 2', [['value3', 'label3'], ['value4', 'label4']]))
     477>>> w = SelectMultipleGrouped(choices=choices)
     478>>> print w.render('name',['value1'])
     479<select multiple="multiple" name="name">
     480<optgroup label="label for group 1">
     481<option value="value1" selected="selected">label1</option>
     482<option value="value2">label2</option>
     483</optgroup>
     484<optgroup label="label for group 2">
     485<option value="value3">label3</option>
     486<option value="value4">label4</option>
     487</optgroup>
     488</select>
     489
     490>>> choices = []
     491>>> choices.append(['label for group 1', [['value1', 'label1'], ['value2', 'label2']]])
     492>>> choices.append(['label for group 2', [['value3', 'label3'], ['value4', 'label4']]])
     493>>> w = SelectMultipleGrouped(choices=choices)
     494>>> print w.render('name',('value1','value4'))
     495<select multiple="multiple" name="name">
     496<optgroup label="label for group 1">
     497<option value="value1" selected="selected">label1</option>
     498<option value="value2">label2</option>
     499</optgroup>
     500<optgroup label="label for group 2">
     501<option value="value3">label3</option>
     502<option value="value4" selected="selected">label4</option>
     503</optgroup>
     504</select>
     505
     506
    406507# RadioSelect Widget ##########################################################
    407508
    408509>>> w = RadioSelect()
Back to Top