def test_mutex_handler_commit_last(): trm = TransactionsManager() commits = [] mh = TransactionHandlerMock({"commit": lambda: commits.append("A")}) th = TransactionHandlerMock({"commit": lambda: commits.append("B")}) trm.set_mutex_handler(mh) trm.add_transaction_handler(th) with trm.begin(): trm.commit() assert commits == ["B", "A"]
def test_commit(): trm = TransactionsManager() trh1 = TransactionHandlerMock({ "can_prepare_commit": MagicMock(return_value=True), "prepare_commit": MagicMock(return_value=True), }) trh2 = TransactionHandlerMock( {"can_prepare_commit": MagicMock(return_value=False)}) trm.add_transaction_handler(trh1) trm.add_transaction_handler(trh2) with trm.begin(): trm.commit() assert trh1.can_prepare_commit.called assert trh2.can_prepare_commit.called assert trh1.prepare_commit.called assert trh1.commit.called assert trh2.commit.called
def test_commit_not_begun(): trm = TransactionsManager() with pytest.raises(TransactionException): trm.commit()