def test_prefixes(self):
     request, library, definition, group_a, group_b = self._fixtures()
     from uu.formlibrary.forms import ComposedForm
     composed = ComposedForm(definition, request)
     composed.updateFields()
     assert composed.getPrefix(group_b.schema) == group_b.getId()
     assert composed.getPrefix(definition.schema) == ''
     # group_a is a special case, it is a grid, so its schema is wrapped
     # in another schema -- indirectly part of form composition:
     assert composed.getPrefix(group_a.schema) != group_a.getId()
     # however:
     from uu.formlibrary.forms import is_grid_wrapper_schema
     schemas = [t[1] for t in composed.group_schemas]
     wrapper = [s for s in schemas if is_grid_wrapper_schema(s)][0]
     assert composed.getPrefix(wrapper) == group_a.getId()
Exemple #2
0
 def test_prefixes(self):
     request, library, definition, group_a, group_b = self._fixtures()
     from uu.formlibrary.forms import ComposedForm
     composed = ComposedForm(definition, request)
     composed.updateFields()
     assert composed.getPrefix(group_b.schema) == group_b.getId()
     assert composed.getPrefix(definition.schema) == ''
     # group_a is a special case, it is a grid, so its schema is wrapped
     # in another schema -- indirectly part of form composition:
     assert composed.getPrefix(group_a.schema) != group_a.getId()
     # however:
     from uu.formlibrary.forms import is_grid_wrapper_schema
     schemas = [t[1] for t in composed.group_schemas]
     wrapper = [s for s in schemas if is_grid_wrapper_schema(s)][0]
     assert composed.getPrefix(wrapper) == group_a.getId()
    def test_composed(self):
        request, library, definition, group_a, group_b = self._fixtures()
        # modify schema (via XML of definition, group) entries, trigger
        # load of dynamic schema via event handlers from uu.dynamicschema:
        definition.entry_schema = DEFINITION_SCHEMA
        notify(ObjectModifiedEvent(definition))
        assert 'title' in getFieldNamesInOrder(definition.schema)
        group_a.entry_schema = GROUP_A_GRID_SCHEMA
        notify(ObjectModifiedEvent(group_a))
        assert 'name' in getFieldNamesInOrder(group_a.schema)
        group_b.entry_schema = GROUP_B_FIELDSET_SCHEMA
        notify(ObjectModifiedEvent(group_b))
        assert 'feedback' in getFieldNamesInOrder(group_b.schema)

        from uu.formlibrary.forms import ComposedForm
        # assumed: ComposedForm can get out of date when the schema of the
        # adapted item changes.  composed.schema and
        # composed.additionalSchemata reflect the schema of the definition
        # and its contained groups AT THE TIME OF CONSTRUCTION/ADAPTATION
        # -- if this becomes a problem, adjust the property implementation
        # to be a true proxy at a later date, and adjust this test
        # accordingly.
        composed = ComposedForm(definition, request)
        assert len(composed.additionalSchemata) == 2
        #composed.updateFields()
        composed.update()

        # group_a is a grid, which has its schema wrapped by ComposedForm
        # construction -- the wrapper is referenced, we want to get it:
        from uu.formlibrary.forms import is_grid_wrapper_schema
        schemas = [t[1] for t in composed.group_schemas]
        wrapper = [s for s in schemas if is_grid_wrapper_schema(s)][0]
        # 'data' is field name for wrapped datagrid as list of DictRow objects
        assert 'data' in wrapper
        assert isinstance(wrapper['data'], zope.schema.List)
        assert isinstance(wrapper['data'].value_type, DictRow)
        column_schema = wrapper['data'].value_type.schema
        assert column_schema == group_a.schema

        # with regard to wrapping, serializations for the wrapper are NOT
        # stored or available in the uu.dynamicschema.schema.generated module
        # as they are throw-away and temporary for the scope of one view
        # transaction.  Every time you adapt a definition with ComposedForm,
        # a new wrapper schema will be created.
        # However, it should be noted that the wrapped schema providing the
        # field group's columns is persisted in the schema saver:
        from uu.dynamicschema.interfaces import ISchemaSaver
        saver = queryUtility(ISchemaSaver)
        assert saver is not None
        group_signature = saver.signature(group_a.schema)
        # consequence of schema mod above; group_a.schema saved, serialized:
        assert group_signature in saver.keys()
        group_schema_identifier = 'I%s' % group_signature
        from uu.dynamicschema.schema import generated
        #assert group_schema_identifier in generated.__dict__
        dynamic = getattr(generated, group_schema_identifier, None)
        assert dynamic is not None
        assert dynamic is group_a.schema

        wrapper_signature = saver.signature(wrapper)
        assert wrapper_signature not in saver.keys()  # throw-away not stored

        # default fieldset fields:
        composed_schema_fields = [f.field for f in composed.fields.values()]
        assert definition.schema in [
            field.interface for field in composed_schema_fields
        ]
        for name, field in getFieldsInOrder(definition.schema):
            assert name in composed.fields  # keys
            assert field in composed_schema_fields

        # each field group
        for group in (group_a, group_b):
            schema = group.schema
            if group.group_usage == 'grid':
                schema = wrapper  # shortcut, we only have one grid in tests...
                self.assertEqual(schema['data'].required, False)
            formgroup = [
                g for g in composed.groups if g.__name__ == group.getId()
            ][0]
            assert schema in [
                field.field.interface for field in formgroup.fields.values()
            ]
            for name, field in getFieldsInOrder(schema):
                fullname = '.'.join((composed.getPrefix(schema), name))
                assert fullname in formgroup.fields  # prefixed name in keys
                assert field in [f.field for f in formgroup.fields.values()]
