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')
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)
def test_require_baseclass(self): without_baseclass = self.new_temporary_type( behaviors=[IPerson.__identifier__], ) with_baseclass = self.new_temporary_type( behaviors=[IPerson.__identifier__], klass='seantis.people.types.base.PersonBase' ) on_type_modified(without_baseclass) on_type_modified(with_baseclass) # create one object with the correct baseclass, one without. # Both are going to be in portal_catalog, but the one with the # person baseclass will end up in the people catalog only. with self.user('admin'): container = self.new_temporary_folder() api.content.create( id='without-baseclass', type=without_baseclass.id, container=container ) api.content.create( id='with-baseclass', type=with_baseclass.id, container=container ) path = '/'.join(container.getPhysicalPath()) portal_catalog = api.portal.get_tool('portal_catalog') people_catalog = api.portal.get_tool('seantis_people_catalog') self.assertEqual( [b.id for b in portal_catalog(path={'query': path, 'depth': 1})], ['without-baseclass', 'with-baseclass'] ) self.assertEqual( [b.id for b in people_catalog(path={'query': path, 'depth': 1})], ['with-baseclass'] )
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!')
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')
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')