예제 #1
0
 def test_containsNot(self):
     """
     A form does not contains an unknown field.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot')]
     form = data_form.Form('submit', fields=fields)
     self.assertNotIn('features', form)
예제 #2
0
 def test_getUnknownDefault(self):
     """
     Getting the value of a unknown field returns specified default.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot')]
     form = data_form.Form('submit', fields=fields)
     self.assertTrue(form.get('public', True))
예제 #3
0
 def test_contains(self):
     """
     A form contains a known field.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot')]
     form = data_form.Form('submit', fields=fields)
     self.assertIn('botname', form)
예제 #4
0
 def test_get(self):
     """
     Getting the value of a known field succeeds.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot')]
     form = data_form.Form('submit', fields=fields)
     self.assertEqual('The Jabber Bot', form.get('botname'))
예제 #5
0
 def test_getUnknownNone(self):
     """
     Getting the value of a unknown field returns None.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot')]
     form = data_form.Form('submit', fields=fields)
     self.assertIdentical(None, form.get('features'))
예제 #6
0
    def test_formType(self):
        """
        A form has a type.
        """

        form = data_form.Form('result')
        self.assertEqual('result', form.formType)
예제 #7
0
    def test_toElementFields(self):
        """
        Fields are rendered as child elements, in order.
        """
        fields = [data_form.Field('fixed', value='Section 1'),
                  data_form.Field('text-single',
                                  var='botname',
                                  label='The name of your bot'),
                  data_form.Field('text-multi',
                                  var='description',
                                  label='Helpful description of your bot'),
                  data_form.Field('boolean',
                                  var='public',
                                  label='Public bot?',
                                  required=True)
                 ]
        form = data_form.Form('form', fields=fields)
        element = form.toElement()

        elements = list(element.elements())
        self.assertEqual(4, len(elements))
        for field in elements:
            self.assertEqual('field', field.name)
            self.assertEqual(NS_X_DATA, field.uri)

        # Check order
        self.assertEqual('fixed', elements[0]['type'])
        self.assertEqual('botname', elements[1]['var'])
        self.assertEqual('description', elements[2]['var'])
        self.assertEqual('public', elements[3]['var'])
예제 #8
0
 def test_getitemMultipleValuesTypeSingle(self):
     """
     Multiple values for a single-value field type returns the first value.
     """
     fields = [data_form.Field('text-single', var='features',
                                     values=['news', 'search'])]
     form = data_form.Form('submit', fields=fields)
     self.assertEqual('news', form['features'])
예제 #9
0
 def test_getitemMultipleValuesNoType(self):
     """
     Multiple values for a field without type are returned in a list.
     """
     fields = [data_form.Field(None, var='features',
                                     values=['news', 'search'])]
     form = data_form.Form('submit', fields=fields)
     self.assertEqual(['news', 'search'], form['features'])
예제 #10
0
 def test_getitemOneValueTypeMulti(self):
     """
     A single value for a multi-value field type is returned in a list.
     """
     fields = [data_form.Field('list-multi', var='features',
                                             values=['news'])]
     form = data_form.Form('submit', fields=fields)
     self.assertEqual(['news'], form['features'])
예제 #11
0
    def _formFromConfiguration(self, resource, values):
        options = resource.getConfigurationOptions()
        fields = self._makeFields(options, values)
        form = data_form.Form(formType="form",
                              formNamespace=NS_PUBSUB_NODE_CONFIG,
                              fields=fields)

        return form
예제 #12
0
 def test_addField(self):
     """
     A field should occur in fieldList.
     """
     form = data_form.Form('result')
     field = data_form.Field('fixed', value='Section 1')
     form.addField(field)
     self.assertEqual([field], form.fieldList)
예제 #13
0
 def test_addFieldNamed(self):
     """
     A named field should occur in fields.
     """
     form = data_form.Form('result')
     field = data_form.Field(var='test')
     form.addField(field)
     self.assertEqual({'test': field}, form.fields)
예제 #14
0
 def every(self, user, iq, cmd):
     if cmd.firstChildElement():
         form = data_form.Form.fromElement(cmd.firstChildElement())
         return orig(self, user, iq, cmd, form)
     else:
         form = data_form.Form(formType="form", title=self.name)
         self.fillForm(user, iq, cmd, form)
         return self.genFormCmdResponse(iq, cmd, form)
예제 #15
0
 def test_addFieldNotNamed(self):
     """
     A non-named field should not occur in fields.
     """
     form = data_form.Form('result')
     field = data_form.Field('fixed', value='Section 1')
     form.addField(field)
     self.assertEqual({}, form.fields)
예제 #16
0
 def test_itervalues(self):
     """
     Iterating over the values of a form yields all field values.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot'),
               data_form.Field('boolean', var='public', value=True)]
     form = data_form.Form('submit', fields=fields)
     self.assertEqual(set(['The Jabber Bot', True]),
                      set(form.itervalues()))
