# -*- coding: utf-8 -*-

from tests.base import ApiTestCase, fake

import mock
from nose.tools import *  # flake8: noqa

from api.base.middleware import TokuTransactionsMiddleware
from tests.base import ApiTestCase

class TestMiddlewareRollback(ApiTestCase):
    
    @mock.patch('api.base.middleware.commands')
    def test_400_error_causes_rollback(self, mock_commands):

        middleware = TokuTransactionsMiddleware()
        mock_response = mock.Mock()
        mock_response.status_code = 400
        middleware.process_response(mock.Mock(), mock_response)

        assert_is(mock_commands.rollback.assert_called_once_with(), None)


@@ -260,204 +260,564 @@
     
-%0A    @mock.patch('api.base.middleware.commands')%0A    def test_400_error_causes_rollback(self, mock_commands):%0A%0A        middleware = TokuTransactionsMiddleware()%0A        mock_response = mock.Mock()
+def setUp(self):%0A        super(TestMiddlewareRollback, self).setUp()%0A        self.middleware = TokuTransactionsMiddleware()%0A        self.mock_response = mock.Mock()%0A    %0A    @mock.patch('api.base.middleware.commands')%0A    def test_400_error_causes_rollback(self, mock_commands):%0A%0A        self.mock_response.status_code = 400%0A        self.middleware.process_response(mock.Mock(), self.mock_response)%0A%0A        assert_true(mock_commands.rollback.called)%0A%0A    @mock.patch('api.base.middleware.commands')%0A    def test_200_OK_causes_commit(self, mock_commands):%0A
 %0A   
@@ -821,16 +821,21 @@
         
+self.
 mock_res
@@ -846,33 +846,33 @@
 e.status_code = 
-4
+2
 00%0A        middl
@@ -866,16 +866,21 @@
         
+self.
 middlewa
@@ -912,16 +912,21 @@
 Mock(), 
+self.
 mock_res
@@ -952,10 +952,12 @@
 ert_
-is
+true
 (moc
@@ -971,47 +971,21 @@
 nds.
-rollback.assert_called_once_with(), None)
+commit.called)%0A
 %0A%0A

Clean up assert statements and add test for successful commit