def test_toElementOptions(self): """ Test rendering to a DOM with options. """ field = data_form.Field('list-single', var='test') field.options = [data_form.Option(u'option1'), data_form.Option(u'option2')] element = field.toElement(True) self.assertEqual(2, len(element.children))
def fillForm(self, user, iq, cmd, form): form.instructions = ["Select the items you no longer wish to track."] form.addField( data_form.Field(var='tracks', fieldType='list-multi', options=(data_form.Option(v, v) for v in sorted(user.tracks))))
def test_toElement(self): option = data_form.Option('value', 'label') element = option.toElement() self.assertEquals('option', element.name) self.assertEquals(NS_X_DATA, element.uri) self.assertEquals('label', element['label']) self.assertEquals('value', element.value.name) self.assertEquals(NS_X_DATA, element.value.uri) self.assertEquals('value', unicode(element.value))
def test_toElementLabel(self): """ A label is rendered as an attribute on the option element. """ option = data_form.Option('value', 'label') element = option.toElement() self.assertEqual('option', element.name) self.assertEqual(NS_X_DATA, element.uri) self.assertEqual(NS_X_DATA, element.value.uri) self.assertEqual('value', unicode(element.value)) self.assertEqual('label', element['label'])
def test_toElement(self): """ An option is an option element with a value child with the option value. """ option = data_form.Option('value') element = option.toElement() self.assertEqual('option', element.name) self.assertEqual(NS_X_DATA, element.uri) self.assertEqual(NS_X_DATA, element.value.uri) self.assertEqual('value', unicode(element.value)) self.assertFalse(element.hasAttribute('label'))
def test_repr(self): """ The repr of a field should be equal to its initialization. """ field = data_form.Field('list-single', var='test', label='label', desc='desc', required=True, value='test', options=[data_form.Option('test')]) self.assertEqual("""Field(fieldType='list-single', """ """var='test', label='label', """ """desc='desc', required=True, """ """values=['test'], """ """options=[Option('test')])""", repr(field))
def test_repr(self): """ The representation of an Option is equal to how it is created. """ option = data_form.Option('value', 'label') self.assertEqual("""Option('value', 'label')""", repr(option))