def test_migrate_extended_document(self):
     from plone.app.contenttypes.migration.migration import migrateCustomAT
     from plone.app.contenttypes.interfaces import INewsItem
     at_document = self.createCustomATDocument('foo-document')
     qi = self.portal.portal_quickinstaller
     # install pac but only install News Items
     qi.installProduct(
         'plone.app.contenttypes',
         profile='plone.app.contenttypes:default',
         blacklistedSteps=['typeinfo'])
     installTypeIfNeeded("News Item")
     fields_mapping = (
         {'AT_field_name': 'textExtended',
          'AT_field_type': 'Products.Archetypes.Field.TextField',
          'DX_field_name': 'text',
          'DX_field_type': 'RichText', },
         {'AT_field_name': 'stringExtended',
          'AT_field_type': 'StringField',
          'DX_field_name': 'title',
          'DX_field_type': 'StringField', },
     )
     # migrate extended AT Document to default DX News Item
     migrateCustomAT(
         fields_mapping, src_type='Document', dst_type='News Item')
     dx_newsitem = self.portal['foo-document']
     self.assertTrue(INewsItem.providedBy(dx_newsitem))
     self.assertTrue(dx_newsitem is not at_document)
     self.assertEquals(at_document.textExtended(), dx_newsitem.text.raw)
     self.assertEquals(at_document.stringExtended, dx_newsitem.title)
Ejemplo n.º 2
0
 def test_migrate_extended_document(self):
     from plone.app.contenttypes.migration.migration import migrateCustomAT
     from plone.app.contenttypes.interfaces import INewsItem
     at_document = self.createCustomATDocument('foo-document')
     qi = self.portal.portal_quickinstaller
     # install pac but only install News Items
     qi.installProduct('plone.app.contenttypes',
                       profile='plone.app.contenttypes:default',
                       blacklistedSteps=['typeinfo'])
     installTypeIfNeeded('News Item')
     fields_mapping = (
         {
             'AT_field_name': 'textExtended',
             'AT_field_type': 'Products.Archetypes.Field.TextField',
             'DX_field_name': 'text',
             'DX_field_type': 'RichText',
         },
         {
             'AT_field_name': 'stringExtended',
             'AT_field_type': 'StringField',
             'DX_field_name': 'title',
             'DX_field_type': 'StringField',
         },
     )
     # migrate extended AT Document to default DX News Item
     migrateCustomAT(fields_mapping,
                     src_type='Document',
                     dst_type='News Item')
     dx_newsitem = self.portal['foo-document']
     self.assertTrue(INewsItem.providedBy(dx_newsitem))
     self.assertTrue(dx_newsitem is not at_document)
     self.assertEqual(at_document.textExtended(), dx_newsitem.text.raw)
     self.assertEqual(at_document.stringExtended, dx_newsitem.title)
 def test_migrate_extended_document(self):
     from plone.app.contenttypes.migration.migration import migrateCustomAT
     from plone.app.contenttypes.interfaces import INewsItem
     at_document = self.createCustomATDocument('foo-document')
     # install pac but only install News Items
     portal_setup = getToolByName(self.portal, 'portal_setup')
     portal_setup.runAllImportStepsFromProfile(
         'profile-plone.app.contenttypes:default',
         blacklisted_steps=['typeinfo'],
     )
     installTypeIfNeeded('News Item')
     fields_mapping = (
         {'AT_field_name': 'textExtended',
          'AT_field_type': 'Products.Archetypes.Field.TextField',
          'DX_field_name': 'text',
          'DX_field_type': 'RichText', },
         {'AT_field_name': 'stringExtended',
          'AT_field_type': 'StringField',
          'DX_field_name': 'title',
          'DX_field_type': 'StringField', },
     )
     # migrate extended AT Document to default DX News Item
     migrateCustomAT(
         fields_mapping, src_type='Document', dst_type='News Item')
     dx_newsitem = self.portal['foo-document']
     self.assertTrue(INewsItem.providedBy(dx_newsitem))
     self.assertTrue(dx_newsitem is not at_document)
     self.assertEqual(at_document.textExtended(), dx_newsitem.text.raw)
     self.assertEqual(at_document.stringExtended, dx_newsitem.title)
    def test_migration_with_custom_fieldmigrator(self):
        """Migrate a ATDocument to a DXNewsItem using a custom modifier"""
        from plone.app.contenttypes.interfaces import INewsItem
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        at_document = self.createCustomATDocument('foo-document')
        at_text = (
            u'Some | field is | pipe-delimited | in the field\n'
        )
        at_document.setText(at_text)
        # install pac but only install News Items
        portal_setup = getToolByName(self.portal, 'portal_setup')
        portal_setup.runAllImportStepsFromProfile(
            'profile-plone.app.contenttypes:default',
            blacklisted_steps=['typeinfo'],
        )
        installTypeIfNeeded('News Item')
        fields_mapping = (
            {'AT_field_name': 'text',
             'DX_field_name': 'creators',
             'field_migrator': some_field_migrator},
        )
        migrateCustomAT(
            fields_mapping, src_type='Document', dst_type='News Item')

        dx_newsitem = self.portal['foo-document']
        self.assertTrue(INewsItem.providedBy(dx_newsitem))
        self.assertTrue(dx_newsitem is not at_document)
        self.assertEqual(4, len(dx_newsitem.creators))
        self.assertEqual(at_document.Title(), dx_newsitem.title)
