Exemplo n.º 1
0
    def test_compound_columns_metadata(self):
        # Both key and value of a compound_column are added to the metadata
        # if the key alone is added.

        new_type = self.new_temporary_type(behaviors=[IPerson.__identifier__])

        compound_columns = get_compound_columns()
        columns = [[key] for key in compound_columns]
        set_columns(new_type.lookupSchema(), columns)

        catalog = api.portal.get_tool(catalog_id)

        # the sets are completely different, the compound keys/values are not
        # part of the catalog columns
        self.assertFalse(
            set(compound_columns.keys()) & set(catalog._catalog.names)
        )
        self.assertFalse(
            set(compound_columns.values()) & set(catalog._catalog.names)
        )

        update_metadata(new_type)

        # the compound keys/values are a subset of the catalog columns
        self.assertTrue(
            set(compound_columns.keys()) <= set(catalog._catalog.names)
        )
        self.assertTrue(
            set(compound_columns.values()) <= set(catalog._catalog.names)
        )
Exemplo n.º 2
0
    def test_add_person_column_later(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )

        self.assertEqual(get_columns(new_type.lookupSchema()), [])

        with self.user('admin'):
            obj = api.content.create(
                id='123',
                type=new_type.id,
                container=self.new_temporary_folder(),
                foo='stop',
                bar='hammertime!'
            )

        # define the metadata after the obj has been created
        set_columns(new_type.lookupSchema(), [['foo']])

        # which leaves the attribute in a missing value state
        brain = tools.get_brain_by_object(obj, catalog_id)
        self.assertFalse(hasattr(brain, 'foo'))

        # until reindexing happens
        on_type_modified(new_type)
        brain = tools.get_brain_by_object(obj, catalog_id)
        self.assertEqual(brain.foo, 'stop')
Exemplo n.º 3
0
    def test_restricted_columns(self):

        context = self.new_temporary_folder()
        model = loadString(self.address_model)

        set_columns(model.schema, [
            ['firstname', 'lastname'],
            ['town'],
            ['country'],
        ])
        security.set_read_permissions(model.schema, {
            'firstname': 'cmf.ManagePortal',
            'lastname': 'zope2.View'
        })

        # anonymous
        columns = get_schema_columns(model.schema, context)
        self.assertEqual(len(columns), 3)
        self.assertEqual(columns[0].fields, ['lastname'])

        # admin
        with self.user('admin'):
            columns = get_schema_columns(model.schema, context)

        self.assertEqual(len(columns), 3)
        self.assertEqual(columns[0].fields, ['lastname', 'firstname'])
Exemplo n.º 4
0
    def test_default_indexes(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )

        set_columns(new_type.lookupSchema(), [['foo']])
        on_type_modified(new_type)

        with self.user('admin'):
            created = datetime.now()

            api.content.create(
                id='007',
                type=new_type.id,
                container=self.new_temporary_folder(),
                Subject='O O Seven',
                title='James Bond',
                description='Spy for his Majesty, the Queen',
                created=created
            )

        portal_catalog = api.portal.get_tool('portal_catalog')
        people_catalog = api.portal.get_tool('seantis_people_catalog')

        portal_brain = portal_catalog(portal_type=new_type.id)[0]
        people_brain = people_catalog(portal_type=new_type.id)[0]

        self.assertEqual(portal_brain.id, '007')
        self.assertEqual(portal_brain.Subject, 'O O Seven')
        self.assertEqual(portal_brain.Title, 'James Bond')
        self.assertEqual(portal_brain.created, created)
        self.assertEqual(
            portal_brain.Description, 'Spy for his Majesty, the Queen'
        )

        self.assertEqual(portal_brain.id, people_brain.id)
        self.assertEqual(portal_brain.Title, people_brain.Title)
        self.assertEqual(portal_brain.Subject, people_brain.Subject)
        self.assertEqual(portal_brain.created, people_brain.created)
        self.assertEqual(portal_brain.Description, people_brain.Description)

        self.assertEqual(len(portal_catalog(Subject='O O Seven')), 1)
        self.assertEqual(len(people_catalog(Subject='O O Seven')), 1)

        self.assertEqual(len(portal_catalog(SearchableText='James Bond')), 1)
        self.assertEqual(len(people_catalog(SearchableText='James Bond')), 1)

        # folder and person
        self.assertEqual(len(portal_catalog(created=created)), 2)

        # person only
        self.assertEqual(len(people_catalog(created=created)), 1)
Exemplo n.º 5
0
    def test_one_column(self):

        model = loadString(self.address_model)

        set_columns(model.schema, [['lastname']])
        columns = unrestricted_get_schema_columns(model.schema)

        self.assertEqual(len(columns), 1)
        self.assertEqual(columns[0].schema, model.schema)
        self.assertEqual(columns[0].fields, ['lastname'])
        self.assertEqual(columns[0].titles, [u'Nachname'])
        self.assertEqual(columns[0].contains_title_field, False)
