From d8c12a8bc31a3246e3f75b2093006959f5831396 Mon Sep 17 00:00:00 2001 From: Vitalii Martyniak Date: Tue, 17 Mar 2020 13:39:06 +0200 Subject: [PATCH] Add tests for upload contract docs in `pending.winnerSigning` status --- .../tender/belowthreshold/tests/contract.py | 27 +- .../belowthreshold/tests/contract_blanks.py | 897 +++++++++++++++++- .../tender/cfaselectionua/tests/contract.py | 18 + .../cfaselectionua/tests/contract_blanks.py | 170 ++++ .../tests/stage2/contract.py | 17 + .../tender/esco/tests/contract.py | 11 + .../tender/openeu/tests/contract.py | 11 + .../tender/openua/tests/contract.py | 11 + .../tender/openuadefense/tests/contract.py | 11 + 9 files changed, 1159 insertions(+), 14 deletions(-) diff --git a/src/openprocurement/tender/belowthreshold/tests/contract.py b/src/openprocurement/tender/belowthreshold/tests/contract.py index d9c220aeaa..f88314ff51 100644 --- a/src/openprocurement/tender/belowthreshold/tests/contract.py +++ b/src/openprocurement/tender/belowthreshold/tests/contract.py @@ -33,6 +33,15 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_supplier, patch_tender_contract_status_by_others, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, + lot2_create_tender_contract_document_by_supplier, + lot2_create_tender_contract_document_by_others, + lot2_put_tender_contract_document_by_supplier, + lot2_patch_tender_contract_document_by_supplier, ) @@ -198,6 +207,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = auth + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + class Tender2LotContractDocumentResourceTest(TenderContentWebTest): initial_status = "active.qualification" @@ -240,15 +255,21 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = auth - lot2_create_tender_contract_document = snitch(lot2_create_tender_contract_document) - lot2_put_tender_contract_document = snitch(lot2_put_tender_contract_document) - lot2_patch_tender_contract_document = snitch(lot2_patch_tender_contract_document) + test_lot2_create_tender_contract_document = snitch(lot2_create_tender_contract_document) + test_lot2_put_tender_contract_document = snitch(lot2_put_tender_contract_document) + test_lot2_patch_tender_contract_document = snitch(lot2_patch_tender_contract_document) + test_lot2_create_tender_contract_document_by_supplier = snitch(lot2_create_tender_contract_document_by_supplier) + test_lot2_create_tender_contract_document_by_others = snitch(lot2_create_tender_contract_document_by_others) + test_lot2_put_tender_contract_document_by_supplier = snitch(lot2_put_tender_contract_document_by_supplier) + test_lot2_patch_tender_contract_document_by_supplier = snitch(lot2_patch_tender_contract_document_by_supplier) def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TenderContractResourceTest)) suite.addTest(unittest.makeSuite(TenderContractDocumentResourceTest)) + suite.addTest(unittest.makeSuite(TenderContractVATNotIncludedResourceTest)) + suite.addTest(unittest.makeSuite(Tender2LotContractDocumentResourceTest)) return suite diff --git a/src/openprocurement/tender/belowthreshold/tests/contract_blanks.py b/src/openprocurement/tender/belowthreshold/tests/contract_blanks.py index d26e6fdac1..02cb7676f7 100644 --- a/src/openprocurement/tender/belowthreshold/tests/contract_blanks.py +++ b/src/openprocurement/tender/belowthreshold/tests/contract_blanks.py @@ -934,6 +934,17 @@ def not_found(self): def create_tender_contract_document(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + self.assertEqual(response.json["data"]["status"], "pending") + + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if "complaintPeriod" in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc["contracts"][0] and doc["contracts"][0]["value"]["valueAddedTaxIncluded"]: + doc["contracts"][0]["value"]["amountNet"] = str(float(doc["contracts"][0]["value"]["amount"]) - 1) + self.db.save(doc) + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], @@ -957,6 +968,32 @@ def create_tender_contract_document(self): self.assertEqual(doc_id, response.json["data"][0]["id"]) self.assertEqual("name.doc", response.json["data"][0]["title"]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + upload_files=[("file", "contract.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u"Tender onwer can't add document in current contract status", + u'location': u'body', + u'name': u'data'}]) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + + response = self.app.get( "/tenders/{}/contracts/{}/documents/{}?download=some_id".format(self.tender_id, self.contract_id, doc_id), status=404, @@ -1012,6 +1049,187 @@ def create_tender_contract_document(self): ) +def create_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + for bid in doc.get("bids", []): + if bid["id"] == bid_id and bid["status"] == "pending": + bid["status"] = "active" + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc['contracts'][0] and doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u"Supplier can't add document in current contract status", + u'location': u'body', + u'name': u'data'}]) + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_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("name.doc", response.json["data"]["title"]) + key = response.json["data"]["url"].split("?")[-1] + + response = self.app.get("/tenders/{}/contracts/{}/documents".format(self.tender_id, self.contract_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"][0]["id"]) + self.assertEqual("name.doc", response.json["data"][0]["title"]) + + response = self.app.get("/tenders/{}/contracts/{}/documents?all=true".format(self.tender_id, self.contract_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"][0]["id"]) + self.assertEqual("name.doc", response.json["data"][0]["title"]) + + response = self.app.get( + "/tenders/{}/contracts/{}/documents/{}?download=some_id".format(self.tender_id, self.contract_id, doc_id), + status=404, + ) + self.assertEqual(response.status, "404 Not Found") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["status"], "error") + self.assertEqual( + response.json["errors"], [{u"description": u"Not Found", u"location": u"url", u"name": u"download"}] + ) + + response = self.app.get( + "/tenders/{}/contracts/{}/documents/{}?{}".format(self.tender_id, self.contract_id, doc_id, key) + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/msword") + self.assertEqual(response.content_length, 7) + self.assertEqual(response.body, "content") + + response = self.app.get("/tenders/{}/contracts/{}/documents/{}".format(self.tender_id, self.contract_id, doc_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + self.assertEqual("name.doc", response.json["data"]["title"]) + + tender = self.db.get(self.tender_id) + tender["contracts"][-1]["status"] = "cancelled" + self.db.save(tender) + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + self.set_status("{}".format(self.forbidden_contract_document_modification_actions_status)) + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + +def create_tender_contract_document_by_others(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc['contracts'][0] and doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id!='{}'].owner_token".format(bid_id), doc)[0] + + # Bid owner + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u'Forbidden', u'location': u'url', u'name': u'permission'}]) + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Bid onwer + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], [{"location": "url", "name": "permission", "description": "Forbidden"}]) + + tender = self.db.get(self.tender_id) + tender["contracts"][-1]["status"] = "cancelled" + self.db.save(tender) + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], "Forbidden") + + self.set_status("{}".format(self.forbidden_contract_document_modification_actions_status)) + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], "Forbidden") + + def put_tender_contract_document(self): response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), @@ -1034,6 +1252,31 @@ def put_tender_contract_document(self): self.assertEqual(response.json["status"], "error") self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + upload_files=[("file", "name.doc", "content2")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.put( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token @@ -1113,9 +1356,45 @@ def put_tender_contract_document(self): ) -def patch_tender_contract_document(self): +def put_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + for bid in doc.get("bids", []): + if bid["id"] == bid_id and bid["status"] == "pending": + bid["status"] = "active" + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc['contracts'][0] and doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + + # Supplier response = self.app.post( - "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), upload_files=[("file", "name.doc", "content")], ) self.assertEqual(response.status, "201 Created") @@ -1123,23 +1402,282 @@ def patch_tender_contract_document(self): doc_id = response.json["data"]["id"] self.assertIn(doc_id, response.headers["Location"]) - response = self.app.patch_json( + response = self.app.put( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( - self.tender_id, self.contract_id, doc_id, self.tender_token + self.tender_id, self.contract_id, doc_id, bid_token ), - {"data": {"description": "document description"}}, + status=404, + upload_files=[("invalid_name", "name.doc", "content")], ) - self.assertEqual(response.status, "200 OK") + self.assertEqual(response.status, "404 Not Found") self.assertEqual(response.content_type, "application/json") - self.assertEqual(doc_id, response.json["data"]["id"]) + self.assertEqual(response.json["status"], "error") + self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) - response = self.app.get("/tenders/{}/contracts/{}/documents/{}".format(self.tender_id, self.contract_id, doc_id)) + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + upload_files=[("file", "name.doc", "content2")], + ) self.assertEqual(response.status, "200 OK") self.assertEqual(response.content_type, "application/json") self.assertEqual(doc_id, response.json["data"]["id"]) - self.assertEqual("document description", response.json["data"]["description"]) + key = response.json["data"]["url"].split("?")[-1] - tender = self.db.get(self.tender_id) + response = self.app.get( + "/tenders/{}/contracts/{}/documents/{}?{}".format(self.tender_id, self.contract_id, doc_id, key) + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/msword") + self.assertEqual(response.content_length, 8) + self.assertEqual(response.body, "content2") + + response = self.app.get("/tenders/{}/contracts/{}/documents/{}".format(self.tender_id, self.contract_id, doc_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + self.assertEqual("name.doc", response.json["data"]["title"]) + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + "content3", + content_type="application/msword", + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + key = response.json["data"]["url"].split("?")[-1] + + response = self.app.get( + "/tenders/{}/contracts/{}/documents/{}?{}".format(self.tender_id, self.contract_id, doc_id, key) + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/msword") + self.assertEqual(response.content_length, 8) + self.assertEqual(response.body, "content3") + + tender = self.db.get(self.tender_id) + tender["contracts"][-1]["status"] = "cancelled" + self.db.save(tender) + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + upload_files=[("file", "name.doc", "content3")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't update document in current contract status") + + self.set_status("{}".format(self.forbidden_contract_document_modification_actions_status)) + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + upload_files=[("file", "name.doc", "content3")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't update document in current contract status") + + +def put_tender_contract_document_by_others(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc['contracts'][0] and doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id!='{}'].owner_token".format(bid_id), doc)[0] + + # Bid onwer + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u'Forbidden', u'location': u'url', u'name': u'permission'}]) + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Bid owner + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u'Forbidden', u'location': u'url', u'name': u'permission'}]) + + +def patch_tender_contract_document(self): + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_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"]) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + + response = self.app.get("/tenders/{}/contracts/{}/documents/{}".format(self.tender_id, self.contract_id, doc_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + self.assertEqual("document description", response.json["data"]["description"]) + + tender = self.db.get(self.tender_id) + tender["contracts"][-1]["status"] = "cancelled" + self.db.save(tender) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], "Can't update document in current contract status") + + self.set_status("{}".format(self.forbidden_contract_document_modification_actions_status)) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual( + response.json["errors"][0]["description"], + "Can't update document in current ({}) tender status".format( + self.forbidden_contract_document_modification_actions_status + ), + ) + + +def patch_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + for bid in doc.get("bids", []): + if bid["id"] == bid_id and bid["status"] == "pending": + bid["status"] = "active" + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if 'value' in doc['contracts'][0] and doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_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"]) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + {"data": {"description": "document description"}}, + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + + response = self.app.get("/tenders/{}/contracts/{}/documents/{}".format(self.tender_id, self.contract_id, doc_id)) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + self.assertEqual("document description", response.json["data"]["description"]) + + tender = self.db.get(self.tender_id) tender["contracts"][-1]["status"] = "cancelled" self.db.save(tender) @@ -1177,9 +1715,91 @@ def patch_tender_contract_document(self): def lot2_create_tender_contract_document(self): + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't add document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_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("name.doc", response.json["data"]["title"]) + key = response.json["data"]["url"].split("?")[-1] + + cancellation = dict(**test_cancellation) + cancellation.update({ + "status": "active", + "cancellationOf": "lot", + "relatedLot": self.initial_lots[0]["id"], + }) + + response = self.app.post_json( + "/tenders/{}/cancellations?acc_token={}".format(self.tender_id, self.tender_token), {"data": cancellation}, + ) + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], "Can add document only in active lot status") + + +def lot2_create_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], ) self.assertEqual(response.status, "201 Created") self.assertEqual(response.content_type, "application/json") @@ -1199,8 +1819,9 @@ def lot2_create_tender_contract_document(self): {"data": cancellation}, ) + # Supplier response = self.app.post( - "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), upload_files=[("file", "name.doc", "content")], status=403, ) @@ -1209,6 +1830,43 @@ def lot2_create_tender_contract_document(self): self.assertEqual(response.json["errors"][0]["description"], "Can add document only in active lot status") +def lot2_create_tender_contract_document_by_others(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id!='{}'].owner_token".format(bid_id), doc)[0] + + # Bid owner + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u'Forbidden', u'location': u'url', u'name': u'permission'}]) + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Bid owner + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"], + [{u'description': u'Forbidden', u'location': u'url', u'name': u'permission'}]) + + def lot2_put_tender_contract_document(self): response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), @@ -1231,6 +1889,31 @@ def lot2_put_tender_contract_document(self): self.assertEqual(response.json["status"], "error") self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + upload_files=[("file", "name.doc", "content2")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.put( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token @@ -1265,6 +1948,90 @@ def lot2_put_tender_contract_document(self): self.assertEqual(response.json["errors"][0]["description"], "Can update document only in active lot status") +def lot2_put_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't add document in current contract status") + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_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"]) + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + status=404, + upload_files=[("invalid_name", "name.doc", "content")], + ) + self.assertEqual(response.status, "404 Not Found") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["status"], "error") + self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + upload_files=[("file", "name.doc", "content2")], + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + key = response.json["data"]["url"].split("?")[-1] + + # Tender owner + cancellation = dict(**test_cancellation) + cancellation.update({ + "status": "active", + "cancellationOf": "lot", + "relatedLot": self.initial_lots[0]["id"], + }) + response = self.app.post_json( + "/tenders/{}/cancellations?acc_token={}".format(self.tender_id, self.tender_token), + {"data": cancellation}, + ) + + # Supplier + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + upload_files=[("file", "name.doc", "content3")], + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], "Can update document only in active lot status") + + def lot2_patch_tender_contract_document(self): response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), @@ -1275,12 +2042,38 @@ def lot2_patch_tender_contract_document(self): doc_id = response.json["data"]["id"] self.assertIn(doc_id, response.headers["Location"]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.patch_json( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token ), {"data": {"description": "document description"}}, ) + self.assertEqual(response.status, "200 OK") self.assertEqual(response.content_type, "application/json") self.assertEqual(doc_id, response.json["data"]["id"]) @@ -1306,3 +2099,85 @@ def lot2_patch_tender_contract_document(self): self.assertEqual(response.status, "403 Forbidden") self.assertEqual(response.content_type, "application/json") self.assertEqual(response.json["errors"][0]["description"], "Can update document only in active lot status") + + +def lot2_patch_tender_contract_document_by_supplier(self): + response = self.app.get("/tenders/{}/contracts/{}".format(self.tender_id, self.contract_id)) + contract = response.json["data"] + self.assertEqual(response.json["data"]["status"], "pending") + doc = self.db.get(self.tender_id) + bid_id = jmespath.search("awards[?id=='{}'].bid_id".format(contract["awardID"]), doc)[0] + bid_token = jmespath.search("bids[?id=='{}'].owner_token".format(bid_id), doc)[0] + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + # Supplier + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, bid_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"]) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + {"data": {"description": "document description"}}, + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(doc_id, response.json["data"]["id"]) + + # Tender owner + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + + # Supplier + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + {"data": {"description": "document description"}}, + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't update document in current contract status") + + # Tender owner + cancellation = dict(**test_cancellation) + cancellation.update({ + "status": "active", + "cancellationOf": "lot", + "relatedLot": self.initial_lots[0]["id"], + }) + + response = self.app.post_json( + "/tenders/{}/cancellations?acc_token={}".format(self.tender_id, self.tender_token), {"data": cancellation}, + ) + + # Supplier + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, bid_token + ), + {"data": {"description": "new document description"}}, + status=403, + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.content_type, "application/json") + self.assertEqual(response.json["errors"][0]["description"], + "Supplier can't update document in current contract status") diff --git a/src/openprocurement/tender/cfaselectionua/tests/contract.py b/src/openprocurement/tender/cfaselectionua/tests/contract.py index 8de1b1f743..80e5f23d75 100644 --- a/src/openprocurement/tender/cfaselectionua/tests/contract.py +++ b/src/openprocurement/tender/cfaselectionua/tests/contract.py @@ -36,6 +36,15 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, + lot2_create_tender_contract_document_by_supplier, + lot2_create_tender_contract_document_by_others, + lot2_put_tender_contract_document_by_supplier, + lot2_patch_tender_contract_document_by_supplier, ) @@ -135,6 +144,11 @@ class TenderContractDocumentResourceTest(TenderContentWebTest, TenderContractDoc initial_bids = test_bids initial_lots = test_lots + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) @unittest.skip("Skip multi-lots tests") class Tender2LotContractDocumentResourceTest(TenderContentWebTest): @@ -181,6 +195,10 @@ def setUp(self): lot2_create_tender_contract_document = snitch(lot2_create_tender_contract_document) lot2_put_tender_contract_document = snitch(lot2_put_tender_contract_document) lot2_patch_tender_contract_document = snitch(lot2_patch_tender_contract_document) + test_lot2_create_tender_contract_document_by_supplier = snitch(lot2_create_tender_contract_document_by_supplier) + test_lot2_create_tender_contract_document_by_others = snitch(lot2_create_tender_contract_document_by_others) + test_lot2_put_tender_contract_document_by_supplier = snitch(lot2_put_tender_contract_document_by_supplier) + test_lot2_patch_tender_contract_document_by_supplier = snitch(lot2_patch_tender_contract_document_by_supplier) def suite(): diff --git a/src/openprocurement/tender/cfaselectionua/tests/contract_blanks.py b/src/openprocurement/tender/cfaselectionua/tests/contract_blanks.py index 8c4226a085..9386d4e32a 100644 --- a/src/openprocurement/tender/cfaselectionua/tests/contract_blanks.py +++ b/src/openprocurement/tender/cfaselectionua/tests/contract_blanks.py @@ -577,6 +577,37 @@ def not_found(self): def create_tender_contract_document(self): + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't add document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], @@ -656,6 +687,14 @@ def create_tender_contract_document(self): def put_tender_contract_document(self): + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], @@ -677,6 +716,31 @@ def put_tender_contract_document(self): self.assertEqual(response.json["status"], "error") self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + upload_files=[("file", "name.doc", "content2")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.put( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token @@ -757,6 +821,14 @@ def put_tender_contract_document(self): def patch_tender_contract_document(self): + doc = self.db.get(self.tender_id) + for i in doc.get("awards", []): + if 'complaintPeriod' in i: + i["complaintPeriod"]["endDate"] = i["complaintPeriod"]["startDate"] + if doc['contracts'][0]['value']['valueAddedTaxIncluded']: + doc['contracts'][0]['value']['amountNet'] = str(float(doc['contracts'][0]['value']['amount']) - 1) + self.db.save(doc) + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], @@ -766,6 +838,31 @@ def patch_tender_contract_document(self): doc_id = response.json["data"]["id"] self.assertIn(doc_id, response.headers["Location"]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.patch_json( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token @@ -820,6 +917,29 @@ def patch_tender_contract_document(self): def lot2_create_tender_contract_document(self): + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.post( + "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + upload_files=[("file", "name.doc", "content")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't add document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.post( "/tenders/{}/contracts/{}/documents?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), upload_files=[("file", "name.doc", "content")], @@ -873,6 +993,31 @@ def lot2_put_tender_contract_document(self): self.assertEqual(response.json["status"], "error") self.assertEqual(response.json["errors"], [{u"description": u"Not Found", u"location": u"body", u"name": u"file"}]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.put( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + upload_files=[("file", "name.doc", "content2")], + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.put( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token @@ -916,6 +1061,31 @@ def lot2_patch_tender_contract_document(self): doc_id = response.json["data"]["id"] self.assertIn(doc_id, response.headers["Location"]) + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending.winnerSigning"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending.winnerSigning") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( + self.tender_id, self.contract_id, doc_id, self.tender_token + ), + {"data": {"description": "document description"}}, + status=403 + ) + self.assertEqual(response.status, "403 Forbidden") + self.assertEqual(response.json["errors"][0]["description"], + "Tender onwer can't update document in current contract status") + + response = self.app.patch_json( + "/tenders/{}/contracts/{}?acc_token={}".format(self.tender_id, self.contract_id, self.tender_token), + {"data": {"status": "pending"}} + ) + self.assertEqual(response.status, "200 OK") + self.assertEqual(response.json["data"]["status"], "pending") + response = self.app.patch_json( "/tenders/{}/contracts/{}/documents/{}?acc_token={}".format( self.tender_id, self.contract_id, doc_id, self.tender_token diff --git a/src/openprocurement/tender/competitivedialogue/tests/stage2/contract.py b/src/openprocurement/tender/competitivedialogue/tests/stage2/contract.py index 2ce8f79973..91ced82f82 100644 --- a/src/openprocurement/tender/competitivedialogue/tests/stage2/contract.py +++ b/src/openprocurement/tender/competitivedialogue/tests/stage2/contract.py @@ -24,6 +24,11 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, ) from openprocurement.tender.openua.tests.contract_blanks import ( # TenderStage2EU(UA)ContractResourceTest @@ -117,6 +122,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = ("Basic", ("broker", "")) + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + class TenderStage2UAContractResourceTest(BaseCompetitiveDialogUAStage2ContentWebTest): initial_status = "active.qualification" @@ -227,6 +238,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = auth + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + def suite(): suite = unittest.TestSuite() diff --git a/src/openprocurement/tender/esco/tests/contract.py b/src/openprocurement/tender/esco/tests/contract.py index eff7253898..a680e5edb4 100644 --- a/src/openprocurement/tender/esco/tests/contract.py +++ b/src/openprocurement/tender/esco/tests/contract.py @@ -15,6 +15,11 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, ) from openprocurement.tender.openua.tests.contract_blanks import ( @@ -141,6 +146,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = ("Basic", ("broker", "")) + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + def suite(): suite = unittest.TestSuite() diff --git a/src/openprocurement/tender/openeu/tests/contract.py b/src/openprocurement/tender/openeu/tests/contract.py index ac894fc68f..40650d08d9 100644 --- a/src/openprocurement/tender/openeu/tests/contract.py +++ b/src/openprocurement/tender/openeu/tests/contract.py @@ -14,6 +14,11 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, ) from openprocurement.tender.openua.tests.contract_blanks import ( @@ -102,6 +107,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = ("Basic", ("broker", "")) + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + def suite(): suite = unittest.TestSuite() diff --git a/src/openprocurement/tender/openua/tests/contract.py b/src/openprocurement/tender/openua/tests/contract.py index 9a3519676d..2d54dcc3f9 100644 --- a/src/openprocurement/tender/openua/tests/contract.py +++ b/src/openprocurement/tender/openua/tests/contract.py @@ -22,6 +22,11 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, ) @@ -131,6 +136,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = auth + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + def suite(): suite = unittest.TestSuite() diff --git a/src/openprocurement/tender/openuadefense/tests/contract.py b/src/openprocurement/tender/openuadefense/tests/contract.py index 6efebb1825..60826cf057 100644 --- a/src/openprocurement/tender/openuadefense/tests/contract.py +++ b/src/openprocurement/tender/openuadefense/tests/contract.py @@ -24,6 +24,11 @@ patch_tender_contract_status_by_owner, patch_tender_contract_status_by_others, patch_tender_contract_status_by_supplier, + create_tender_contract_document_by_supplier, + create_tender_contract_document_by_others, + put_tender_contract_document_by_supplier, + put_tender_contract_document_by_others, + patch_tender_contract_document_by_supplier, ) @@ -133,6 +138,12 @@ def setUp(self): self.contract_id = contract["id"] self.app.authorization = auth + test_create_tender_contract_document_by_supplier = snitch(create_tender_contract_document_by_supplier) + test_create_tender_contract_document_by_others = snitch(create_tender_contract_document_by_others) + test_put_tender_contract_document_by_supplier = snitch(put_tender_contract_document_by_supplier) + test_put_tender_contract_document_by_others = snitch(put_tender_contract_document_by_others) + test_patch_tender_contract_document_by_supplier = snitch(patch_tender_contract_document_by_supplier) + def suite(): suite = unittest.TestSuite()