From 742e7be2b6bb8fae3fced38ce0a3a9d8f0781705 Mon Sep 17 00:00:00 2001 From: Oleksiy Veretiuk Date: Mon, 18 May 2020 14:42:34 +0300 Subject: [PATCH 1/2] Patch document to api with additional fields --- openprocurement_client/clients.py | 8 +++++--- openprocurement_client/tests/tests_resources.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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() From 3a40be108a29d675862bd0cbd66e077e35a4638d Mon Sep 17 00:00:00 2001 From: Oleksiy Veretiuk Date: Thu, 21 May 2020 11:35:03 +0300 Subject: [PATCH 2/2] Add additional doc data functionality for update_document --- openprocurement_client/clients.py | 4 ++-- openprocurement_client/tests/tests_resources.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/openprocurement_client/clients.py b/openprocurement_client/clients.py index c3e0d7f..c1d851a 100755 --- a/openprocurement_client/clients.py +++ b/openprocurement_client/clients.py @@ -371,7 +371,7 @@ def patch_document(self, resource_item_id, document_data, document_id, @verify_file def update_document(self, file_, resource_item_id, document_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} @@ -385,7 +385,7 @@ def update_document(self, file_, resource_item_id, document_id, subitem_name=DOC url = '{}/{}/{}/{}'.format(self.prefix_path, resource_item_id, subitem_name, document_id) return self._upload_resource_file(url, file_=file_, headers=headers, method='PUT', use_ds_client=use_ds_client, - doc_registration=doc_registration, doc_type=doc_type) + doc_registration=doc_registration, doc_type=doc_type, additional_doc_data=additional_doc_data) ########################################################################### # UPLOAD CLIENT METHODS diff --git a/openprocurement_client/tests/tests_resources.py b/openprocurement_client/tests/tests_resources.py index 095cc9f..ec93860 100644 --- a/openprocurement_client/tests/tests_resources.py +++ b/openprocurement_client/tests/tests_resources.py @@ -922,6 +922,21 @@ def test_update_tender_document(self): ) self.assertEqual(doc.data.title, file_.name) + def test_update_tender_document_with_additional_doc_data(self): + setup_routing(self.app, routes=["tender_document_update"]) + file_ = StringIO() + file_.name = 'test_document.txt' + file_.write("test upload tender document text data") + file_.seek(0) + doc_data = {'documentOf': 'documents', 'relatedItem': '1'}, + doc = self.client.update_document( + file_, self.limited_tender, + TEST_TENDER_KEYS_LIMITED.document_id, + doc_type='tenderNotice', + additional_doc_data=doc_data + ) + self.assertEqual(doc.data.title, file_.name) + def test_update_bid_document(self): setup_routing(self.app, routes=["tender_subpage_document_update"]) file_ = StringIO()