def test_report_result(self, mock_raise, mock_request): auction_doc = Munch({ 'id': uuid4().hex, # this is auction id 'status': 'complete', 'merchandisingObject': uuid4().hex }) lc = mock.MagicMock() lot = munchify({ 'data': { 'id': auction_doc['merchandisingObject'], 'lotIdentifier': u'Q81318b19827', 'status': u'active.auction', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'] } }) lc.get_lot.return_value = lot convoy = Convoy(self.config) convoy.lots_client = lc convoy.assets_client = mock.MagicMock() convoy.report_results(auction_doc) convoy.lots_client.patch_resource_item.assert_called_with( auction_doc.merchandisingObject, {'data': { 'status': 'pending.sold' }}) auction_doc.status = 'pending.verification' convoy.report_results(auction_doc) convoy.lots_client.patch_resource_item.assert_called_with( auction_doc.merchandisingObject, {'data': { 'status': 'active.salable' }})
def test_prepare_auction(self, mock_raise, mock_request): a_doc = Munch({ 'id': uuid4().hex, # this is auction id 'merchandisingObject': uuid4().hex }) api_auction_doc = { 'data': { 'id': a_doc['id'], 'status': 'pending.verifcation', 'merchandisingObject': a_doc['merchandisingObject'] } } lc = mock.MagicMock() lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'lotIdentifier': u'Q81318b19827', 'status': u'verification', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'] } }) api_client = mock.MagicMock() api_client.get_resource_item.return_value = munchify(api_auction_doc) convoy = Convoy(self.config) convoy.api_client = api_client convoy.lots_client = lc auction_doc = convoy.prepare_auction(a_doc) self.assertEqual(None, auction_doc) convoy.lots_client.get_lot.assert_called_with( a_doc['merchandisingObject']) # Preparing for test with valid status and documents with open('{}/asset.json'.format(self.test_files_path), 'r') as af: asset_dict = json.loads(af.read()) with open('{}/register_response.json'.format(self.test_files_path), 'r') as rf: register_response_dict = json.loads(rf.read()) # Prepare mocked clients mock_rc = mock.MagicMock() mock_rc.get_asset.return_value = munchify(asset_dict) mock_rc.ds_client.register_document_upload.return_value = \ munchify(register_response_dict) asset_ids = ['580d38b347134ac6b0ee3f04e34b9770'] convoy.assets_client = mock_rc lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'lotIdentifier': u'Q81318b19827', 'status': u'active.salable', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'] } }) items, documents = convoy._create_items_from_assets(asset_ids) convoy._create_items_from_assets = mock.MagicMock( return_value=(items, documents)) # Needed to call mock function before prepare_auction, to # check if parameted of this call and call from prepare_auction is equal expected = {'data': {'items': items, 'dgfID': u'Q81318b19827'}} # convoy.api_client.patch_resource_item(expected) # convoy.prepare_auction(a_doc) lot = convoy._receive_lot(a_doc) convoy._form_auction(lot, a_doc) convoy.api_client.patch_resource_item.assert_called_with( a_doc['id'], expected) convoy._activate_auction(lot, a_doc) self.assertEqual(convoy.documents_transfer_queue.qsize(), 2) convoy.lots_client.get_lot.assert_called_with( a_doc['merchandisingObject']) convoy.lots_client.patch_resource_item.assert_called_with( a_doc['merchandisingObject'], {'data': { 'status': 'active.auction' }}) convoy._create_items_from_assets.assert_called_with(asset_ids) patched_api_auction_doc = {'data': {'status': 'active.tendering'}} convoy.api_client.get_resource_item.assert_called_with(a_doc['id']) convoy.api_client.patch_resource_item.assert_called_with( api_auction_doc['data']['id'], patched_api_auction_doc) convoy.api_client.create_resource_item_subitem.assert_called_with( a_doc['id'], {'data': documents[1]}, 'documents') # convoy.prepare_auction(a_doc) with active.awaiting lot lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'lotIdentifier': u'Q81318b19827', 'status': u'active.awaiting', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'], 'auctions': [a_doc['id']] } }) items, documents = convoy._create_items_from_assets(asset_ids) convoy._create_items_from_assets = mock.MagicMock( return_value=(items, documents)) lot = convoy._receive_lot(a_doc) self.assertEqual(len(lot.auctions), 1) convoy._form_auction(lot, a_doc) convoy.api_client.patch_resource_item.assert_called_with( a_doc['id'], expected) convoy._activate_auction(lot, a_doc) self.assertEqual(convoy.documents_transfer_queue.qsize(), 2) convoy.lots_client.get_lot.assert_called_with( a_doc['merchandisingObject']) convoy.lots_client.patch_resource_item.assert_called_with( a_doc['merchandisingObject'], {'data': { 'status': 'active.auction' }}) convoy._create_items_from_assets.assert_called_with(asset_ids) convoy.api_client.get_resource_item.assert_called_with(a_doc['id']) convoy.api_client.patch_resource_item.assert_called_with( api_auction_doc['data']['id'], patched_api_auction_doc) convoy.api_client.create_resource_item_subitem.assert_called_with( a_doc['id'], {'data': documents[1]}, 'documents') # convoy.prepare_auction(a_doc) with active.auction lot lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'lotIdentifier': u'Q81318b19827', 'status': u'active.auction', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'], 'auctions': [a_doc['id']] } }) convoy._receive_lot(a_doc) patched_api_auction_doc = {'data': {'status': 'active.tendering'}} convoy.api_client.patch_resource_item.assert_called_with( api_auction_doc['data']['id'], patched_api_auction_doc)
def test_prepare_auction(self): a_doc = Munch({ 'id': uuid4().hex, # this is auction id 'merchandisingObject': uuid4().hex }) api_auction_doc = { 'data': { 'id': a_doc['id'], 'status': 'pending.verifcation', 'merchandisingObject': a_doc['merchandisingObject'] } } lc = mock.MagicMock() lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'status': u'verification', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'] } }) api_client = mock.MagicMock() api_client.get_resource_item.return_value = munchify(api_auction_doc) convoy = Convoy(self.config) convoy.api_client = api_client convoy.lots_client = lc auction_doc = convoy.prepare_auction(a_doc) self.assertEqual(None, auction_doc) convoy.lots_client.get_lot.assert_called_with( a_doc['merchandisingObject']) # Preparing for test with valid status and documents with open('{}/asset.json'.format(self.test_files_path), 'r') as af: asset_dict = json.loads(af.read()) with open('{}/register_response.json'.format(self.test_files_path), 'r') as rf: register_response_dict = json.loads(rf.read()) # Prepare mocked clients mock_rc = mock.MagicMock() mock_rc.get_asset.return_value = munchify(asset_dict) mock_rc.ds_client.register_document_upload.return_value = \ munchify(register_response_dict) asset_ids = ['580d38b347134ac6b0ee3f04e34b9770'] convoy.assets_client = mock_rc lc.get_lot.return_value = munchify({ 'data': { 'id': a_doc['merchandisingObject'], 'status': u'active.salable', 'assets': ['580d38b347134ac6b0ee3f04e34b9770'] } }) items, documents = convoy._create_items_from_assets(asset_ids) convoy._create_items_from_assets = mock.MagicMock( return_value=(items, documents)) auction_doc = convoy.prepare_auction(a_doc) self.assertEqual(convoy.documents_transfer_queue.qsize(), 2) convoy.lots_client.get_lot.assert_called_with( a_doc['merchandisingObject']) convoy.lots_client.patch_resource_item.assert_called_with( a_doc['merchandisingObject'], {'data': { 'status': 'active.auction' }}) convoy._create_items_from_assets.assert_called_with(asset_ids) patched_api_auction_doc = {'data': {'status': 'active.tendering'}} convoy.api_client.get_resource_item.assert_called_with(a_doc['id']) convoy.api_client.patch_resource_item.assert_called_with( api_auction_doc['data']['id'], patched_api_auction_doc) convoy.api_client.create_resource_item_subitem.assert_called_with( a_doc['id'], {'data': documents[1]}, 'documents')