예제 #1
0
파일: test_forms.py 프로젝트: codbox/eulxml
    def test_exclude(self):
        # if exclude is specified, those fields should not be listed
        myform = xmlobjectform_factory(TestObject,
            exclude=['id', 'bool', 'child.id2'])
        form = myform()
        self.assert_('int' in form.base_fields,
            'int field is present in form fields when not excluded')
        self.assert_('longtext' in form.base_fields,
            'longtext field is present in form fields when not excluded')
        self.assert_('bool' not in form.base_fields,
            'bool field is not present in form fields when excluded')
        self.assert_('id' not in form.base_fields,
            'id field is not present in form fields when excluded')
        self.assert_('child' in form.subforms,
            'child subform is present in form fields when subfields excluded')
        self.assert_('val' in form.subforms['child'].base_fields,
            'val field is present in child subform fields when not excluded')
        self.assert_('id2' not in form.subforms['child'].base_fields,
            'id2 field is not present in child subform fields when excluded')

        # another variant for excluding an entire subform
        myform = xmlobjectform_factory(TestObject,
            exclude=['child'])
        form = myform()
        self.assert_('child' not in form.subforms,
            'child subform is not present in form fields when excluded')
예제 #2
0
    def test_exclude(self):
        # if exclude is specified, those fields should not be listed
        myform = xmlobjectform_factory(TestObject,
            exclude=['id', 'bool', 'child.id2'])
        form = myform()
        self.assert_('int' in form.base_fields,
            'int field is present in form fields when not excluded')
        self.assert_('longtext' in form.base_fields,
            'longtext field is present in form fields when not excluded')
        self.assert_('bool' not in form.base_fields,
            'bool field is not present in form fields when excluded')
        self.assert_('id' not in form.base_fields,
            'id field is not present in form fields when excluded')
        self.assert_('child' in form.subforms,
            'child subform is present in form fields when subfields excluded')
        self.assert_('val' in form.subforms['child'].base_fields,
            'val field is present in child subform fields when not excluded')
        self.assert_('id2' not in form.subforms['child'].base_fields,
            'id2 field is not present in child subform fields when excluded')

        # another variant for excluding an entire subform
        myform = xmlobjectform_factory(TestObject,
            exclude=['child'])
        form = myform()
        self.assert_('child' not in form.subforms,
            'child subform is not present in form fields when excluded')
예제 #3
0
파일: test_forms.py 프로젝트: codbox/eulxml
    def test_specified_fields(self):
        # if fields are specified, only they should be listed
        myfields = ['int', 'bool', 'child.val']
        myform = xmlobjectform_factory(TestObject, fields=myfields)
        form = myform()
        self.assert_('int' in form.base_fields,
            'int field is present in form fields when specified in field list')
        self.assert_('bool' in form.base_fields,
            'bool field is present in form fields when specified in field list')
        self.assert_('id' not in form.base_fields,
            'id field is not present in form fields when not specified in field list')

        self.assert_('child' in form.subforms,
            'child field is present in subforms when specified in nested field list')
        self.assert_('val' in form.subforms['child'].base_fields,
            'val field present in child subform fields when specified in nested field list')
        self.assert_('id2' not in form.subforms['child'].base_fields,
            'id2 field is not present in child subform fields when not specified in nested field list')

        # form field order should match order in fields list
        self.assertEqual(form.base_fields.keys(), ['int', 'bool'])

        # second variant to confirm field order
        myfields = ['longtext', 'int', 'bool']
        myform = xmlobjectform_factory(TestObject, fields=myfields)
        form = myform()
        self.assertEqual(myfields, form.base_fields.keys())
예제 #4
0
    def test_specified_fields(self):
        # if fields are specified, only they should be listed
        myfields = ['int', 'bool', 'child.val']
        myform = xmlobjectform_factory(TestObject, fields=myfields)
        form = myform()
        self.assert_('int' in form.base_fields,
            'int field is present in form fields when specified in field list')
        self.assert_('bool' in form.base_fields,
            'bool field is present in form fields when specified in field list')
        self.assert_('id' not in form.base_fields,
            'id field is not present in form fields when not specified in field list')

        self.assert_('child' in form.subforms,
            'child field is present in subforms when specified in nested field list')
        self.assert_('val' in form.subforms['child'].base_fields,
            'val field present in child subform fields when specified in nested field list')
        self.assert_('id2' not in form.subforms['child'].base_fields,
            'id2 field is not present in child subform fields when not specified in nested field list')

        # form field order should match order in fields list
        self.assertEqual(list(form.base_fields.keys()), ['int', 'bool'])

        # second variant to confirm field order
        myfields = ['longtext', 'int', 'bool']
        myform = xmlobjectform_factory(TestObject, fields=myfields)
        form = myform()
        self.assertEqual(myfields, list(form.base_fields.keys()))
예제 #5
0
    def test_xmlobjectform_factory(self):
        form = xmlobjectform_factory(TestObject)
        # creates and returns a new form class of type XmlObjectFormType
        self.assert_(
            isinstance(form, XmlObjectFormType),
            'factory-generated form class is of type XmlObjectFormType')

        expected, got = 'TestObjectXmlObjectForm', form.__name__
        self.assertEqual(expected, got,
            "factory-generated form class has a reasonable name; expected %s, got %s" % \
            (expected, got))
        self.assertEqual(
            TestObject, form.Meta.model,
            "xmlobject class 'TestObject' correctly set as model in form class Meta"
        )

        # specify particular fields - should be set in form Meta
        form = xmlobjectform_factory(TestObject, fields=['int', 'bool'])
        self.assert_('int' in form.Meta.fields)
        self.assert_('bool' in form.Meta.fields)
        self.assert_('id' not in form.Meta.fields)

        # exclude particular fields - should be set in form Meta
        form = xmlobjectform_factory(TestObject, exclude=['int', 'bool'])
        self.assert_('int' in form.Meta.exclude)
        self.assert_('bool' in form.Meta.exclude)
        self.assert_('id' not in form.Meta.exclude)
