Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Завантаження документів з додатковою інформацією #15

Open
wants to merge 4 commits into
base: upstream
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 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 Expand Up @@ -369,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}
Expand All @@ -383,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
Expand Down
31 changes: 31 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 Expand Up @@ -906,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()
Expand Down