def test_api_update_for_old_contract_proforma( self, mocked_downloader_factory_cls, mocked_client_cls, _): mocked_client, template_downloader, _ = prepare_mocks_handler_mocks( mocked_client_cls, mocked_downloader_factory_cls) updated_document = deepcopy(tender['documents'][1]) updated_document['previousVersions'] = [ deepcopy(tender['documents'][1]) ] updated_document['templateId'] = 'paper0000001' mocked_client.get_resource_item_subitem.return_value = munchify( {'data': updated_document}) prepare_template_downloader_result(template_downloader) custom_tender = deepcopy(tender) custom_template_docs = deepcopy(template_docs) custom_template_docs[0]['dateModified'] = date_newer_contract_proforma custom_template_docs[1]['dateModified'] = date_newer_contract_proforma custom_template_docs[2]['dateModified'] = date_newer_contract_proforma custom_tender['documents'] += custom_template_docs handler = TemplateUploaderHandler(self.config, 'cache_db') handler.process_resource(custom_tender) self.assertEqual(template_downloader.get_template_by_id.call_count, 1) self.assertEqual(mocked_client.update_document.call_count, 0) self.assertEqual(mocked_client.upload_document.call_count, 0)
def test_api_update_one_old_template(self, mocked_downloader_factory_cls, mocked_client_cls, _, mocked_bytesio): mocked_client, template_downloader, _ = prepare_mocks_handler_mocks( mocked_client_cls, mocked_downloader_factory_cls) updated_document = deepcopy(tender['documents'][1]) updated_document['previousVersions'] = [ deepcopy(tender['documents'][1]) ] mocked_client.get_resource_item_subitem.return_value = munchify( {'data': updated_document}) template_info = prepare_template_downloader_result(template_downloader) custom_tender = deepcopy(tender) custom_template_docs = deepcopy(template_docs) custom_template_docs[1]['dateModified'] = date_newer_contract_proforma custom_tender['documents'] += custom_template_docs wrapped_file = 'wrappedfile' mocked_bytesio.return_value = wrapped_file handler = TemplateUploaderHandler(self.config, 'cache_db') handler.process_resource(custom_tender) self.assertEqual(template_downloader.get_template_by_id.call_count, 1) cp_doc = handler.get_contract_proforma_documents(tender)[0] template_downloader.get_template_by_id.assert_called_with( cp_doc['templateId']) self.assertEqual(mocked_bytesio.call_count, 0) self.assertEqual(mocked_client.update_document.call_count, 0) self.assertEqual(mocked_client.upload_document.call_count, 0)
def test_api_upload_document(self, mocked_downloader_factory_cls, mocked_client_cls, _, mocked_bytesio): mocked_client, template_downloader, _ = prepare_mocks_handler_mocks( mocked_client_cls, mocked_downloader_factory_cls) mocked_client.get_resource_item_subitem.return_value = munchify( {'data': tender['documents'][1]}) template_info = prepare_template_downloader_result(template_downloader) wrapped_file = 'wrappedfile' mocked_bytesio.return_value = wrapped_file handler = TemplateUploaderHandler(self.config, 'cache_db') handler.process_resource(tender) self.assertEqual(template_downloader.get_template_by_id.call_count, 1) cp_doc = handler.get_contract_proforma_documents(tender)[0] template_downloader.get_template_by_id.assert_called_with( cp_doc['templateId']) calls = [ call(template_info['template']), call(template_info['scheme']), call(template_info['form']), ] mocked_bytesio.assert_has_calls(calls, any_order=True) self.assertEqual(mocked_client.upload_document.call_count, 3) doc = tender['documents'][1] additional_data = { 'documentOf': 'document', 'relatedItem': doc['id'], } calls = [ call(wrapped_file, tender['id'], doc_type='contractTemplate', additional_doc_data=additional_data), call(wrapped_file, tender['id'], doc_type='contractSchema', additional_doc_data=additional_data), call(wrapped_file, tender['id'], doc_type='contractForm', additional_doc_data=additional_data), ] mocked_client.upload_document.assert_has_calls(calls, any_order=True) self.assertEqual(mocked_client.update_document.call_count, 0)
def test_api_update_missed_file(self, mocked_downloader_factory_cls, mocked_client_cls, _, mocked_bytesio): mocked_client, template_downloader, _ = prepare_mocks_handler_mocks( mocked_client_cls, mocked_downloader_factory_cls) mocked_client.get_resource_item_subitem.return_value = munchify( {'data': tender['documents'][1]}) template_info = prepare_template_downloader_result(template_downloader) custom_tender = deepcopy(tender) custom_template_docs = deepcopy(template_docs) custom_template_docs.pop(1) custom_template_docs[0]['dateModified'] = date_newer_contract_proforma custom_template_docs[1]['dateModified'] = date_newer_contract_proforma custom_tender['documents'] += custom_template_docs wrapped_file = 'wrappedfile' mocked_bytesio.return_value = wrapped_file handler = TemplateUploaderHandler(self.config, 'cache_db') handler.process_resource(custom_tender) self.assertEqual(template_downloader.get_template_by_id.call_count, 1) cp_doc = handler.get_contract_proforma_documents(tender)[0] template_downloader.get_template_by_id.assert_called_with( cp_doc['templateId']) mocked_bytesio.assert_called_once_with(template_info['scheme']) self.assertEqual(mocked_client.upload_document.call_count, 1) doc = tender['documents'][1] additional_data = { 'documentOf': 'document', 'relatedItem': doc['id'], } mocked_client.upload_document.assert_called_once_with( wrapped_file, tender['id'], doc_type='contractSchema', additional_doc_data=additional_data) self.assertEqual(mocked_client.update_document.call_count, 0)