Ejemplo n.º 5
0
    def test_migration_with_custom_fieldmigrator(self):
        """Migrate a ATDocument to a DXNewsItem using a custom modifier"""
        from plone.app.contenttypes.interfaces import INewsItem
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        at_document = self.createCustomATDocument('foo-document')
        at_text = (u'Some | field is | pipe-delimited | in the field\n')
        at_document.setText(at_text)
        qi = self.portal.portal_quickinstaller
        # install pac but only install News Items
        qi.installProduct('plone.app.contenttypes',
                          profile='plone.app.contenttypes:default',
                          blacklistedSteps=['typeinfo'])
        installTypeIfNeeded('News Item')
        fields_mapping = ({
            'AT_field_name': 'text',
            'DX_field_name': 'creators',
            'field_migrator': some_field_migrator
        }, )
        migrateCustomAT(fields_mapping,
                        src_type='Document',
                        dst_type='News Item')

        dx_newsitem = self.portal['foo-document']
        self.assertTrue(INewsItem.providedBy(dx_newsitem))
        self.assertTrue(dx_newsitem is not at_document)
        self.assertEqual(4, len(dx_newsitem.creators))
        self.assertEqual(at_document.Title(), dx_newsitem.title)
def migrate_helpcenterreferencemanualsection(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterReferencemanualsection...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterReferenceManualSection',
        dst_type='Folder',
    )
def migrate_helpcenterglossary(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterGlossary...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterGlossary',
        dst_type='Document',
    )
def migrate_helpcenter(context=None):
    fields_mapping = ({
        'AT_field_name': 'rights',
        'DX_field_name': 'text',
        'field_migrator': appending_richtext_migrator
    }, )
    log.info('Migrating HelpCenter...')
    migrateCustomAT(fields_mapping, src_type='HelpCenter', dst_type='Folder')
def migrate_helpcentererrorreference(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterErrorReference...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterErrorReference',
        dst_type='Document',
    )
def migrate_helpcenterknowledgebase(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterKnowledgebase...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterKnowledgebase',
        dst_type='Folder',
    )
def migrate_helpcentertutorial(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterTutorial...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterTutorial',
        dst_type='Folder',
    )
def migrate_helpcenterlinkfolder(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterLinkFolder...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterLinkFolder',
        dst_type='Folder',
    )
def migrate_helpcenterinstructionalvideofolder(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterInstructionalVideoFolder...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterInstructionalVideoFolder',
        dst_type='Folder',
    )
def migrate_helpcentererrorreferencefolder(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterErrorReferenceFolder...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterErrorReferenceFolder',
        dst_type='Folder',
    )
