Пример #1
0
    def test_process_response_aborts_transaction_not_managed(self):
        abort = self.mocker.replace("transaction.abort")
        commit = self.mocker.replace("transaction.commit")
        leave_transaction_management = self.mocker.replace(
            "django.db.transaction.leave_transaction_management")
        is_managed = self.mocker.replace(
            "django.db.transaction.is_managed")
        set_clean = self.mocker.replace(
            "django.db.transaction.set_clean")

        self.expect(is_managed()).result(False).count(2)
        # None of these methods should be called
        self.expect(commit()).count(0)
        self.expect(abort()).count(0)
        self.expect(set_clean()).count(0)
        self.expect(leave_transaction_management()).count(0)
        self.mocker.replay()

        zope_middleware = ZopeTransactionMiddleware()
        request = HttpRequest()
        response = HttpResponse()

        request.method = "GET"
        zope_middleware.process_response(request, response)

        # Try the same with a safe method.
        conf.settings.STORM_COMMIT_SAFE_METHODS = False
        zope_middleware = ZopeTransactionMiddleware()
        zope_middleware.process_response(request, response)
Пример #2
0
    def test_process_response_aborts_transaction_not_managed(self):
        abort = self.mocker.replace("transaction.abort")
        commit = self.mocker.replace("transaction.commit")
        leave_transaction_management = self.mocker.replace(
            "django.db.transaction.leave_transaction_management")
        is_managed = self.mocker.replace("django.db.transaction.is_managed")
        set_clean = self.mocker.replace("django.db.transaction.set_clean")

        self.expect(is_managed()).result(False).count(2)
        # None of these methods should be called
        self.expect(commit()).count(0)
        self.expect(abort()).count(0)
        self.expect(set_clean()).count(0)
        self.expect(leave_transaction_management()).count(0)
        self.mocker.replay()

        zope_middleware = ZopeTransactionMiddleware()
        request = HttpRequest()
        response = HttpResponse()

        request.method = "GET"
        zope_middleware.process_response(request, response)

        # Try the same with a safe method.
        conf.settings.STORM_COMMIT_SAFE_METHODS = False
        zope_middleware = ZopeTransactionMiddleware()
        zope_middleware.process_response(request, response)
Пример #3
0
    def test_process_response_commits_transaction_if_managed(self):
        commit = self.mocker.replace("transaction.commit")
        leave_transaction_management = self.mocker.replace(
            "django.db.transaction.leave_transaction_management")
        is_managed = self.mocker.replace(
            "django.db.transaction.is_managed")
        set_clean = self.mocker.replace(
            "django.db.transaction.set_clean")
        # We test three request methods
        self.expect(is_managed()).result(True).count(3)
        self.expect(commit()).count(3)
        self.expect(set_clean()).count(3)
        self.expect(leave_transaction_management()).count(3)
        self.mocker.replay()

        # Commit on all methods
        conf.settings.STORM_COMMIT_SAFE_METHODS = True

        zope_middleware = ZopeTransactionMiddleware()
        request = HttpRequest()
        response = HttpResponse()

        request.method = "GET"
        zope_middleware.process_response(request, response)
        request.method = "HEAD"
        zope_middleware.process_response(request, response)
        request.method = "POST"
        zope_middleware.process_response(request, response)
Пример #4
0
    def test_process_response_commits_transaction_if_managed(self):
        commit = self.mocker.replace("transaction.commit")
        leave_transaction_management = self.mocker.replace(
            "django.db.transaction.leave_transaction_management")
        is_managed = self.mocker.replace("django.db.transaction.is_managed")
        set_clean = self.mocker.replace("django.db.transaction.set_clean")
        # We test three request methods
        self.expect(is_managed()).result(True).count(3)
        self.expect(commit()).count(3)
        self.expect(set_clean()).count(3)
        self.expect(leave_transaction_management()).count(3)
        self.mocker.replay()

        # Commit on all methods
        conf.settings.STORM_COMMIT_SAFE_METHODS = True

        zope_middleware = ZopeTransactionMiddleware()
        request = HttpRequest()
        response = HttpResponse()

        request.method = "GET"
        zope_middleware.process_response(request, response)
        request.method = "HEAD"
        zope_middleware.process_response(request, response)
        request.method = "POST"
        zope_middleware.process_response(request, response)