Beispiel #1
0
    def test_upgradeStoreRecursing(self):
        """
        L{Upgrade} upgrades L{Item}s in substores.
        """
        choose(oldapp)

        ss1 = SubStore.createNew(self.store, ['a'])
        ss2 = SubStore.createNew(self.store, ['b'])

        swordIDs = [
            (ss1.storeID, oldapp.Sword(store=ss1.open(), name='foo').storeID),
            (ss2.storeID, oldapp.Sword(store=ss2.open(), name='bar').storeID)]

        del ss1, ss2
        self.store.close()

        choose(deleteswordapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')

        callWithStdoutRedirect(cmd.parseOptions, [])

        for (ssid, swordID) in swordIDs:
            self.assertRaises(
                KeyError,
                self.store.getItemByID(ssid).open().getItemByID, swordID)
Beispiel #2
0
    def test_axiomaticUpgradeExceptionBubbling(self):
        """
        Exceptions encountered by L{Upgrade.upgradeStore} are handled and
        re-raised as L{errors.ItemUpgradeError} with attributes indicating
        which L{Item} was being upgraded when the exception occurred.
        """
        choose(oldapp)
        swordID = oldapp.Sword(
            store=self.store, name='longsword', hurtfulness=4).storeID
        self.store.close()

        choose(brokenapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')
        cmd.count = 100

        err = self.assertRaises(
            errors.ItemUpgradeError,
            callWithStdoutRedirect, cmd.upgradeStore, self.store)

        self.assertTrue(
            err.originalFailure.check(brokenapp.UpgradersAreBrokenHere))

        oldType = item.declareLegacyItem(
            oldapp.Sword.typeName,
            oldapp.Sword.schemaVersion, {})
        self.assertEqual(err.storeID, swordID)
        self.assertIdentical(err.oldType, oldType)
        self.assertIdentical(err.newType, brokenapp.Sword)
Beispiel #3
0
    def test_axiomaticUpgradePerformFails(self):
        """
        If an exception occurs while upgrading items, L{Upgrade.postOptions}
        reports the item and schema version for which it occurred and returns
        without exception.
        """
        choose(oldapp)
        swordID = oldapp.Sword(
            store=self.store, name='rapier', hurtfulness=3).storeID
        self.store.close()

        choose(brokenapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')

        result, output = callWithStdoutRedirect(
            cmd.parseOptions, ['--count', '100'])
        lines = output.getvalue().splitlines()

        # Ensure that the original error is output.
        self.assertEqual(lines[0], 'Upgrader error:')
        self.assertTrue(len(lines) > 2)

        oldType = oldapp.Sword
        newType = store._typeNameToMostRecentClass[oldType.typeName]
        msg = cmd.errorMessageFormat % (
            oldType.typeName, swordID, oldType.schemaVersion,
            newType.schemaVersion)
        self.assertTrue(lines[-1].startswith(msg))
Beispiel #4
0
    def test_upgradeStoreRecursing(self):
        """
        L{Upgrade} upgrades L{Item}s in substores.
        """
        choose(oldapp)

        ss1 = SubStore.createNew(self.store, ['a'])
        ss2 = SubStore.createNew(self.store, ['b'])

        swordIDs = [(ss1.storeID, oldapp.Sword(store=ss1.open(),
                                               name='foo').storeID),
                    (ss2.storeID, oldapp.Sword(store=ss2.open(),
                                               name='bar').storeID)]

        del ss1, ss2
        self.store.close()

        choose(deleteswordapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')

        callWithStdoutRedirect(cmd.parseOptions, [])

        for (ssid, swordID) in swordIDs:
            self.assertRaises(KeyError,
                              self.store.getItemByID(ssid).open().getItemByID,
                              swordID)
Beispiel #5
0
    def test_axiomaticUpgradePerformFails(self):
        """
        If an exception occurs while upgrading items, L{Upgrade.postOptions}
        reports the item and schema version for which it occurred and returns
        without exception.
        """
        choose(oldapp)
        swordID = oldapp.Sword(store=self.store, name='rapier',
                               hurtfulness=3).storeID
        self.store.close()

        choose(brokenapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')

        result, output = callWithStdoutRedirect(cmd.parseOptions,
                                                ['--count', '100'])
        lines = output.getvalue().splitlines()

        # Ensure that the original error is output.
        self.assertEqual(lines[0], 'Upgrader error:')
        self.assertTrue(len(lines) > 2)

        oldType = oldapp.Sword
        newType = store._typeNameToMostRecentClass[oldType.typeName]
        msg = cmd.errorMessageFormat % (oldType.typeName, swordID,
                                        oldType.schemaVersion,
                                        newType.schemaVersion)
        self.assertTrue(lines[-1].startswith(msg))
Beispiel #6
0
    def test_axiomaticUpgradeExceptionBubbling(self):
        """
        Exceptions encountered by L{Upgrade.upgradeStore} are handled and
        re-raised as L{errors.ItemUpgradeError} with attributes indicating
        which L{Item} was being upgraded when the exception occurred.
        """
        choose(oldapp)
        swordID = oldapp.Sword(store=self.store,
                               name='longsword',
                               hurtfulness=4).storeID
        self.store.close()

        choose(brokenapp)
        self.store = store.Store(self.dbdir)

        cmd = Upgrade()
        cmd.parent = CommandStub(self.store, 'upgrade')
        cmd.count = 100

        err = self.assertRaises(errors.ItemUpgradeError,
                                callWithStdoutRedirect, cmd.upgradeStore,
                                self.store)

        self.assertTrue(
            err.originalFailure.check(brokenapp.UpgradersAreBrokenHere))

        oldType = item.declareLegacyItem(oldapp.Sword.typeName,
                                         oldapp.Sword.schemaVersion, {})
        self.assertEqual(err.storeID, swordID)
        self.assertIdentical(err.oldType, oldType)
        self.assertIdentical(err.newType, brokenapp.Sword)
Beispiel #7
0
 def test_successOutput(self):
     """
     Upon successful completion of the upgrade, L{Upgrade} writes a success
     message to stdout.
     """
     cmd = Upgrade()
     cmd.parent = CommandStub(self.store, 'upgrade')
     result, output = callWithStdoutRedirect(cmd.parseOptions, [])
     self.assertEqual(output.getvalue(), 'Upgrade complete\n')
Beispiel #8
0
 def test_successOutput(self):
     """
     Upon successful completion of the upgrade, L{Upgrade} writes a success
     message to stdout.
     """
     cmd = Upgrade()
     cmd.parent = CommandStub(self.store, 'upgrade')
     result, output = callWithStdoutRedirect(cmd.parseOptions, [])
     self.assertEqual(output.getvalue(), 'Upgrade complete\n')
Beispiel #9
0
    def test_axiomaticUpgradeEverything(self):
        """
        L{Upgrade.upgradeStore} upgrades all L{Item}s.
        """
        choose(oldapp)
        swordID = oldapp.Sword(
            store=self.store, name='broadsword', hurtfulness=5).storeID
        self.store.close()

        choose(deleteswordapp)

        cmd = Upgrade()
        cmd.parent = CommandStub(store.Store(self.dbdir), 'upgrade')

        result, output = callWithStdoutRedirect(
            cmd.parseOptions, ['--count', '100'])

        self.store = store.Store(self.dbdir)
        self.assertRaises(
            KeyError, self.store.getItemByID, swordID, autoUpgrade=False)
Beispiel #10
0
    def test_axiomaticUpgradeEverything(self):
        """
        L{Upgrade.upgradeStore} upgrades all L{Item}s.
        """
        choose(oldapp)
        swordID = oldapp.Sword(store=self.store,
                               name='broadsword',
                               hurtfulness=5).storeID
        self.store.close()

        choose(deleteswordapp)

        cmd = Upgrade()
        cmd.parent = CommandStub(store.Store(self.dbdir), 'upgrade')

        result, output = callWithStdoutRedirect(cmd.parseOptions,
                                                ['--count', '100'])

        self.store = store.Store(self.dbdir)
        self.assertRaises(KeyError,
                          self.store.getItemByID,
                          swordID,
                          autoUpgrade=False)