diff --git a/openprocurement_client/clients.py b/openprocurement_client/clients.py index 4e82db5..c3e0d7f 100755 --- a/openprocurement_client/clients.py +++ b/openprocurement_client/clients.py @@ -131,7 +131,7 @@ def patch_document(self, obj, document): @verify_file def upload_document(self, file_, resource_item_id, subitem_name=DOCUMENTS, doc_type=None, use_ds_client=True, - doc_registration=True, depth_path=None, access_token=None): + doc_registration=True, depth_path=None, access_token=None, additional_doc_data=None): headers = None if access_token: headers = {'X-Access-Token': access_token} @@ -144,7 +144,7 @@ def upload_document(self, file_, resource_item_id, subitem_name=DOCUMENTS, doc_t url = '{}/{}/{}'.format(self.prefix_path, resource_item_id, subitem_name) return self._upload_resource_file(url, file_=file_, headers=headers, doc_registration=doc_registration, - doc_type=doc_type, use_ds_client=use_ds_client) + doc_type=doc_type, use_ds_client=use_ds_client, additional_doc_data=additional_doc_data) def _update_params(self, params): for key in params: @@ -152,7 +152,7 @@ def _update_params(self, params): self.params[key] = params[key] def _upload_resource_file(self, url, file_=None, headers=None, doc_type=None, method='POST', - use_ds_client=True, doc_registration=True): + use_ds_client=True, doc_registration=True, additional_doc_data=None): if hasattr(self, 'ds_client') and use_ds_client: if doc_registration: response = self.ds_client.document_upload_registered(file_=file_, headers=headers) @@ -161,6 +161,8 @@ def _upload_resource_file(self, url, file_=None, headers=None, doc_type=None, me payload = {'data': response['data']} if doc_type: payload['data']['documentType'] = doc_type + if additional_doc_data: + payload['data'].update(additional_doc_data) response = self._create_resource_item(url, headers=headers, payload=payload, method=method) else: if use_ds_client: diff --git a/openprocurement_client/tests/tests_resources.py b/openprocurement_client/tests/tests_resources.py index 3b33db2..095cc9f 100644 --- a/openprocurement_client/tests/tests_resources.py +++ b/openprocurement_client/tests/tests_resources.py @@ -783,6 +783,22 @@ def test_upload_tender_document_path_failed(self, mock_request): access_token=self.tender.access['token'] ) + def test_upload_tender_document_with_doc_data(self): + setup_routing(self.app, routes=["tender_document_create"]) + file_ = StringIO() + file_.name = 'test_document.txt' + file_.write("test upload tender document text data") + file_.seek(0) + + doc = self.client.upload_document( + file_, self.tender, + doc_type='tenderNotice', + additional_doc_data={'documentOf': 'documents', 'relatedItem': '1'}, + + ) + self.assertEqual(doc.data.title, file_.name) + self.assertEqual(doc.data.id, TEST_TENDER_KEYS.new_document_id) + def test_upload_qualification_document(self): setup_routing(self.app, routes=["tender_subpage_document_create"]) file_ = StringIO()