Skip to content

Commit

Permalink
Merge branch 'a163283577592188_fixed_check_bids'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Aug 4, 2016
2 parents 7daac9c + 4f51327 commit dc36dbf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
73 changes: 73 additions & 0 deletions src/openprocurement/api/tests/lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,79 @@ def test_2lot_2can(self):
self.assertTrue(all([i['status'] == 'cancelled' for i in response.json['data']['lots']]))
self.assertEqual(response.json['data']['status'], 'cancelled')

def test_2lot_2bid_0com_1can_before_auction(self):
self.app.authorization = ('Basic', ('broker', ''))
# create tender
response = self.app.post_json('/tenders', {"data": test_tender_data})
tender_id = self.tender_id = response.json['data']['id']
owner_token = response.json['access']['token']
lots = []
for lot in 2 * test_lots:
# add lot
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(tender_id, owner_token), {'data': test_lots[0]})
self.assertEqual(response.status, '201 Created')
lots.append(response.json['data']['id'])
# add item
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender_id, owner_token), {"data": {"items": [test_tender_data['items'][0] for i in lots]}})
# add relatedLot for item
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(tender_id, owner_token), {"data": {"items": [{'relatedLot': i} for i in lots]}})
self.assertEqual(response.status, '200 OK')
# switch to active.tendering
response = self.set_status('active.tendering', {"lots": [
{"auctionPeriod": {"startDate": (get_now() + timedelta(days=10)).isoformat()}}
for i in lots
]})
# create bid
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json('/tenders/{}/bids'.format(tender_id), {'data': {'tenderers': [test_organization], 'lotValues': [
{"value": {"amount": 500}, 'relatedLot': lot_id}
for lot_id in lots
]}})
# for first lot
lot_id = lots[0]
# create bid #2 for 1 lot
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json('/tenders/{}/bids'.format(tender_id), {'data': {'tenderers': [test_organization], 'lotValues': [
{"value": {"amount": 500}, 'relatedLot': lot_id}
]}})
# cancel lot
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.post_json('/tenders/{}/cancellations?acc_token={}'.format(tender_id, owner_token), {'data': {
'reason': 'cancellation reason',
'status': 'active',
"cancellationOf": "lot",
"relatedLot": lot_id
}})
# switch to active.qualification
response = self.set_status('active.auction', {'status': 'active.tendering'})
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(tender_id), {"data": {"id": tender_id}})
self.assertEqual(response.json['data']['status'], 'active.qualification')
# for second lot
lot_id = lots[1]
# get awards
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.get('/tenders/{}/awards?acc_token={}'.format(tender_id, owner_token))
# get pending award
award_id = [i['id'] for i in response.json['data'] if i['status'] == 'pending' and i['lotID'] == lot_id][0]
# set award as unsuccessful
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(tender_id, award_id, owner_token), {"data": {"status": "unsuccessful"}})
# after stand slill period
self.set_status('complete', {'status': 'active.awarded'})
# time travel
tender = self.db.get(tender_id)
for i in tender.get('awards', []):
i['complaintPeriod']['endDate'] = i['complaintPeriod']['startDate']
self.db.save(tender)
# check tender status
self.app.authorization = ('Basic', ('chronograph', ''))
response = self.app.patch_json('/tenders/{}'.format(tender_id), {"data": {"id": tender_id}})
# check status
self.app.authorization = ('Basic', ('broker', ''))
response = self.app.get('/tenders/{}'.format(tender_id))
self.assertEqual([i['status'] for i in response.json['data']['lots']], [u'cancelled', u'unsuccessful'])
self.assertEqual(response.json['data']['status'], 'unsuccessful')

def test_2lot_1bid_0com_1can(self):
self.app.authorization = ('Basic', ('broker', ''))
# create tender
Expand Down
5 changes: 2 additions & 3 deletions src/openprocurement/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ def check_bids(request):
[setattr(i.auctionPeriod, 'startDate', None) for i in tender.lots if i.numberOfBids < 2 and i.auctionPeriod and i.auctionPeriod.startDate]
[setattr(i, 'status', 'unsuccessful') for i in tender.lots if i.numberOfBids == 0 and i.status == 'active']
cleanup_bids_for_cancelled_lots(tender)
if max([i.numberOfBids for i in tender.lots]) < 2:
#tender.status = 'active.qualification'
add_next_award(request)
if not set([i.status for i in tender.lots]).difference(set(['unsuccessful', 'cancelled'])):
tender.status = 'unsuccessful'
elif max([i.numberOfBids for i in tender.lots if i.status == 'active']) < 2:
add_next_award(request)
else:
if tender.numberOfBids < 2 and tender.auctionPeriod and tender.auctionPeriod.startDate:
tender.auctionPeriod.startDate = None
Expand Down

0 comments on commit dc36dbf

Please sign in to comment.