def migrate_helpcenterlink(context=None):
    fields_mapping = ({'AT_field_name': 'url', 'DX_field_name': 'remoteUrl'}, )
    log.info('Migrating HelpCenterLink...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterLink',
        dst_type='Link',
    )
def migrate_helpcenterdefinition(context=None):
    fields_mapping = []
    log.info('Migrating HelpCenterDefinition...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterDefinition',
        dst_type='Document',
    )
def migrate_helpcenterinstructionalvideo(context=None):
    fields_mapping = ({
        'AT_field_name': 'video_file',
        'DX_field_name': 'file',
        'DX_field_type': 'NamedBlobFile',
    }, )
    log.info('Migrating HelpCenterInstructionalVideo...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterInstructionalVideo',
        dst_type='File',
    )
def migrate_helpcentertutorialpage(context=None):
    fields_mapping = ({
        'AT_field_name': 'text',
        'DX_field_name': 'text',
        'DX_field_type': 'RichText',
    }, )
    log.info('Migrating HelpCenterTutorialpage...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterTutorialpage',
        dst_type='Document',
    )
def migrate_helpcenterhowto(context=None):
    fields_mapping = ({
        'AT_field_name': 'text',
        'DX_field_name': 'text',
        'DX_field_type': 'RichText',
    }, )
    log.info('Migrating HelpCenterHowTo...')
    migrateCustomAT(
        fields_mapping,
        src_type='HelpCenterHowTo',
        dst_type='Folder',
    )
