Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a143330483135017_add_award_quali…
Browse files Browse the repository at this point in the history
…fied_validation'
  • Loading branch information
kroman0 committed Jul 15, 2016
2 parents ab899a3 + f46e362 commit 2c0acd5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
14 changes: 9 additions & 5 deletions openprocurement/tender/limited/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_create_tender_award(self):
def test_canceling_created_award_and_create_new_one(self):
request_path = '/tenders/{}/awards?acc_token={}'.format(self.tender_id, self.tender_token)
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
'qualified': True,
'status': 'pending'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -188,6 +189,7 @@ def test_canceling_created_award_and_create_new_one(self):

# Create new award
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
'qualified': True,
'status': 'pending'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -220,6 +222,7 @@ def test_canceling_created_award_and_create_new_one(self):
def test_patch_tender_award(self):
request_path = '/tenders/{}/awards?acc_token={}'.format(self.tender_id, self.tender_token)
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
'qualified': True,
'status': u'pending', "value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -316,7 +319,7 @@ def test_patch_tender_award(self):
self.assertEqual(response.content_type, 'application/json')
award = response.json['data']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, award['id'], self.tender_token),
{"data": {"status": "active"}})
{"data": {"status": "active", 'qualified': True}})
self.assertEqual(response.status, '200 OK')
active_award = award

Expand Down Expand Up @@ -359,7 +362,7 @@ def test_patch_tender_award(self):

def test_patch_tender_award_unsuccessful(self):
request_path = '/tenders/{}/awards?acc_token={}'.format(self.tender_id, self.tender_token)
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization], 'qualified': True,
'status': u'pending', "value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -391,7 +394,7 @@ def test_patch_tender_award_unsuccessful(self):

def test_get_tender_award(self):
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization],
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'qualified': True,
'status': 'pending'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -437,7 +440,7 @@ def setUp(self):
super(TenderNegotiationAwardComplaintResourceTest, self).setUp()
# Create award
request_path = '/tenders/{}/awards?acc_token={}'.format(self.tender_id, self.tender_token)
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization], 'qualified': True,
'status': 'pending'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -787,6 +790,7 @@ def setUp(self):
# Create award
request_path = '/tenders/{}/awards?acc_token={}'.format(self.tender_id, self.tender_token)
response = self.app.post_json(request_path, {'data': {'suppliers': [test_organization],
'qualified': True,
'status': 'pending'}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -1124,7 +1128,7 @@ def setUp(self):
super(TenderAwardDocumentResourceTest, self).setUp()
# Create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending'}})
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'qualified': True, 'status': 'pending'}})
award = response.json['data']
self.award_id = award['id']

Expand Down
21 changes: 13 additions & 8 deletions openprocurement/tender/limited/tests/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def setUp(self):
super(TenderContractResourceTest, self).setUp()
# Create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending',
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending', 'qualified': True,
'value': {"amount": 469, "currency": "UAH", "valueAddedTaxIncluded": True}}})
award = response.json['data']
self.award_id = award['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token), {"data": {"status": "active"}})
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token),
{"data": {"status": "active"}})

def test_create_tender_contract_invalid(self):
# This can not be, but just in case check
Expand Down Expand Up @@ -244,7 +245,8 @@ def test_patch_tender_contract(self):
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
tender_id, tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending'}})
award_id = response.json['data']['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, tender_token), {"data": {"status": "active"}})
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, tender_token),
{"data": {'qualified': True, "status": "active"}})

response = self.app.get('/tenders/{}/contracts'.format(
tender_id))
Expand Down Expand Up @@ -363,7 +365,7 @@ def test_award_id_change_is_not_allowed(self):
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization]}})
award = response.json['data']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, award['id'], self.tender_token), {"data": {"status": "active"}})
self.tender_id, award['id'], self.tender_token), {"data": {'qualified': True, "status": "active"}})
response = self.app.get('/tenders/{}/contracts'.format(
self.tender_id))
contract = response.json['data'][-1]
Expand Down Expand Up @@ -461,7 +463,8 @@ def test_patch_tender_contract(self):
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(
tender_id, tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending'}})
award_id = response.json['data']['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, tender_token), {"data": {"status": "active"}})
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, tender_token),
{"data": {'qualified': True, "status": "active"}})

response = self.app.get('/tenders/{}/contracts'.format(
tender_id))
Expand Down Expand Up @@ -564,7 +567,8 @@ def setUp(self):
self.tender_id, self.tender_token), {'data': {'suppliers': [test_organization], 'status': 'pending'}})
award = response.json['data']
self.award_id = award['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token), {"data": {"status": "active"}})
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token),
{"data": {'qualified': True, "status": "active"}})

