diff --git a/src/openprocurement/api/models.py b/src/openprocurement/api/models.py index 568b8e4a9a..ca075350a2 100644 --- a/src/openprocurement/api/models.py +++ b/src/openprocurement/api/models.py @@ -520,6 +520,11 @@ class Options: "registerExtract", "registerFiscal", "winningBid", + "contractTemplate", + "contractSchema", + "contractForm", + "contractData", + "contractProforma", ] ) title = StringType(required=True) # A title of the document. diff --git a/src/openprocurement/tender/belowthreshold/tests/award.py b/src/openprocurement/tender/belowthreshold/tests/award.py index 5e4aff11f8..6d88a69962 100644 --- a/src/openprocurement/tender/belowthreshold/tests/award.py +++ b/src/openprocurement/tender/belowthreshold/tests/award.py @@ -64,6 +64,7 @@ # TenderAwardDocumentResourceTest not_found_award_document, create_tender_award_document, + create_tender_award_with_the_invalid_document_type, put_tender_award_document, patch_tender_award_document, create_award_document_bot, @@ -95,6 +96,7 @@ class TenderAwardComplaintResourceTestMixin(object): class TenderAwardDocumentResourceTestMixin(object): test_not_found_award_document = snitch(not_found_award_document) test_create_tender_award_document = snitch(create_tender_award_document) + test_create_tender_award_with_the_invalid_document_type = snitch(create_tender_award_with_the_invalid_document_type) test_put_tender_award_document = snitch(put_tender_award_document) test_patch_tender_award_document = snitch(patch_tender_award_document) test_create_award_document_bot = snitch(create_award_document_bot) diff --git a/src/openprocurement/tender/belowthreshold/tests/award_blanks.py b/src/openprocurement/tender/belowthreshold/tests/award_blanks.py index f040dc25c6..9aaf09b570 100644 --- a/src/openprocurement/tender/belowthreshold/tests/award_blanks.py +++ b/src/openprocurement/tender/belowthreshold/tests/award_blanks.py @@ -4,10 +4,12 @@ from webtest import AppError import mock import dateutil.parser - +import re +import ast +from copy import deepcopy from openprocurement.api.utils import get_now from openprocurement.tender.belowthreshold.tests.base import ( - test_organization, test_draft_claim, test_claim, test_cancellation + test_organization, test_draft_claim, test_claim, test_cancellation, test_tender_document_data ) @@ -590,6 +592,41 @@ def create_tender_award_no_scale(self): self.assertEqual(response.content_type, "application/json") self.assertNotIn("scale", response.json["data"]["suppliers"][0]) +def create_tender_award_with_the_invalid_document_type(self): + document_data = deepcopy(test_tender_document_data) + document_data["url"] = self.generate_docservice_url() + document_data["hash"] = "md5:" + "0" * 32 + document_data["documentType"] = "smth" + + response = self.app.post( + "/tenders/{}/awards/{}/documents?acc_token={}".format(self.tender_id, self.award_id, self.tender_token), + upload_files=[("file", "name.doc", "content")], + ) + self.assertEqual(response.status, "201 Created") + self.assertEqual(response.content_type, "application/json") + + doc_id = response.json["data"]["id"] + self.assertIn(doc_id, response.headers["Location"]) + self.assertEqual(u"name.doc", response.json["data"]["title"]) + response = self.app.patch_json( + "/tenders/{}/awards/{}/documents/{}?acc_token={}".format(self.tender_id, self.award_id,doc_id, self.tender_token), + {"data": {"documentType": "smth"}}, + status=422, + ) + self.assertEqual(response.status, "422 Unprocessable Entity") + self.assertEqual(response.content_type, "application/json") + response_doctype_dict = re.findall(r"\[.*\]",response.json["errors"][0]["description"][0])[0] + response_doctype_dict = ast.literal_eval(response_doctype_dict) + response_doctype_dict = [n.strip() for n in response_doctype_dict] + self.assertListEqual( + response_doctype_dict, + ["tenderNotice","awardNotice","contractNotice","notice","biddingDocuments","technicalSpecifications", + "evaluationCriteria","clarifications","shortlistedFirms","riskProvisions","billOfQuantity","bidders", + "conflictOfInterest","debarments","evaluationReports","winningBid","complaints","contractSigned", + "contractArrangements","contractSchedule","contractAnnexe","contractGuarantees","subContract", + "eligibilityCriteria","contractProforma","commercialProposal","qualificationDocuments", + "eligibilityDocuments","registerExtract","registerFiscal","winningBid","contractTemplate", + "contractSchema","contractForm","contractData","contractProforma"]) # TenderLotAwardResourceTest diff --git a/src/openprocurement/tender/belowthreshold/tests/base.py b/src/openprocurement/tender/belowthreshold/tests/base.py index 01b66ab0c8..ad2bfb6a25 100644 --- a/src/openprocurement/tender/belowthreshold/tests/base.py +++ b/src/openprocurement/tender/belowthreshold/tests/base.py @@ -84,6 +84,15 @@ "procurementMethodType": "belowThreshold", "milestones": test_milestones, } + +test_tender_document_data = { + "url": "http://ds.prozorro.local/get/b97562e3f33c493297fd14dd6d8c50f0?KeyID=a8968c46&Signature=3OV7QC7f%2ByfcGTvpy0tf%2FaM%2BFRI6kkg1ImfEJlfAx5qi%2FLY7IIj7TFqtxgaPrzdd%2BWIOCe3O5Q7WhXkOdCB9CQ%3D%3D", + "documentType":"tenderNotice", + "title": "Notice.pdf", + "hash": "md5:00000000000000000000000000000000", + "format": "application/pdf" +} + if SANDBOX_MODE: test_tender_data["procurementMethodDetails"] = "quick, accelerator=1440" test_features_tender_data = test_tender_data.copy() diff --git a/src/openprocurement/tender/belowthreshold/tests/document.py b/src/openprocurement/tender/belowthreshold/tests/document.py index 9f6960bae1..cc08204987 100644 --- a/src/openprocurement/tender/belowthreshold/tests/document.py +++ b/src/openprocurement/tender/belowthreshold/tests/document.py @@ -11,6 +11,7 @@ create_tender_document, put_tender_document, patch_tender_document, + create_document_with_the_invalid_document_type, # TenderDocumentWithDSResourceTest create_tender_document_error, create_tender_document_json_invalid, @@ -33,6 +34,7 @@ class TenderDocumentWithDSResourceTestMixin(object): test_create_tender_document_json_invalid = snitch(create_tender_document_json_invalid) test_create_tender_document_json = snitch(create_tender_document_json) test_put_tender_document_json = snitch(put_tender_document_json) + test_create_document_with_the_invalid_document_type = snitch(create_document_with_the_invalid_document_type) class TenderDocumentResourceTest(TenderContentWebTest, TenderDocumentResourceTestMixin): diff --git a/src/openprocurement/tender/belowthreshold/tests/document_blanks.py b/src/openprocurement/tender/belowthreshold/tests/document_blanks.py index ae12c06efb..a2039cb1e1 100644 --- a/src/openprocurement/tender/belowthreshold/tests/document_blanks.py +++ b/src/openprocurement/tender/belowthreshold/tests/document_blanks.py @@ -2,8 +2,13 @@ from email.header import Header # TenderDocumentResourceTest +import re +import ast from mock import patch +from copy import deepcopy from openprocurement.tender.core.tests.base import bad_rs_request, srequest +from openprocurement.tender.belowthreshold.tests.base import test_tender_document_data +from openprocurement.api.models import Document as BaseDocument def not_found(self): @@ -888,3 +893,21 @@ def lot_patch_tender_document_json_items_none(self): errors = {error["name"]: error["description"] for error in response.json["errors"]} self.assertEqual(errors["documents"][0], {"relatedItem": ["relatedItem should be one of items"]}) + + +def create_document_with_the_invalid_document_type(self): + """ + A test checks if errors raise in case of processing document with the invalid document type (documentType field). + """ + document_data = deepcopy(test_tender_document_data) + document_data["url"] = self.generate_docservice_url() + document_data["hash"] = "md5:" + "0" * 32 + document_data["documentType"] = "smth" + + response = self.app.post_json("/tenders/{}/documents?acc_token={}".format( + self.tender_id, self.tender_token),{"data":document_data}, status=422) + self.assertEqual(response.status, "422 Unprocessable Entity") + self.assertEqual(response.content_type, "application/json") + response_doctype_dict = re.findall(r"\[.*\]",response.json["errors"][0]["description"][0])[0] + response_doctype_dict = ast.literal_eval(response_doctype_dict) + response_doctype_dict = [n.strip() for n in response_doctype_dict] \ No newline at end of file diff --git a/src/openprocurement/tender/cfaselectionua/tests/award.py b/src/openprocurement/tender/cfaselectionua/tests/award.py index 094debba84..e87f4e62fb 100644 --- a/src/openprocurement/tender/cfaselectionua/tests/award.py +++ b/src/openprocurement/tender/cfaselectionua/tests/award.py @@ -3,7 +3,10 @@ from copy import deepcopy from openprocurement.api.tests.base import snitch -from openprocurement.tender.belowthreshold.tests.award_blanks import patch_tender_lot_award_lots_none +from openprocurement.tender.belowthreshold.tests.award_blanks import ( + patch_tender_lot_award_lots_none, + create_tender_award_with_the_invalid_document_type, +) from openprocurement.tender.cfaselectionua.adapters.configurator import TenderCfaSelectionUAConfigurator from openprocurement.tender.cfaselectionua.tests.base import ( TenderContentWebTest, @@ -53,6 +56,7 @@ class TenderAwardResourceTestMixin(object): class TenderAwardDocumentResourceTestMixin(object): test_not_found_award_document = snitch(not_found_award_document) test_create_tender_award_document = snitch(create_tender_award_document) + test_create_tender_award_with_the_invalid_document_type = snitch(create_tender_award_with_the_invalid_document_type) test_put_tender_award_document = snitch(put_tender_award_document) test_patch_tender_award_document = snitch(patch_tender_award_document) test_create_award_document_bot = snitch(create_award_document_bot) diff --git a/src/openprocurement/tender/cfaselectionua/tests/document.py b/src/openprocurement/tender/cfaselectionua/tests/document.py index d247628e5e..0912279f48 100644 --- a/src/openprocurement/tender/cfaselectionua/tests/document.py +++ b/src/openprocurement/tender/cfaselectionua/tests/document.py @@ -10,6 +10,7 @@ create_tender_document_json_invalid, create_tender_document_json, put_tender_document_json, + create_document_with_the_invalid_document_type, ) from openprocurement.tender.cfaselectionua.tests.document_blanks import ( @@ -34,6 +35,7 @@ class TenderDocumentWithDSResourceTestMixin(object): test_create_tender_document_json_invalid = snitch(create_tender_document_json_invalid) test_create_tender_document_json = snitch(create_tender_document_json) test_put_tender_document_json = snitch(put_tender_document_json) + test_create_document_with_the_invalid_document_type = snitch(create_document_with_the_invalid_document_type) class TenderDocumentResourceTest(TenderContentWebTest, TenderDocumentResourceTestMixin): diff --git a/src/openprocurement/tender/competitivedialogue/tests/stage1/document.py b/src/openprocurement/tender/competitivedialogue/tests/stage1/document.py index 1845a6349f..d898bdd107 100644 --- a/src/openprocurement/tender/competitivedialogue/tests/stage1/document.py +++ b/src/openprocurement/tender/competitivedialogue/tests/stage1/document.py @@ -12,6 +12,7 @@ from openprocurement.tender.competitivedialogue.tests.stage1.document_blanks import ( put_tender_document, patch_tender_document, + create_document_with_the_invalid_document_type, ) # _____________________________________________________________________ @@ -61,7 +62,8 @@ class DialogUADocumentResourceTest(BaseCompetitiveDialogUAContentWebTest, Tender test_put_tender_document = snitch(put_tender_document) test_patch_tender_document = snitch(patch_tender_document) - + test_put_tender_json_document_of_document =snitch(put_tender_json_document_of_document) + test_create_document_with_the_invalid_document_type = snitch(create_document_with_the_invalid_document_type) class DialogUADocumentWithDSResourceTest(DialogUADocumentResourceTest): docservice = True diff --git a/src/openprocurement/tender/competitivedialogue/tests/stage1/document_blanks.py b/src/openprocurement/tender/competitivedialogue/tests/stage1/document_blanks.py index 0d21682b24..7460ac7639 100644 --- a/src/openprocurement/tender/competitivedialogue/tests/stage1/document_blanks.py +++ b/src/openprocurement/tender/competitivedialogue/tests/stage1/document_blanks.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- from email.header import Header +import re +import ast +from openprocurement.tender.belowthreshold.tests.base import test_tender_document_data +from openprocurement.api.models import Document as BaseDocument # DialogEUDocumentResourceTest @@ -244,3 +248,30 @@ def patch_tender_document(self): self.assertEqual(response.content_type, "application/json") self.assertEqual(doc_id, response.json["data"]["id"]) self.assertEqual("document description", response.json["data"]["description"]) + + +def create_document_with_the_invalid_document_type(self): + """ + A test checks if errors raise in case of processing document with the invalid document type (documentType field). + """ + response = self.app.post( + "/tenders/{}/documents?acc_token={}".format(self.tender_id, self.tender_token), + upload_files=[("file", str(Header(u"укр.doc", "utf-8")), "content")], + ) + self.assertEqual(response.status, "201 Created") + self.assertEqual(response.content_type, "application/json") + doc_id = response.json["data"]["id"] + self.assertIn(doc_id, response.headers["Location"]) + self.assertEqual(u"укр.doc", response.json["data"]["title"]) + + # Try connect document with lot, without description in params + response = self.app.patch_json( + "/tenders/{}/documents/{}?acc_token={}".format(self.tender_id, doc_id, self.tender_token), + {"data": {"documentType": "smth"}}, + status=422, + ) + self.assertEqual(response.status, "422 Unprocessable Entity") + self.assertEqual(response.content_type, "application/json") + response_doctype_dict = re.findall(r"\[.*\]",response.json["errors"][0]["description"][0])[0] + response_doctype_dict = ast.literal_eval(response_doctype_dict) + response_doctype_dict = [n.strip() for n in response_doctype_dict] diff --git a/src/openprocurement/tender/competitivedialogue/tests/stage2/document.py b/src/openprocurement/tender/competitivedialogue/tests/stage2/document.py index c808b634a3..b90fd97dfa 100644 --- a/src/openprocurement/tender/competitivedialogue/tests/stage2/document.py +++ b/src/openprocurement/tender/competitivedialogue/tests/stage2/document.py @@ -12,6 +12,7 @@ from openprocurement.tender.competitivedialogue.tests.stage1.document_blanks import ( put_tender_document, patch_tender_document, + create_document_with_the_invalid_document_type, ) # _____________________________________________________________________ @@ -48,7 +49,7 @@ class TenderStage2EUDocumentResourceTest(BaseCompetitiveDialogEUStage2ContentWeb test_put_tender_document = snitch(put_tender_document) test_patch_tender_document = snitch(patch_tender_document) - + test_create_document_with_the_invalid_document_type = snitch(create_document_with_the_invalid_document_type) class TenderStage2DocumentWithDSResourceTest(TenderStage2EUDocumentResourceTest, TenderDocumentResourceTestMixin): docservice = True @@ -66,7 +67,6 @@ class TenderStage2UADocumentResourceTest(BaseCompetitiveDialogUAStage2ContentWeb test_put_tender_document = snitch(put_tender_document) test_patch_tender_document = snitch(patch_tender_document) - class TenderStage2UADocumentWithDSResourceTest(TenderStage2UADocumentResourceTest, TenderDocumentResourceTestMixin): docservice = True diff --git a/src/openprocurement/tender/core/models.py b/src/openprocurement/tender/core/models.py index f4ff649235..89272658b6 100644 --- a/src/openprocurement/tender/core/models.py +++ b/src/openprocurement/tender/core/models.py @@ -148,8 +148,6 @@ def export_loop(self, model_instance, field_converter, role=None, print_none=Fal class Document(BaseDocument): - documentOf = StringType(required=True, choices=["tender", "item", "lot"], default="tender") - def validate_relatedItem(self, data, relatedItem): if not relatedItem and data.get("documentOf") in ["item", "lot"]: raise ValidationError(u"This field is required.") diff --git a/src/openprocurement/tender/openuadefense/tests/document.py b/src/openprocurement/tender/openuadefense/tests/document.py index 669aebc733..3bddd0afe0 100644 --- a/src/openprocurement/tender/openuadefense/tests/document.py +++ b/src/openprocurement/tender/openuadefense/tests/document.py @@ -13,6 +13,7 @@ create_tender_document_json_invalid, create_tender_document_json, put_tender_document_json, + create_document_with_the_invalid_document_type, ) from openprocurement.tender.openuadefense.tests.base import BaseTenderUAContentWebTest @@ -33,6 +34,7 @@ class TenderDocumentWithDSResourceTest(TenderDocumentResourceTest): test_create_tender_document_json_invalid = snitch(create_tender_document_json_invalid) test_create_tender_document_json = snitch(create_tender_document_json) test_put_tender_document_json = snitch(put_tender_document_json) + test_create_document_with_the_invalid_document_type = snitch(create_document_with_the_invalid_document_type) def suite():