Skip to content
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
5 changes: 5 additions & 0 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ class Options:
"registerExtract",
"registerFiscal",
"winningBid",
"contractTemplate",
"contractSchema",
"contractForm",
"contractData",
"contractProforma",
]
)
title = StringType(required=True) # A title of the document.
Expand Down
2 changes: 2 additions & 0 deletions src/openprocurement/tender/belowthreshold/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 39 additions & 2 deletions src/openprocurement/tender/belowthreshold/tests/award_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions src/openprocurement/tender/belowthreshold/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/openprocurement/tender/belowthreshold/tests/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down
23 changes: 23 additions & 0 deletions src/openprocurement/tender/belowthreshold/tests/document_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
6 changes: 5 additions & 1 deletion src/openprocurement/tender/cfaselectionua/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/openprocurement/tender/cfaselectionua/tests/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

# _____________________________________________________________________
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

# _____________________________________________________________________
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/openprocurement/tender/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 2 additions & 0 deletions src/openprocurement/tender/openuadefense/tests/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down