Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/a207264421644588_award_related_l…
Browse files Browse the repository at this point in the history
…ot_validation'
  • Loading branch information
vmaksymiv committed Nov 17, 2016
2 parents a2570cf + 1080ba9 commit 1a35ca1
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 0 deletions.
160 changes: 160 additions & 0 deletions openprocurement/tender/limited/tests/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,166 @@ class Tender2LotNegotiationQuickAwardComplaintResourceTest(Tender2LotNegotiation
initial_data = test_tender_negotiation_quick_data_2items


class Tender2LotNegotiationAwardComplaintResourceTest(BaseTenderContentWebTest):
initial_data = test_tender_negotiation_data_2items

def setUp(self):
super(Tender2LotNegotiationAwardComplaintResourceTest, self).setUp()
self.create_award()

def create_award(self):
# create lots
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(self.tender_id, self.tender_token),
{'data': test_lots[0]})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.first_lot = response.json['data']

self.assertEqual(response.content_type, 'application/json')
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(self.tender_id, self.tender_token),
{'data': test_lots[0]})
self.assertEqual(response.status, '201 Created')
self.second_lot = response.json['data']

# set items to lot
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(self.tender_id, self.tender_token),
{
"data": {
"items": [
{"relatedLot": self.first_lot['id']},
{"relatedLot": self.second_lot['id']}
]
}
})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['items'][0]['relatedLot'], self.first_lot['id'])
self.assertEqual(response.json['data']['items'][1]['relatedLot'], self.second_lot['id'])

# create first 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', 'lotID': self.first_lot['id']}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.first_award = response.json['data']
self.award_id = self.first_award['id']

# create second 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', 'lotID': self.second_lot['id']}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.second_award = response.json['data']
self.second_award_id = self.second_award['id']

def test_two_awards_on_one_lot(self):
""" Create two award and move second on first lot """

response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}},
status=403)

self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.json['errors'], [{"location": "body",
"name": "lotID",
"description": "Another award is already using this lotID."}])

def test_change_lotID_from_unsuccessful_award(self):
""" Create two award, and then try change lotId when
award in status unsuccessful """

# Make award unsuccessful
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.second_award_id, self.tender_token),
{'data': {'status': 'unsuccessful'}})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'unsuccessful')

# Move award on another lot
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['lotID'], self.second_lot['id'])

def test_change_lotID_from_active_award(self):
""" Create two award, and then change lotID when
award in status active """
# Try set lotID while another award has status pending
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}},
status=403)

self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.json['errors'], [{"location": "body",
"name": "lotID",
"description": "Another award is already using this lotID."}])

# Make award active
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.second_award_id, self.tender_token),
{'data': {'status': 'active'}})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'active')

# Move award on another lot
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}},
status=403)

self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.json['errors'], [{"location": "body",
"name": "lotID",
"description": "Another award is already using this lotID."}])

def test_change_lotID_from_cancelled_award(self):
""" Create two award, and then change lotID when
award in status cancelled """
# active second award
self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.second_award_id, self.tender_token),
{'data': {'status': 'active'}})

# Try set lotID while another award has status active
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}},
status=403)

self.assertEqual(response.status, '403 Forbidden')
self.assertEqual(response.json['errors'], [{"location": "body",
"name": "lotID",
"description": "Another award is already using this lotID."}])

# Make award cancelled
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.second_award_id, self.tender_token),
{'data': {'status': 'cancelled'}})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'cancelled')

# Move award on another lot
response = self.app.patch_json('/tenders/{}/awards/{}?acc_token={}'.format(
self.tender_id, self.award_id, self.tender_token),
{'data': {'lotID': self.second_lot['id']}})

self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['lotID'], self.second_lot['id'])


class Tender2LotNegotiationQuickAwardComplaintResourceTest(Tender2LotNegotiationAwardComplaintResourceTest):
initial_data = test_tender_negotiation_quick_data_2items


class TenderNegotiationQuickAwardComplaintResourceTest(TenderNegotiationAwardComplaintResourceTest):
initial_data = test_tender_negotiation_quick_data

Expand Down
3 changes: 3 additions & 0 deletions openprocurement/tender/limited/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
if SANDBOX_MODE:
test_tender_negotiation_quick_data['procurementMethodDetails'] = 'quick, accelerator=1440'

test_tender_negotiation_data_2items = deepcopy(test_tender_negotiation_data)
test_tender_negotiation_data_2items['items'] = [deepcopy(test_tender_negotiation_data_2items['items'][0]),
deepcopy(test_tender_negotiation_data_2items['items'][0])]

test_tender_negotiation_quick_data_2items = deepcopy(test_tender_negotiation_quick_data)
test_tender_negotiation_quick_data_2items['items'] = [deepcopy(test_tender_negotiation_quick_data_2items['items'][0]),
Expand Down
5 changes: 5 additions & 0 deletions openprocurement/tender/limited/views/award.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ def patch(self):
self.request.errors.add('body', 'data', 'Can\'t update award to active status with not qualified')
self.request.errors.status = 403
return
if award.lotID and \
[aw.lotID for aw in tender.awards if aw.status in['pending', 'active']].count(award.lotID) > 1:
self.request.errors.add('body', 'lotID', 'Another award is already using this lotID.')
self.request.errors.status = 403
return
if award_status == 'pending' and award.status == 'active':
normalized_end = calculate_normalized_date(get_now(), tender, True)
award.complaintPeriod.endDate = calculate_business_date(normalized_end, self.stand_still_delta, tender)
Expand Down

0 comments on commit 1a35ca1

Please sign in to comment.