Example #1
0
 def test_after_request_uncaught_exception(self):
     commands.begin()
     key = 'test_after_request_uncaught_exception'
     database['txn'].insert({'_id': key})
     response = make_response('ack!', 500)
     handlers.transaction_after_request(response)
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 0)
     assert_equal(
         database['txn'].find({'_id': key}).count(),
         0,
     )
Example #2
0
 def test_after_request_uncaught_exception(self):
     commands.begin()
     key = 'test_after_request_uncaught_exception'
     database['txn'].insert({'_id': key})
     response = make_response('ack!', 500)
     handlers.transaction_after_request(response)
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 0)
     assert_equal(
         database['txn'].find({
             '_id': key
         }).count(),
         0,
     )
Example #3
0
 def test_after_request_lock_error(self):
     commands.begin()
     key = 'test_after_request_lock_error'
     database['txn'].insert({'_id': key})
     with app.test_request_context(content_type='application/json'):
         response = make_response('bob', 200)
         with mock.patch('framework.transactions.commands.commit') as mock_commit:
             mock_commit.side_effect = OperationFailure(messages.LOCK_ERROR)
             handlers.transaction_after_request(response)
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 0)
     assert_equal(
         database['txn'].find({'_id': key}).count(),
         0,
     )
Example #4
0
 def test_after_request_lock_error(self):
     commands.begin()
     key = 'test_after_request_lock_error'
     database['txn'].insert({'_id': key})
     with app.test_request_context(content_type='application/json'):
         response = make_response('bob', 200)
         with mock.patch(
                 'framework.transactions.commands.commit') as mock_commit:
             mock_commit.side_effect = OperationFailure(messages.LOCK_ERROR)
             handlers.transaction_after_request(response)
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 0)
     assert_equal(
         database['txn'].find({
             '_id': key
         }).count(),
         0,
     )
Example #5
0
 def process_response(self, request, response):
     """Commit transaction if it exists, rolling back in an
     exception occurs.
     """
     transaction_after_request(response, base_status_code_error=400)
     return response
Example #6
0
 def process_response(self, request, response):
     """Commit transaction if it exists, rolling back in an
     exception occurs.
     """
     transaction_after_request(response, base_status_code_error=400)
     return response