Exemple #4
0
    def test_composed(self):
        request, library, definition, group_a, group_b = self._fixtures()
        # modify schema (via XML of definition, group) entries, trigger
        # load of dynamic schema via event handlers from uu.dynamicschema:
        definition.entry_schema = DEFINITION_SCHEMA
        notify(ObjectModifiedEvent(definition))
        assert 'title' in getFieldNamesInOrder(definition.schema)
        group_a.entry_schema = GROUP_A_GRID_SCHEMA
        notify(ObjectModifiedEvent(group_a))
        assert 'name' in getFieldNamesInOrder(group_a.schema)
        group_b.entry_schema = GROUP_B_FIELDSET_SCHEMA
        notify(ObjectModifiedEvent(group_b))
        assert 'feedback' in getFieldNamesInOrder(group_b.schema)

        from uu.formlibrary.forms import ComposedForm
        # assumed: ComposedForm can get out of date when the schema of the
        # adapted item changes.  composed.schema and
        # composed.additionalSchemata reflect the schema of the definition
        # and its contained groups AT THE TIME OF CONSTRUCTION/ADAPTATION
        # -- if this becomes a problem, adjust the property implementation
        # to be a true proxy at a later date, and adjust this test
        # accordingly.
        composed = ComposedForm(definition, request)
        assert len(composed.additionalSchemata) == 2
        #composed.updateFields()
        composed.update()

        # group_a is a grid, which has its schema wrapped by ComposedForm
        # construction -- the wrapper is referenced, we want to get it:
        from uu.formlibrary.forms import is_grid_wrapper_schema
        schemas = [t[1] for t in composed.group_schemas]
        wrapper = [s for s in schemas if is_grid_wrapper_schema(s)][0]
        # 'data' is field name for wrapped datagrid as list of DictRow objects
        assert 'data' in wrapper
        assert isinstance(wrapper['data'], zope.schema.List)
        assert isinstance(wrapper['data'].value_type, DictRow)
        column_schema = wrapper['data'].value_type.schema
        assert column_schema == group_a.schema

        # with regard to wrapping, serializations for the wrapper are NOT
        # stored or available in the uu.dynamicschema.schema.generated module
        # as they are throw-away and temporary for the scope of one view
        # transaction.  Every time you adapt a definition with ComposedForm,
        # a new wrapper schema will be created.
        # However, it should be noted that the wrapped schema providing the
        # field group's columns is persisted in the schema saver:
        from uu.dynamicschema.interfaces import ISchemaSaver
        saver = queryUtility(ISchemaSaver)
        assert saver is not None
        group_signature = saver.signature(group_a.schema)
        # consequence of schema mod above; group_a.schema saved, serialized:
        assert group_signature in saver.keys()
        group_schema_identifier = 'I%s' % group_signature
        from uu.dynamicschema.schema import generated
        #assert group_schema_identifier in generated.__dict__
        dynamic = getattr(generated, group_schema_identifier, None)
        assert dynamic is not None
        assert dynamic is group_a.schema

        wrapper_signature = saver.signature(wrapper)
        assert wrapper_signature not in saver.keys()  # throw-away not stored

        # default fieldset fields:
        composed_schema_fields = [f.field for f in composed.fields.values()]
        assert definition.schema in [
            field.interface for field in composed_schema_fields]
        for name, field in getFieldsInOrder(definition.schema):
            assert name in composed.fields  # keys
            assert field in composed_schema_fields

        # each field group
        for group in (group_a, group_b):
            schema = group.schema
            if group.group_usage == 'grid':
                schema = wrapper  # shortcut, we only have one grid in tests...
                self.assertEqual(
                    schema['data'].required,
                    False
                    )
            formgroup = [
                g for g in composed.groups
                if g.__name__ == group.getId()
                ][0]
            assert schema in [
                field.field.interface for field in formgroup.fields.values()]
            for name, field in getFieldsInOrder(schema):
                fullname = '.'.join((composed.getPrefix(schema), name))
                assert fullname in formgroup.fields  # prefixed name in keys
                assert field in [f.field for f in formgroup.fields.values()]