예제 #6
0
파일: test_forms.py 프로젝트: codbox/eulxml
    def test_default_field_order(self):
        # form field order should correspond to field order in xmlobject, which is:
        # id, int, bool, longtext, [child]
        field_names = self.update_form.base_fields.keys()
        self.assertEqual('id', field_names[0],
            "first field in xmlobject ('id') is first in form fields")
        self.assertEqual('int', field_names[1],
            "second field in xmlobject ('int') is second in form fields")
        self.assertEqual('bool', field_names[2],
            "third field in xmlobject ('bool') is third in form fields")
        self.assertEqual('longtext', field_names[3],
            "fourth field in xmlobject ('longtext') is fourth in form fields")

        class MyTestObject(xmlmap.XmlObject):
            ROOT_NAME = 'foo'
            a = xmlmap.StringField('a')
            z = xmlmap.StringField('z')
            b = xmlmap.StringField('b')
            y = xmlmap.StringField('y')

        myform = xmlobjectform_factory(MyTestObject)
        form = myform()
        field_names = form.base_fields.keys()
        self.assertEqual('a', field_names[0],
            "first field in xmlobject ('a') is first in form fields")
        self.assertEqual('z', field_names[1],
            "second field in xmlobject ('z') is second in form fields")
        self.assertEqual('b', field_names[2],
            "third field in xmlobject ('b') is third in form fields")
        self.assertEqual('y', field_names[3],
            "fourth field in xmlobject ('y') is fourth in form fields")
예제 #7
0
    def test_default_field_order(self):
        # form field order should correspond to field order in xmlobject, which is:
        # id, int, bool, longtext, [child]
        field_names = list(self.update_form.base_fields.keys())
        self.assertEqual('id', field_names[0],
            "first field in xmlobject ('id') is first in form fields")
        self.assertEqual('int', field_names[1],
            "second field in xmlobject ('int') is second in form fields")
        self.assertEqual('bool', field_names[2],
            "third field in xmlobject ('bool') is third in form fields")
        self.assertEqual('longtext', field_names[3],
            "fourth field in xmlobject ('longtext') is fourth in form fields")

        class MyTestObject(xmlmap.XmlObject):
            ROOT_NAME = 'foo'
            a = xmlmap.StringField('a')
            z = xmlmap.StringField('z')
            b = xmlmap.StringField('b')
            y = xmlmap.StringField('y')

        myform = xmlobjectform_factory(MyTestObject)
        form = myform()
        field_names = list(form.base_fields.keys())
        self.assertEqual('a', field_names[0],
            "first field in xmlobject ('a') is first in form fields")
        self.assertEqual('z', field_names[1],
            "second field in xmlobject ('z') is second in form fields")
        self.assertEqual('b', field_names[2],
            "third field in xmlobject ('b') is third in form fields")
        self.assertEqual('y', field_names[3],
            "fourth field in xmlobject ('y') is fourth in form fields")
예제 #8
0
파일: forms.py 프로젝트: jrhoads/TheKeep
class OriginInfoForm(XmlObjectForm):
    """Custom :class:`~eulxml.forms.XmlObjectForm` to edit MODS
    :class:`~eulxml.xmlmap.mods.OriginInfo`.  Currently only consists
    of simple date entry for date created and issued using :class:`SimpleDateForm`.
    """
    form_label = 'Origin Info'
    #Create the subform fields from fields (xmlmap) in eulxml.
    created = SubformField(formclass=xmlobjectform_factory(
        mods.DateCreated, form=SimpleDateForm, max_num=1, can_delete=False))
    issued = SubformField(formclass=xmlobjectform_factory(mods.DateIssued,
                                                          form=SimpleDateForm,
                                                          max_num=1,
                                                          can_delete=False),
                          label='Date Issued')

    class Meta:
        model = mods.OriginInfo
        fields = ['created', 'issued']
예제 #9
0
파일: test_forms.py 프로젝트: codbox/eulxml
    def test_xmlobjectform_factory(self):
        form = xmlobjectform_factory(TestObject)
        # creates and returns a new form class of type XmlObjectFormType
        self.assert_(isinstance(form, XmlObjectFormType),
            'factory-generated form class is of type XmlObjectFormType')

        expected, got = 'TestObjectXmlObjectForm', form.__name__
        self.assertEqual(expected, got,
            "factory-generated form class has a reasonable name; expected %s, got %s" % \
            (expected, got))
        self.assertEqual(TestObject, form.Meta.model,
            "xmlobject class 'TestObject' correctly set as model in form class Meta")

        # specify particular fields - should be set in form Meta
        form = xmlobjectform_factory(TestObject, fields=['int', 'bool'])
        self.assert_('int' in form.Meta.fields)
        self.assert_('bool' in form.Meta.fields)
        self.assert_('id' not in form.Meta.fields)

        # exclude particular fields - should be set in form Meta
        form = xmlobjectform_factory(TestObject, exclude=['int', 'bool'])
        self.assert_('int' in form.Meta.exclude)
        self.assert_('bool' in form.Meta.exclude)
        self.assert_('id' not in form.Meta.exclude)