Skip to content

Commit

Permalink
Merge branch 'patch_doc_with_additional_data' into 'upstream'
Browse files Browse the repository at this point in the history
Patch document to api with additional fields

See merge request op/e-contracting/openprocurement.client.python!1
  • Loading branch information
VDigitall committed May 20, 2020
2 parents 5a1fc58 + 742e7be commit 0ab343d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions openprocurement_client/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -144,15 +144,15 @@ 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:
if key not in IGNORE_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)
Expand All @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions openprocurement_client/tests/tests_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0ab343d

Please sign in to comment.