Exemplo n.º 6
0
    def test_merged_columns(self):

        model = loadString(self.address_model)

        set_columns(model.schema, [['country', 'lastname']])
        columns = unrestricted_get_schema_columns(model.schema)

        self.assertEqual(len(columns), 1)

        # ordered by field order
        self.assertEqual(columns[0].fields, ['lastname', 'country'])
        self.assertEqual(columns[0].titles, [u'Nachname', u'Land'])
        self.assertEqual(columns[0].contains_title_field, False)
Exemplo n.º 7
0
    def test_write_column_schema(self):
        model = loadString(self.column_xml)
        set_columns(
            model.schema, [['first'], ['third', 'fourth']]
        )
        set_custom_column_titles(
            model.schema, ['one', 'two']
        )
        xml = self.deprettify(serializeSchema(model.schema))

        self.assertIn('<people:column title="one"><people:item>first<', xml)
        self.assertIn('<people:column title="two"><people:item>third<', xml)
        self.assertIn('</people:item><people:item>fourth</people:item>', xml)

        self.assertTrue(
            xml.find('<people:item>first</people:item>') <
            xml.find('<people:item>third</people:item>') <
            xml.find('<people:item>fourth</people:item>')
        )
Exemplo n.º 8
0
    def test_contains_title_field(self):

        model = loadString(self.address_model)

        set_columns(model.schema, [['country', 'lastname']])

        columns = unrestricted_get_schema_columns(model.schema)
        self.assertEqual(columns[0].contains_title_field, False)

        set_title_fields(model.schema, ['lastname'])
        columns = unrestricted_get_schema_columns(model.schema)
        self.assertEqual(columns[0].contains_title_field, True)

        set_title_fields(model.schema, ['firstname'])
        columns = unrestricted_get_schema_columns(model.schema)
        self.assertEqual(columns[0].contains_title_field, False)

        set_columns(model.schema, [['firstname']])
        columns = unrestricted_get_schema_columns(model.schema)
        self.assertEqual(columns[0].contains_title_field, True)
Exemplo n.º 9
0
    def test_reindex_on_change(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )

        set_columns(new_type.lookupSchema(), [['foo']])
        on_type_modified(new_type)

        with self.user('admin'):
            obj = api.content.create(
                id='123',
                type=new_type.id,
                container=self.new_temporary_folder(),
                foo='stop',
                bar='hammertime!'
            )

        brain = tools.get_brain_by_object(obj, catalog_id)

        self.assertTrue(hasattr(brain, 'foo'))
        self.assertFalse(hasattr(brain, 'bar'))

        self.assertEqual(brain.foo, 'stop')

        set_columns(new_type.lookupSchema(), [['bar']])

        # usually the dexterity fti modified event does this
        on_type_modified(new_type)

        brain = tools.get_brain_by_object(obj, catalog_id)

        # The metadata is not deleted at this point because it is impossible
        # to tell if the metadata is used elsewhere. It's a rather big caveat..
        self.assertTrue(hasattr(brain, 'foo'))
        self.assertTrue(hasattr(brain, 'bar'))

        self.assertEqual(brain.bar, 'hammertime!')
Exemplo n.º 10
0
    def test_column_metadata(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )

        set_columns(new_type.lookupSchema(), [['foo']])
        on_type_modified(new_type)

        with self.user('admin'):
            api.content.create(
                id='123',
                type=new_type.id,
                container=self.new_temporary_folder(),
                foo='bar',
            )

        portal_catalog = api.portal.get_tool('portal_catalog')
        people_catalog = api.portal.get_tool('seantis_people_catalog')

        with self.assertRaises(AttributeError):
            portal_catalog(portal_type=new_type.id)[0].foo

        self.assertEqual(people_catalog(portal_type=new_type.id)[0].foo, 'bar')
Exemplo n.º 11
0
    def test_add_person_column_first(self):
        new_type = self.new_temporary_type(
            behaviors=[IPerson.__identifier__],
            klass='seantis.people.types.base.PersonBase'
        )

        set_columns(new_type.lookupSchema(), [['foo']])
        on_type_modified(new_type)

        with self.user('admin'):
            obj = api.content.create(
                id='123',
                type=new_type.id,
                container=self.new_temporary_folder(),
                foo='stop',
                bar='hammertime!'
            )

        brain = tools.get_brain_by_object(obj, catalog_id)

        self.assertTrue(hasattr(brain, 'foo'))
        self.assertFalse(hasattr(brain, 'bar'))

        self.assertEqual(brain.foo, 'stop')