Ejemplo n.º 20
0
    def migrate(self, dry_run=False):
        '''Build data from the migration form. We will build a dict like :
           {'MyATPortalType':
                {'MyDXPortalType': (
                    {'AT_field_name': 'fieldname1',
                     'AT_field_type': 'Products.Archetypes.Field.TextField',
                     'DX_field_name': 'field_name1',
                     'DX_field_type': 'RichText'}, )}}
        Call the migrateCustomAT migrator for each AT content_type we choose
        to migrate.
        '''
        data = {}
        form = self.request.form
        # manipulate what we receive in the form and build a useable data dict
        for k in self.request.form.keys():
            if k.startswith('dx_select_'):
                # we found select where we choose a DX type regarding an AT
                # type the selelect name is like 'dx_select_MyATPortalType'
                if not form[k] or (dry_run and k != form.get('tested_type')):
                    # nothing selected in this select, continue
                    continue
                at_typename = k[10:]
                dx_typename = form[k]
                data[at_typename] = {
                    'target_type': dx_typename,
                    'field_mapping': []
                }
                # now handle fields mapping for found DX/AT type migration
                # definition we have 2 keys we relevant mappings, first key
                # is the AT typename second key is a particular key like
                # 'dx_DXPortalType__for__MyATPortalType
                dx_key = 'dx_%s__for__%s' % (dx_typename, at_typename)
                for at_field in form[at_typename]:
                    dx_field = form[dx_key][form[at_typename].index(at_field)]
                    if not dx_field:
                        continue
                    at_field_name, at_field_type = at_field.split('__type__')
                    dx_field_name, dx_field_type = dx_field.split('__type__')
                    field_data = {
                        'AT_field_name': at_field_name,
                        'AT_field_type': at_field_type,
                        'DX_field_name': dx_field_name,
                        'DX_field_type': dx_field_type,
                    }
                    data[at_typename]['field_mapping'].append(field_data)

        # now that the data dict contains relevant information, we can call
        # the custom migrator
        migration_results = []
        for at_typename in data:
            fields_mapping = data[at_typename]['field_mapping']
            res = migrateCustomAT(fields_mapping=fields_mapping,
                                  src_type=at_typename,
                                  dst_type=data[at_typename]['target_type'],
                                  dry_run=dry_run)
            migration_results.append({'type': at_typename, 'infos': res})
        return migration_results
    def migrate(self, dry_run=False):
        '''Build data from the migration form. We will build a dict like :
           {'MyATPortalType':
                {'MyDXPortalType': (
                    {'AT_field_name': 'fieldname1',
                     'AT_field_type': 'Products.Archetypes.Field.TextField',
                     'DX_field_name': 'field_name1',
                     'DX_field_type': 'RichText'}, )}}
        Call the migrateCustomAT migrator for each AT content_type we choose
        to migrate.
        '''
        data = {}
        form = self.request.form
        # manipulate what we receive in the form and build a useable data dict
        for k in self.request.form.keys():
            if k.startswith('dx_select_'):
                # we found select where we choose a DX type regarding an AT
                # type the selelect name is like 'dx_select_MyATPortalType'
                if not form[k] or (dry_run and k != form.get('tested_type')):
                    # nothing selected in this select, continue
                    continue
                at_typename = k[10:]
                dx_typename = form[k]
                data[at_typename] = {'target_type': dx_typename,
                                     'field_mapping': []}
                # now handle fields mapping for found DX/AT type migration
                # definition we have 2 keys we relevant mappings, first key
                # is the AT typename second key is a particular key like
                # 'dx_DXPortalType__for__MyATPortalType
                dx_key = 'dx_%s__for__%s' % (dx_typename, at_typename)
                for at_field in form[at_typename]:
                    dx_field = form[dx_key][form[at_typename].index(at_field)]
                    if not dx_field:
                        continue
                    at_field_name, at_field_type = at_field.split('__type__')
                    dx_field_name, dx_field_type = dx_field.split('__type__')
                    field_data = {'AT_field_name': at_field_name,
                                  'AT_field_type': at_field_type,
                                  'DX_field_name': dx_field_name,
                                  'DX_field_type': dx_field_type, }
                    data[at_typename]['field_mapping'].append(field_data)

        # now that the data dict contains relevant information, we can call
        # the custom migrator
        migration_results = []
        for at_typename in data:
            fields_mapping = data[at_typename]['field_mapping']
            res = migrateCustomAT(
                fields_mapping=fields_mapping,
                src_type=at_typename,
                dst_type=data[at_typename]['target_type'],
                dry_run=dry_run)
            migration_results.append({'type': at_typename,
                                      'infos': res})
        return migration_results
    def test_migrate_atevent_to_dxevent(self):
        """Tests the custom migration by migrating a default type. It is not
        meant to be used this way but is a nice way to test the migrations.
        During this migration the event fti is already replaced by the dx one.
        """
        from DateTime import DateTime
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        from plone.app.contenttypes.interfaces import IEvent

        # create an ATEvent
        self.portal.invokeFactory('Event', 'event')
        at_event = self.portal['event']

        # Date
        FORMAT = '%Y-%m-%d %H:%M'
        start = '2013-02-03 12:15'
        end = '2013-04-05 13:45'
        at_event.getField('startDate').set(at_event, DateTime(start))
        at_event.getField('endDate').set(at_event, DateTime(end))

        # Contact
        at_event.getField('contactPhone').set(at_event, '123456789')
        at_event.getField('contactEmail').set(at_event, '*****@*****.**')
        at_event.getField('contactName').set(at_event, u'Näme')

        # URL
        at_event.getField('eventUrl').set(at_event, 'http://www.plone.org')

        # Attendees
        at_event.getField('attendees').set(at_event, ('Yöu', 'Me'))

        # Text
        at_event.setText('Tütensuppe')
        at_event.setContentType('text/plain')

        oldTZ = os.environ.get('TZ', None)
        TZ = 'Asia/Tbilisi'
        os.environ['TZ'] = TZ
        timezone = pytz.timezone(TZ)

        qi = self.portal.portal_quickinstaller
        # install pac but only install Event
        qi.installProduct(
            'plone.app.contenttypes',
            profile='plone.app.contenttypes:default',
            blacklistedSteps=['typeinfo'])
        installTypeIfNeeded("Event")
        fields_mapping = (
            {'AT_field_name': 'startDate',
             'AT_field_type': 'Products.Archetypes.Field.DateTimeField',
             'DX_field_name': 'start',
             'DX_field_type': 'Datetime', },
            {'AT_field_name': 'endDate',
             'AT_field_type': 'Products.Archetypes.Field.DateTimeField',
             'DX_field_name': 'end',
             'DX_field_type': 'Datetime', },
            {'AT_field_name': 'text',
             'AT_field_type': 'Products.Archetypes.Field.TextField',
             'DX_field_name': 'text',
             'DX_field_type': 'RichText', },
            {'AT_field_name': 'eventUrl',
             'AT_field_type': 'Products.Archetypes.Field.StringField',
             'DX_field_name': 'event_url',
             'DX_field_type': 'StringField', },
            {'AT_field_name': 'contactEmail',
             'AT_field_type': 'Products.Archetypes.Field.StringField',
             'DX_field_name': 'contact_email',
             'DX_field_type': 'StringField', },
            {'AT_field_name': 'contactName',
             'AT_field_type': 'Products.Archetypes.Field.StringField',
             'DX_field_name': 'contact_name',
             'DX_field_type': 'StringField', },
            {'AT_field_name': 'contactPhone',
             'AT_field_type': 'Products.Archetypes.Field.StringField',
             'DX_field_name': 'contact_phone',
             'DX_field_type': 'StringField', },
            {'AT_field_name': 'attendees',
             'AT_field_type': 'Products.Archetypes.Field.LinesField',
             'DX_field_name': 'attendees',
             'DX_field_type': 'Tuple', },
        )
        # migrate ATEvent to new default Event
        migrateCustomAT(fields_mapping, src_type='Event', dst_type='Event')
        dx_event = self.portal['event']
        self.assertTrue(IEvent.providedBy(dx_event))
        self.assertTrue(dx_event is not at_event)
        self.assertEquals(safe_unicode(
            at_event.getText()), dx_event.text.output)
        self.assertEquals(at_event.eventUrl, dx_event.event_url)
        self.assertEquals(at_event.contactEmail, dx_event.contact_email)
        self.assertEquals(at_event.contactName, dx_event.contact_name)
        self.assertEquals(at_event.contactPhone, dx_event.contact_phone)
        self.assertEquals(at_event.attendees, dx_event.attendees)
        self.assertEquals(
            dx_event.start,
            timezone.localize(datetime.strptime(start, FORMAT)))
        self.assertEquals(
            dx_event.end, timezone.localize(datetime.strptime(end, FORMAT)))
        if oldTZ:
            os.environ['TZ'] = oldTZ
        else:
            del os.environ['TZ']
