<s> from arangodb . tests . base import ExtendedTestCase <EOL> from arangodb . api import Database , Collection <EOL> from arangodb . query . simple import SimpleQuery <EOL> from arangodb . query . utils . document import create_document_from_result_dict <EOL> from arangodb . transaction . controller import TransactionController , Transaction <EOL> class TransactionTestCase ( ExtendedTestCase ) : <EOL> def setUp ( self ) : <EOL> self . database_name = '<STR_LIT>' <EOL> self . db = Database . create ( name = self . database_name ) <EOL> self . operating_collection = '<STR_LIT>' <EOL> self . test_1_col = Collection . create ( name = self . operating_collection ) <EOL> def tearDown ( self ) : <EOL> Collection . remove ( name = self . operating_collection ) <EOL> Database . remove ( name = self . database_name ) <EOL> def test_create_document ( self ) : <EOL> trans = Transaction ( collections = { <EOL> '<STR_LIT>' : [ <EOL> self . operating_collection , <EOL> ] <EOL> } ) <EOL> collection = trans . collection ( name = self . operating_collection ) <EOL> collection . create_document ( data = { <EOL> '<STR_LIT:test>' : '<STR_LIT:foo>' <EOL> } ) <EOL> ctrl = TransactionController ( ) <EOL> transaction_result = ctrl . start ( transaction = trans ) <EOL> transaction_doc = create_document_from_result_dict ( transaction_result [ '<STR_LIT:result>' ] , self . test_1_col . api ) <EOL> created_doc = SimpleQuery . get_by_example ( self . test_1_col , example_data = { <EOL> '<STR_LIT>' : transaction_doc . id <EOL> } ) <EOL> self . assertDocumentsEqual ( transaction_doc , created_doc ) <EOL> def test_update_document ( self ) : <EOL> doc = self . test_1_col . create_document ( ) <EOL> doc . foo = '<STR_LIT:bar>' <EOL> doc . save ( ) <EOL> trans = Transaction ( collections = { <EOL> '<STR_LIT>' : [ <EOL> self . operating_collection , <EOL> ] <EOL> } ) <EOL> new_foo_value = '<STR_LIT>' <EOL> collection = trans . collection ( self . operating_collection ) <EOL> collection . update_document ( doc_id = doc . id , data = { <EOL> '<STR_LIT:foo>' : new_foo_value <EOL> } ) <EOL> ctrl = TransactionController ( ) <EOL> ctrl . start ( transaction = trans ) <EOL> doc . retrieve ( ) <EOL> self . assertEqual ( doc . foo , new_foo_value ) </s>
