Example #1
0
 def setUp(self):
     currencyclient.Verbose = True
     currencyclient.CurrencyClient = currencyclient.FakeCurrencyClient
     self.destroyDb()
     self.client = currencyclient.FakeCurrencyClient()
     # Fake out the value on the starting serial so I can reuse the
     # tests completely from the previous test class.
     self.client.serial = 0
     self.client.getPage = self.getPage
     currencyclient.FakeCurrencyFailure = False
Example #2
0
    def test03_checkNote_checkNoteResultIsFalse(self):
        """test03_checkNote_checkNoteResultIsFalse

        The goal of this test is to cover the setting of result to
        failure.Failure() in checkNote().  We have to get a bit tricky
        with deferreds to cause this to happen.  Our chainBegin deferred
        is set up to raise an exception immediately in its callback, which
        will chain off to its own errBack.  Its errBack then calls
        checkNote.  Since there is already an error propogating through,
        the failure.Failure() will work properly to then, in turn, trigger
        the errBack of checkNotesDeferred.  Finally, we make sure the
        point is reached by having the usual rougue deferred that only
        gets called back by the verification process."""
        class PropogatedException(Exception):
            pass

        self.client = currencyclient.FakeCurrencyClient()
        self.client.check_note_result = False

        forceTimeoutErrorIfNotCalledBack = defer.Deferred()

        def verifyError(err):
            self.assertEquals(err.check(PropogatedException),
                              PropogatedException)
            self.assertEquals(err.getErrorMessage(),
                              "this exception ends up in checknotes errback")
            forceTimeoutErrorIfNotCalledBack.callback(True)
            if hasattr(self, 'client'):
                self.client.check_note_result = True

        def executeCheckNote(value):
            self.assertEquals(value.check(PropogatedException),
                              PropogatedException)
            self.assertEquals(value.getErrorMessage(),
                              "this exception ends up in checknotes errback")

            checkNotesDeferred = self.client.checkNote(None)
            checkNotesDeferred.addErrback(verifyError)
            return checkNotesDeferred

        def propogateError(value):
            raise PropogatedException(
                "this exception ends up in checknotes errback")

        chainBegin = defer.Deferred()
        chainBegin.addCallback(propogateError)
        chainBegin.addErrback(executeCheckNote)
        chainBegin.callback(True)

        return forceTimeoutErrorIfNotCalledBack
Example #3
0
    def test04_commit_commitResultIsFalse(self):
        """test04_commit_commitResultIsFalse
        This test is nearly identical to
        test03_checkNote_checkNoteResultIsFalse, since the methods work
        very similarily."""
        class PropogatedException(Exception):
            pass

        self.client = currencyclient.FakeCurrencyClient()
        self.client.commit_result = False

        forceTimeoutErrorIfNotCalledBack = defer.Deferred()

        def verifyError(err):
            self.assertEquals(err.check(PropogatedException),
                              PropogatedException)
            self.assertEquals(err.getErrorMessage(),
                              "this exception ends up in commit errback")
            forceTimeoutErrorIfNotCalledBack.callback(True)
            if hasattr(self, 'client'):
                self.client.commit_result = True

        def executeCommit(value):
            self.assertEquals(value.check(PropogatedException),
                              PropogatedException)
            self.assertEquals(value.getErrorMessage(),
                              "this exception ends up in commit errback")

            commitDeferred = self.client.commit(None, None)
            commitDeferred.addErrback(verifyError)
            return commitDeferred

        def propogateError(value):
            raise PropogatedException(
                "this exception ends up in commit errback")

        chainBegin = defer.Deferred()
        chainBegin.addCallback(propogateError)
        chainBegin.addErrback(executeCommit)
        chainBegin.callback(True)
        return forceTimeoutErrorIfNotCalledBack