예제 #17
0
 def test_otherFormTypeCancel(self):
     """
     Cancelled forms with another FORM_TYPE are ignored.
     """
     element = domish.Element((None, 'test'))
     cancelledForm = data_form.Form('cancel', formNamespace='otherns')
     element.addChild(cancelledForm.toElement())
     form = data_form.findForm(element, 'myns')
     self.assertIdentical(None, form)
예제 #18
0
 def __init__(self, to=None, frm=None):
     GroupChat.__init__(self, to=to, frm=frm)
     # build data form
     form = data_form.Form('submit', formNamespace=NS_MUC_REQUEST)
     form.addField(
         data_form.Field(var='muc#role',
                         value='participant',
                         label='Requested role'))
     self.addChild(form.toElement())
예제 #19
0
 def test_noFormTypeCancel(self):
     """
     Cancelled forms don't have a FORM_TYPE field, the first is returned.
     """
     element = domish.Element((None, 'test'))
     cancelledForm = data_form.Form('cancel')
     element.addChild(cancelledForm.toElement())
     form = data_form.findForm(element, 'myns')
     self.assertEqual('cancel', form.formType)
예제 #20
0
 def test_removeFieldNamed(self):
     """
     A removed named field should not occur in fields.
     """
     form = data_form.Form('result')
     field = data_form.Field(var='test', value='test1')
     form.addField(field)
     form.removeField(field)
     self.assertNotIn('test', form.fields)
예제 #21
0
    def toElement(self):
        element = generic.Request.toElement(self)

        query = element.addElement((self.requestNamespace, 'query'))
        if self.options is None:
            # This is a request for the configuration form.
            form = None
        elif self.options is False:
            form = data_form.Form(formType='cancel')
        else:
            form = data_form.Form(formType='submit',
                                  formNamespace=self.formNamespace)
            form.makeFields(self.options)

        if form is not None:
            query.addChild(form.toElement())

        return element
예제 #22
0
 def test_removeField(self):
     """
     A removed field should not occur in fieldList.
     """
     form = data_form.Form('result')
     field = data_form.Field('fixed', value='Section 1')
     form.addField(field)
     form.removeField(field)
     self.assertNotIn(field, form.fieldList)
예제 #23
0
 def test_addFieldSameName(self):
     """
     A named field cannot occur twice.
     """
     form = data_form.Form('result')
     field1 = data_form.Field(var='test', value='value')
     field2 = data_form.Field(var='test', value='value2')
     form.addField(field1)
     self.assertRaises(data_form.Error, form.addField, field2)
예제 #24
0
 def test_otherFormType(self):
     """
     Forms with other FORM_TYPEs are ignored.
     """
     element = domish.Element((None, 'test'))
     otherForm = data_form.Form('submit', formNamespace='otherns')
     element.addChild(otherForm.toElement())
     form = data_form.findForm(element, 'myns')
     self.assertIdentical(None, form)
예제 #25
0
 def test_addFieldTwiceNamed(self):
     """
     A second named field should occur in fields.
     """
     form = data_form.Form('result')
     field1 = data_form.Field(var='test')
     field2 = data_form.Field(var='test2')
     form.addField(field2)
     form.addField(field1)
     self.assertEqual({'test': field1, 'test2': field2}, form.fields)
예제 #26
0
 def test_values(self):
     """
     Getting the values of a form yields a list of field values.
     """
     fields = [data_form.Field(var='botname', value='The Jabber Bot'),
               data_form.Field('boolean', var='public', value=True)]
     form = data_form.Form('submit', fields=fields)
     values = form.values()
     self.assertIsInstance(values, list)
     self.assertEqual(set(['The Jabber Bot', True]), set(values))
예제 #27
0
 def test_addFieldTwice(self):
     """
     Fields occur in fieldList in the order they were added.
     """
     form = data_form.Form('result')
     field1 = data_form.Field('fixed', value='Section 1')
     field2 = data_form.Field('fixed', value='Section 2')
     form.addField(field1)
     form.addField(field2)
     self.assertEqual([field1, field2], form.fieldList)
예제 #28
0
파일: muc.py 프로젝트: Gandi/wokkel
    def toElement(self):
        element = xmppim.Message.toElement(self)

        # build data form
        form = data_form.Form('submit', formNamespace=NS_MUC_REQUEST)
        form.addField(data_form.Field(var='muc#role',
                                      value='participant',
                                      label='Requested role'))
        element.addChild(form.toElement())

        return element
예제 #29
0
    def test_makeFieldsUnknownTypeListMulti(self):
        """
        Without type, multiple values sets field type list-multi.
        """
        values = {'pubsub#show-values': ['chat', 'online', 'away']}
        form = data_form.Form('result')
        form.makeFields(values)

        field = form.fields['pubsub#show-values']
        self.assertEqual(None, field.fieldType)
        self.assertEqual(values, form.getValues())
예제 #30
0
    def test_makeFieldsUnknownTypeBoolean(self):
        """
        Without type, a boolean value sets field type boolean.
        """
        values = {'pubsub#persist_items': True}
        form = data_form.Form('result')
        form.makeFields(values)

        field = form.fields['pubsub#persist_items']
        self.assertEqual(None, field.fieldType)
        self.assertEqual(values, form.getValues())