Ejemplo n.º 23
0
    def test_migrate_atevent_to_dxevent(self):
        """Tests the custom migration by migrating a default type. It is not
        meant to be used this way but is a nice way to test the migrations.
        During this migration the event fti is already replaced by the dx one.
        """
        from DateTime import DateTime
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        from plone.app.contenttypes.interfaces import IEvent

        # create an ATEvent
        self.portal.invokeFactory('Event', 'event')
        at_event = self.portal['event']

        # Date
        FORMAT = '%Y-%m-%d %H:%M'
        start = '2013-02-03 12:15'
        end = '2013-04-05 13:45'
        at_event.getField('startDate').set(at_event, DateTime(start))
        at_event.getField('endDate').set(at_event, DateTime(end))

        # Contact
        at_event.getField('contactPhone').set(at_event, '123456789')
        at_event.getField('contactEmail').set(at_event, '*****@*****.**')
        at_event.getField('contactName').set(at_event, u'Näme')

        # URL
        at_event.getField('eventUrl').set(at_event, 'http://www.plone.org')

        # Attendees
        at_event.getField('attendees').set(at_event, ('Yöu', 'Me'))

        # Text
        at_event.setText('Tütensuppe')
        at_event.setContentType('text/plain')

        oldTZ = os.environ.get('TZ', None)
        TZ = 'Asia/Tbilisi'
        os.environ['TZ'] = TZ
        timezone = pytz.timezone(TZ)

        qi = self.portal.portal_quickinstaller
        # install pac but only install Event
        qi.installProduct('plone.app.contenttypes',
                          profile='plone.app.contenttypes:default',
                          blacklistedSteps=['typeinfo'])
        installTypeIfNeeded('Event')
        fields_mapping = (
            {
                'AT_field_name': 'startDate',
                'AT_field_type': 'Products.Archetypes.Field.DateTimeField',
                'DX_field_name': 'start',
                'DX_field_type': 'Datetime',
            },
            {
                'AT_field_name': 'endDate',
                'AT_field_type': 'Products.Archetypes.Field.DateTimeField',
                'DX_field_name': 'end',
                'DX_field_type': 'Datetime',
            },
            {
                'AT_field_name': 'text',
                'AT_field_type': 'Products.Archetypes.Field.TextField',
                'DX_field_name': 'text',
                'DX_field_type': 'RichText',
            },
            {
                'AT_field_name': 'eventUrl',
                'AT_field_type': 'Products.Archetypes.Field.StringField',
                'DX_field_name': 'event_url',
                'DX_field_type': 'StringField',
            },
            {
                'AT_field_name': 'contactEmail',
                'AT_field_type': 'Products.Archetypes.Field.StringField',
                'DX_field_name': 'contact_email',
                'DX_field_type': 'StringField',
            },
            {
                'AT_field_name': 'contactName',
                'AT_field_type': 'Products.Archetypes.Field.StringField',
                'DX_field_name': 'contact_name',
                'DX_field_type': 'StringField',
            },
            {
                'AT_field_name': 'contactPhone',
                'AT_field_type': 'Products.Archetypes.Field.StringField',
                'DX_field_name': 'contact_phone',
                'DX_field_type': 'StringField',
            },
            {
                'AT_field_name': 'attendees',
                'AT_field_type': 'Products.Archetypes.Field.LinesField',
                'DX_field_name': 'attendees',
                'DX_field_type': 'Tuple',
            },
        )
        # migrate ATEvent to new default Event
        migrateCustomAT(fields_mapping, src_type='Event', dst_type='Event')
        dx_event = self.portal['event']
        self.assertTrue(IEvent.providedBy(dx_event))
        self.assertTrue(dx_event is not at_event)
        self.assertEqual(safe_unicode(at_event.getText()),
                         dx_event.text.output)
        self.assertEqual(at_event.eventUrl, dx_event.event_url)
        self.assertEqual(at_event.contactEmail, dx_event.contact_email)
        self.assertEqual(at_event.contactName, dx_event.contact_name)
        self.assertEqual(at_event.contactPhone, dx_event.contact_phone)
        self.assertEqual(at_event.attendees, dx_event.attendees)
        self.assertEqual(dx_event.start,
                         timezone.localize(datetime.strptime(start, FORMAT)))
        self.assertEqual(dx_event.end,
                         timezone.localize(datetime.strptime(end, FORMAT)))
        if oldTZ:
            os.environ['TZ'] = oldTZ
        else:
            del os.environ['TZ']
