Skip to content

Commit

Permalink
Cancelling all awards on canceling award with satisfied complaint
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed May 12, 2016
1 parent decbd66 commit e15f694
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
70 changes: 69 additions & 1 deletion openprocurement/tender/openua/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_patch_tender_award(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['errors'][0]["description"], "Can't update award in current (complete) tender status")

def test_patch_tender_award_unsuccessful(self):
def test_patch_tender_award_active(self):
auth = self.app.authorization
self.app.authorization = ('Basic', ('token', ''))
response = self.app.post_json( '/tenders/{}/awards'.format(self.tender_id), {'data': {'suppliers': [test_organization], 'status': u'pending', 'bid_id': self.initial_bids[0]['id'], "value": {"amount": 500}}})
Expand All @@ -276,6 +276,74 @@ def test_patch_tender_award_unsuccessful(self):
self.assertIn('Location', response.headers)
new_award_location = response.headers['Location']

response = self.app.patch_json(new_award_location[-81:]+'?acc_token={}'.format(self.tender_token), {"data": {"status": "active", "qualified": True, "eligible": True}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertNotIn('Location', response.headers)

response = self.app.get('/tenders/{}/awards'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(len(response.json['data']), 2)

bid_token = self.initial_bids_tokens[self.initial_bids[0]['id']]
response = self.app.post_json(new_award_location[-81:]+'/complaints?acc_token={}'.format(bid_token), {'data': {
'title': 'complaint title',
'description': 'complaint description',
'author': test_organization,
'status': 'pending'
}})
self.assertEqual(response.status, '201 Created')

self.app.authorization = ('Basic', ('reviewer', ''))
response = self.app.patch_json(new_award_location[-81:]+'/complaints/{}'.format(response.json['data']['id']), {'data': {
'status': 'accepted'
}})
self.assertEqual(response.status, '200 OK')

response = self.app.patch_json(new_award_location[-81:]+'/complaints/{}'.format(response.json['data']['id']), {'data': {
'status': 'satisfied'
}})
self.assertEqual(response.status, '200 OK')

self.app.authorization = ('Basic', ('token', ''))
response = self.app.patch_json(new_award_location[-81:], {"data": {"status": "cancelled"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertIn('Location', response.headers)
new_award_location = response.headers['Location']

response = self.app.patch_json(new_award_location[-81:], {"data": {"status": "unsuccessful"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertIn('Location', response.headers)
new_award_location = response.headers['Location']

response = self.app.patch_json(new_award_location[-81:], {"data": {"status": "unsuccessful"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertNotIn('Location', response.headers)

response = self.app.get('/tenders/{}/awards'.format(self.tender_id))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(len(response.json['data']), 4)

def test_patch_tender_award_unsuccessful(self):
auth = self.app.authorization
self.app.authorization = ('Basic', ('token', ''))
response = self.app.post_json( '/tenders/{}/awards'.format(self.tender_id), {'data': {'suppliers': [test_organization], 'status': u'pending', 'bid_id': self.initial_bids[0]['id'], "value": {"amount": 500}}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
award = response.json['data']

self.app.authorization = auth
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, award['id'], self.tender_token), {"data": {"status": "unsuccessful"}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.content_type, 'application/json')
self.assertIn('Location', response.headers)
new_award_location = response.headers['Location']

response = self.app.patch_json(new_award_location[-81:]+'?acc_token={}'.format(self.tender_token), {"data": {"status": "active", "qualified": True, "eligible": True}})
self.assertEqual(response.status, '200 OK')
Expand Down
13 changes: 13 additions & 0 deletions openprocurement/tender/openua/views/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ def patch(self):
'items': [i for i in tender.items if i.relatedLot == award.lotID ],
'contractID': '{}-{}{}'.format(tender.tenderID, self.server_id, len(tender.contracts) +1) }))
add_next_award(self.request)
elif award_status == 'active' and award.status == 'cancelled' and any([i.status == 'satisfied' for i in award.complaints]):
now = get_now()
cancelled_awards = []
for i in tender.awards:
if i.lotID != award.lotID:
continue
i.complaintPeriod.endDate = now
i.status = 'cancelled'
cancelled_awards.append(i.id)
for i in tender.contracts:
if i.awardID in cancelled_awards:
i.status = 'cancelled'
add_next_award(self.request)
elif award_status == 'active' and award.status == 'cancelled':
now = get_now()
if award.complaintPeriod.endDate > now:
Expand Down

0 comments on commit e15f694

Please sign in to comment.