Пример #1
0
    def testMigrating(self):
        serialization.register(VersionedTest1)
        feat.initial_data(VersionedTest1)
        yield tools.push_initial_data(self.connection)
        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default', doc.field1)

        serialization.register(VersionedTest2)
        yield tools.migration_script(self.connection)

        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default upgraded', doc.field1)
Пример #2
0
    def testComplexMigration(self):
        migration.register(ComplexMigration(type_name=VersionedTest2.type_name,
                                            source_ver=1, target_ver=2))

        serialization.register(VersionedTest2)
        doc = yield self.connection.save_document(VersionedTest1())
        self.assertEqual('default', doc.field1)

        yield tools.migration_script(self.connection)
        self.assertTrue(self.run)

        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default upgraded', doc.field1)
        self.assertTrue('attachment' in doc.attachments)
Пример #3
0
    def testMigrating(self):
        serialization.register(VersionedTest1)
        feat.initial_data(VersionedTest1)
        yield tools.push_initial_data(self.connection)
        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default', doc.field1)

        serialization.register(VersionedTest2)
        migration.register(SimpleMigration(type_name=VersionedTest2.type_name,
                                           source_ver=1,
                                           target_ver=2))
        yield tools.migration_script(self.connection)

        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default upgraded', doc.field1)
Пример #4
0
    def testComplexMigration(self):
        mig = migration.Migration()

        self.run = False

        def handler(connection, unparsed):
            doc = connection._unserializer.convert(unparsed)
            self.run = True
            doc.create_attachment('attachment', 'Hi!')
            return connection.save_document(doc)

        mig.registry.register(VersionedTest2)
        mig.migrate_type(VersionedTest2, handler)
        r = applications.get_application_registry()
        snapshot = r.get_snapshot()
        self.addCleanup(r.reset, snapshot)
        r.reset([])
        app = applications.Application()
        app.name = u'test'
        r.register(app)
        app.register_migration('1.0', mig)

        serialization.register(VersionedTest2)
        doc = yield self.connection.save_document(VersionedTest2())
        self.assertEqual('default', doc.field1)

        yield tools.migration_script(self.connection)
        self.assertTrue(self.run)

        doc = yield self.connection.get_document('testdoc')
        self.assertEqual('default', doc.field1)
        self.assertTrue('attachment' in doc.attachments)

        version_doc = yield self.connection.query_view(
            tools.ApplicationVersions, key='test', include_docs=True)
        self.assertEquals(1, len(version_doc))
        self.assertEquals('1.0', version_doc[0].version)
        self.assertEquals('test', version_doc[0].name)