@unittest.skipUnless(SANDBOX_MODE, "not supported accelerator")
def test_create_tender_contract_negotination_quick(self):
Expand Down Expand Up @@ -597,7 +601,7 @@ def setUp(self):
award = response.json['data']
self.award_id = award['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token),
{"data": {"status": "active"}})
{"data": {"status": "active", 'qualified': True}})
response = self.app.get('/tenders/{}/contracts'.format(
self.tender_id))
self.contract_id = response.json['data'][0]['id']
Expand Down Expand Up @@ -861,7 +865,8 @@ def test_patch_tender_contract_document(self):
self.assertEqual('document description', response.json["data"]["description"])

# cancel contract by award cancellation
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token), {"data": {"status": "cancelled"}})
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(self.tender_id, self.award_id, self.tender_token),
{"data": {"status": "cancelled"}})
self.assertEqual(response.json['data']["status"], "cancelled")

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)
Expand Down
14 changes: 11 additions & 3 deletions openprocurement/tender/limited/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ def test_patch_tender(self):
tender['id'], owner_token), {'data': {'suppliers': [test_organization], 'status': 'pending'}})
award_id = response.json['data']['id']
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender['id'], award_id, owner_token),
{"data": {"status": "active"}})
{"data": {"qualified": True, "status": "active"}})

response = self.app.get('/tenders/{}/contracts'.format(
tender['id']))
Expand Down Expand Up @@ -887,7 +887,7 @@ def test_single_award_tender(self):
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending'][0]

# set award as active
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, owner_token), {"data": {"status": "active"}})
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, owner_token), {"data": {"qualified": True, "status": "active"}})

# get contract id
response = self.app.get('/tenders/{}'.format(tender_id))
Expand Down Expand Up @@ -915,6 +915,7 @@ def test_single_award_tender(self):
# create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')

Expand Down Expand Up @@ -973,21 +974,24 @@ def test_multiple_awards_tender(self):
# create award
response = self.app.post_json('/tenders/{}/awards'.format(tender_id),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}}, status=403)
self.assertEqual(response.status, '403 Forbidden')

response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
award = response.json['data']

response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award['id'], owner_token),
{"data": {"status": "active"}})
{"data": {"qualified": True, "status": "active"}})
self.assertEqual(response.status, '200 OK')

response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
'value': {"amount": 501}}}, status=403)
self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.json['errors'][0]["description"], "Can't create new award while any (active) award exists")
Expand All @@ -997,6 +1001,7 @@ def test_multiple_awards_tender(self):

response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 505}}})
self.assertEqual(response.status, '201 Created')

Expand Down Expand Up @@ -1058,6 +1063,7 @@ def test_tender_cancellation(self):
# create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')

Expand All @@ -1081,6 +1087,7 @@ def test_tender_cancellation(self):
# create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
# get awards
Expand Down Expand Up @@ -1117,6 +1124,7 @@ def test_tender_cancellation(self):
# create award
response = self.app.post_json('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token),
{'data': {'suppliers': [test_organization],
"qualified": True,
"value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
# get awards
Expand Down
16 changes: 16 additions & 0 deletions openprocurement/tender/limited/views/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def collection_post(self):
self.request.errors.status = 403
return
award = self.request.validated['award']
if award.status == "active" and not award.qualified:
self.request.errors.add('body', 'data', 'Can\'t create new award in active status and not qualified')
self.request.errors.status = 403
return
tender.awards.append(award)
if save_tender(self.request):
self.LOGGER.info('Created tender award {}'.format(award.id),
Expand Down Expand Up @@ -303,6 +307,10 @@ def patch(self):
award = self.request.context
award_status = award.status
apply_patch(self.request, save=False, src=self.request.context.serialize())
if award.status == "active" and not award.qualified:
self.request.errors.add('body', 'data', 'Can\'t update award to active status with not qualified')
self.request.errors.status = 403
return
if award_status == 'pending' and award.status == 'active':
tender.contracts.append(type(tender).contracts.model_class({
'awardID': award.id,
Expand Down Expand Up @@ -434,6 +442,10 @@ def collection_post(self):
self.request.errors.status = 403
return
award = self.request.validated['award']
if award.status == "active" and not award.qualified:
self.request.errors.add('body', 'data', 'Can\'t create new award in active status and not qualified')
self.request.errors.status = 403
return
award.complaintPeriod = {'startDate': get_now().isoformat()}
tender.awards.append(award)
if save_tender(self.request):
Expand Down Expand Up @@ -511,6 +523,10 @@ def patch(self):
award_status = award.status
apply_patch(self.request, save=False, src=self.request.context.serialize())
award.date = get_now()
if award.status == "active" and not award.qualified:
self.request.errors.add('body', 'data', 'Can\'t update award to active status with not qualified')
self.request.errors.status = 403
return
if award_status == 'pending' and award.status == 'active':
normalized_end = calculate_normalized_date(award.date, tender, True)
award.complaintPeriod.endDate = calculate_business_date(normalized_end, self.stand_still_delta, tender)
Expand Down

0 comments on commit 2c0acd5

Please sign in to comment.