def test_to_archive(self): user_profile = UserProfile(document_id=1, categories=['amateur'], locales=[ DocumentLocale(id=2, lang='en', title='Me', summary='...'), DocumentLocale(id=3, lang='fr', title='Moi', summary='...'), ]) user_profile_archive = user_profile.to_archive() self.assertIsNone(user_profile_archive.id) self.assertEqual(user_profile_archive.document_id, user_profile.document_id) self.assertEqual(user_profile_archive.categories, user_profile.categories) archive_locals = user_profile.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = user_profile.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title)
def test_to_archive(self): user_profile = UserProfile( document_id=1, categories=['amateur'], locales=[ DocumentLocale( id=2, lang='en', title='Me', summary='...'), DocumentLocale( id=3, lang='fr', title='Moi', summary='...'), ] ) user_profile_archive = user_profile.to_archive() self.assertIsNone(user_profile_archive.id) self.assertEqual( user_profile_archive.document_id, user_profile.document_id) self.assertEqual( user_profile_archive.categories, user_profile.categories) archive_locals = user_profile.get_archive_locales() self.assertEqual(len(archive_locals), 2) locale = user_profile.locales[0] locale_archive = archive_locals[0] self.assertIsNot(locale_archive, locale) self.assertIsNone(locale_archive.id) self.assertEqual(locale_archive.lang, locale.lang) self.assertEqual(locale_archive.title, locale.title)
def migrate(self): super(MigrateUserProfiles, self).migrate() # some users to do not have a profile, create an empty profile so that # the users can be imported. with transaction.manager: last_locale_id = self.connection_source.execute( text('select max(document_i18n_archive_id) ' 'from app_documents_i18n_archives;')).fetchone()[0] last_archive_id = self.connection_source.execute( text('select max(document_archive_id) ' 'from app_documents_archives;')).fetchone()[0] profileless_users = self.connection_source.execute( text(MigrateUserProfiles.query_profileless_users)) for row in profileless_users: user_id = row[0] last_locale_id += 1 last_archive_id += 1 locale = DocumentLocale(id=last_locale_id, document_id=user_id, lang='fr', title='') profile = UserProfile(document_id=user_id, locales=[locale]) locale_archive = locale.to_archive() locale_archive.id = last_locale_id profile_archive = profile.to_archive() profile_archive.id = last_archive_id self.session_target.add(profile) self.session_target.add(locale) self.session_target.flush() self.session_target.add(locale_archive) self.session_target.add(profile_archive)
def migrate(self): super(MigrateUserProfiles, self).migrate() # some users to do not have a profile, create an empty profile so that # the users can be imported. with transaction.manager: last_locale_id = self.connection_source.execute( text('select max(document_i18n_archive_id) ' 'from app_documents_i18n_archives;')).fetchone()[0] last_archive_id = self.connection_source.execute( text('select max(document_archive_id) ' 'from app_documents_archives;')).fetchone()[0] profileless_users = self.connection_source.execute( text(MigrateUserProfiles.query_profileless_users)) for row in profileless_users: user_id = row[0] last_locale_id += 1 last_archive_id += 1 locale = DocumentLocale( id=last_locale_id, document_id=user_id, lang='fr', title='' ) profile = UserProfile( document_id=user_id, locales=[locale] ) locale_archive = locale.to_archive() locale_archive.id = last_locale_id profile_archive = profile.to_archive() profile_archive.id = last_archive_id self.session_target.add(profile) self.session_target.add(locale) self.session_target.flush() self.session_target.add(locale_archive) self.session_target.add(profile_archive)