Beispiel #1
0
 def test_before_request_transaction_active(self):
     commands.begin()
     transactions_before = database.command('showLiveTransactions')
     handlers.transaction_before_request()
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 1)
     assert_not_equal(
         transactions_before['transactions'][0]['txnid'],
         transactions['transactions'][0]['txnid'],
     )
 def test_before_request_transaction_active(self):
     commands.begin()
     transactions_before = database.command('showLiveTransactions')
     handlers.transaction_before_request()
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 1)
     assert_not_equal(
         transactions_before['transactions'][0]['txnid'],
         transactions['transactions'][0]['txnid'],
     )
 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,
     )
Beispiel #4
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,
     )
 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,
     )
Beispiel #6
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,
     )
Beispiel #7
0
 def test_before_request(self):
     handlers.transaction_before_request()
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 1)
 def test_before_request(self):
     handlers.transaction_before_request()
     transactions = database.command('showLiveTransactions')
     assert_equal(len(transactions['transactions']), 1)