Ejemplo n.º 24
0
    def test_migrate_atevent_to_dxnewsitem(self):
        """Tests the custom migration by migrating a default type. It is not
        meant to be used this way but is a nice way to test the migrations.
        During this migration the old event fti is still present.
        """
        from DateTime import DateTime
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        from plone.app.contenttypes.interfaces import INewsItem

        # create an ATEvent
        self.portal.invokeFactory('Event', 'event')
        at_event = self.portal['event']

        # Date
        at_event.getField('startDate') \
                .set(at_event, DateTime('2013-02-03 12:00'))
        at_event.getField('endDate') \
                .set(at_event, DateTime('2013-04-05 13:00'))

        # Contact
        at_event.getField('contactPhone').set(at_event, '123456789')
        at_event.getField('contactEmail').set(at_event, '*****@*****.**')
        at_event.getField('contactName').set(at_event, u'Näme')

        # URL
        at_event.getField('eventUrl').set(at_event, 'http://www.plone.org')

        # Attendees
        at_event.getField('attendees').set(at_event, ('You', 'Me'))

        # Text
        at_event.setText('Tütensuppe')
        at_event.setContentType('text/plain')

        oldTZ = os.environ.get('TZ', None)
        os.environ['TZ'] = 'Asia/Tbilisi'

        qi = self.portal.portal_quickinstaller
        # install pac but only install News Items
        qi.installProduct('plone.app.contenttypes',
                          profile='plone.app.contenttypes:default',
                          blacklistedSteps=['typeinfo'])
        installTypeIfNeeded('News Item')
        fields_mapping = (
            {
                'AT_field_name': 'text',
                'AT_field_type': 'Products.Archetypes.Field.TextField',
                'DX_field_name': 'text',
                'DX_field_type': 'RichText',
            },
            {
                'AT_field_name': 'contactName',
                'AT_field_type': 'StringField',
                'DX_field_name': 'image_caption',
                'DX_field_type': 'StringField',
            },
        )
        # migrate ATCTEvent to default DX News Item
        migrateCustomAT(fields_mapping, src_type='Event', dst_type='News Item')
        if oldTZ:
            os.environ['TZ'] = oldTZ
        else:
            del os.environ['TZ']

        dx_newsitem = self.portal['event']
        self.assertTrue(INewsItem.providedBy(dx_newsitem))
        self.assertTrue(dx_newsitem is not at_event)
        self.assertEqual(safe_unicode(at_event.getText()),
                         dx_newsitem.text.output)
        self.assertEqual(at_event.contactName, dx_newsitem.image_caption)
    def test_migrate_atevent_to_dxnewsitem(self):
        """Tests the custom migration by migrating a default type. It is not
        meant to be used this way but is a nice way to test the migrations.
        During this migration the old event fti is still present.
        """
        from DateTime import DateTime
        from plone.app.contenttypes.migration.migration import migrateCustomAT
        from plone.app.contenttypes.interfaces import INewsItem

        # create an ATEvent
        self.portal.invokeFactory('Event', 'event')
        at_event = self.portal['event']

        # Date
        at_event.getField('startDate') \
                .set(at_event, DateTime('2013-02-03 12:00'))
        at_event.getField('endDate') \
                .set(at_event, DateTime('2013-04-05 13:00'))

        # Contact
        at_event.getField('contactPhone').set(at_event, '123456789')
        at_event.getField('contactEmail').set(at_event, '*****@*****.**')
        at_event.getField('contactName').set(at_event, u'Näme')

        # URL
        at_event.getField('eventUrl').set(at_event, 'http://www.plone.org')

        # Attendees
        at_event.getField('attendees').set(at_event, ('You', 'Me'))

        # Text
        at_event.setText('Tütensuppe')
        at_event.setContentType('text/plain')

        oldTZ = os.environ.get('TZ', None)
        os.environ['TZ'] = 'Asia/Tbilisi'

        qi = self.portal.portal_quickinstaller
        # install pac but only install News Items
        qi.installProduct(
            'plone.app.contenttypes',
            profile='plone.app.contenttypes:default',
            blacklistedSteps=['typeinfo'])
        installTypeIfNeeded("News Item")
        fields_mapping = (
            {'AT_field_name': 'text',
             'AT_field_type': 'Products.Archetypes.Field.TextField',
             'DX_field_name': 'text',
             'DX_field_type': 'RichText', },
            {'AT_field_name': 'contactName',
             'AT_field_type': 'StringField',
             'DX_field_name': 'image_caption',
             'DX_field_type': 'StringField', },
        )
        # migrate ATCTEvent to default DX News Item
        migrateCustomAT(fields_mapping, src_type='Event', dst_type='News Item')
        if oldTZ:
            os.environ['TZ'] = oldTZ
        else:
            del os.environ['TZ']

        dx_newsitem = self.portal['event']
        self.assertTrue(INewsItem.providedBy(dx_newsitem))
        self.assertTrue(dx_newsitem is not at_event)
        self.assertEquals(
            safe_unicode(at_event.getText()),
            dx_newsitem.text.output)
        self.assertEquals(
            at_event.contactName,
            dx_newsitem.image_caption)