<s> from mongo_test import TestWithMongo <EOL> from biicode . server . store . mongo_server_store import MongoServerStore <EOL> from db_model_creator import ModelCreator <EOL> from biicode . server . publish . publish_service import PublishService <EOL> from biicode . server . store . generic_server_store import GenericServerStore <EOL> from mock import Mock <EOL> from biicode . common . exception import ServerInternalErrorException <EOL> from biicode . common . publish . publish_request import PublishRequest <EOL> from biicode . common . model . cells import SimpleCell <EOL> from biicode . common . model . blob import Blob <EOL> from biicode . common . model . content import Content <EOL> from biicode . common . model . brl . brl_block import BRLBlock <EOL> from biicode . common . model . symbolic . block_version import BlockVersion <EOL> from biicode . common . model . brl . block_cell_name import BlockCellName <EOL> from biicode . common . model . symbolic . block_version_table import BlockVersionTable <EOL> def publish_pack_add ( pack , block_cell_name , content_text ) : <EOL> name = BlockCellName ( block_cell_name ) <EOL> cell1 = SimpleCell ( name ) <EOL> pack . cells . add ( cell1 ) <EOL> pack . contents [ name . cell_name ] = Content ( load = Blob ( content_text ) ) <EOL> return cell1 <EOL> class PublishTransactionTest ( TestWithMongo ) : <EOL> _multiprocess_shared_ = True <EOL> def setUp ( self ) : <EOL> self . conn . drop_database ( self . _testMethodName ) <EOL> self . store = MongoServerStore ( self . conn , self . _testMethodName ) <EOL> self . mother = ModelCreator ( self . store ) <EOL> self . user = self . mother . make_test_user ( ) <EOL> self . p = PublishService ( self . store , self . user . ID ) <EOL> self . brl = BRLBlock ( '<STR_LIT>' % ( self . user . ID , self . user . ID ) ) <EOL> pack = PublishRequest ( BlockVersion ( self . brl , - <NUM_LIT:1> ) ) <EOL> pack . cells . append ( SimpleCell ( '<STR_LIT>' % self . user . ID ) ) <EOL> pack . cells . append ( SimpleCell ( '<STR_LIT>' % self . user . ID ) ) <EOL> pack . cells . append ( SimpleCell ( '<STR_LIT>' % self . user . ID ) ) <EOL> pack . contents [ '<STR_LIT>' ] = Content ( id_ = None , load = Blob ( '<STR_LIT>' ) ) <EOL> pack . contents [ '<STR_LIT>' ] = Content ( id_ = None , load = Blob ( '<STR_LIT>' ) ) <EOL> pack . contents [ '<STR_LIT>' ] = Content ( id_ = None , load = Blob ( '<STR_LIT>' ) ) <EOL> pack . deptable = BlockVersionTable ( ) <EOL> self . pack = pack <EOL> self . cell_collection = self . store . db [ GenericServerStore . PUBLISHED_CELL_ST ] <EOL> self . content_collection = self . store . db [ GenericServerStore . PUBLISHED_CONTENT_ST ] <EOL> self . block_collection = self . store . db [ GenericServerStore . BLOCK_ST ] <EOL> def tearDown ( self ) : <EOL> print '<STR_LIT>' % self . _testMethodName <EOL> self . conn . drop_database ( self . _testMethodName ) <EOL> def test_publish_success ( self ) : <EOL> self . p . publish ( self . pack ) <EOL> blocks = list ( self . block_collection . find ( ) ) <EOL> cells = list ( self . cell_collection . find ( ) ) <EOL> contents = list ( self . content_collection . find ( ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( contents ) ) <EOL> self . assertEqual ( <NUM_LIT:3> , len ( cells ) ) <EOL> self . assertEquals ( <NUM_LIT:1> , len ( blocks ) ) <EOL> self . assertNotransactionPending ( ) <EOL> def test_roll_back ( self ) : <EOL> self . p . _write_resources_to_db = Mock ( side_effect = Exception ( '<STR_LIT>' ) ) <EOL> cells_no = len ( list ( self . cell_collection . find ( ) ) ) <EOL> contents_no = len ( list ( self . content_collection . find ( ) ) ) <EOL> with self . assertRaises ( ServerInternalErrorException ) : <EOL> self . p . publish ( self . pack ) <EOL> cells = list ( self . cell_collection . find ( ) ) <EOL> contents = list ( self . content_collection . find ( ) ) <EOL> self . assertEqual ( cells_no , len ( cells ) ) <EOL> self . assertEqual ( contents_no , len ( contents ) ) <EOL> self . assertNotransactionPending ( ) <EOL> def assertNotransactionPending ( self ) : <EOL> dbcol = self . store . db [ self . store . BLOCK_TRANSACTIONS ] <EOL> transaction = dbcol . find_one ( { '<STR_LIT>' : str ( self . brl ) } ) <EOL> self . assertTrue ( transaction is None ) </s>
