Skip to content

Commit

Permalink
Merge branch 'a479775209763048_yppr_fundingKind_validation_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
annawzz committed Nov 16, 2017
2 parents 1b5defa + 78e35c1 commit c4aeb29
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 7 deletions.
10 changes: 5 additions & 5 deletions openprocurement/tender/esco/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def lot_minValue(self):
valueAddedTaxIncluded=self.__parent__.minValue.valueAddedTaxIncluded))

def validate_yearlyPaymentsPercentageRange(self, data, value):
if data['fundingKind'] == 'other' and value != Decimal('0.8'):
raise ValidationError('when fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8')
if data['fundingKind'] == 'budget' and (value > Decimal('0.8') or value < Decimal('0')):
raise ValidationError('when fundingKind is budget, yearlyPaymentsPercentageRange should be less or equal 0.8, and more or equal 0')
if data['__parent__']['fundingKind'] == 'other' and value != Decimal('0.8'):
raise ValidationError('when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8')
if data['__parent__']['fundingKind'] == 'budget' and (value > Decimal('0.8') or value < Decimal('0')):
raise ValidationError('when tender fundingKind is budget, yearlyPaymentsPercentageRange should be less or equal 0.8, and more or equal 0')


class ContractDuration(Model):
Expand Down Expand Up @@ -364,7 +364,7 @@ class Options:
'cancelled': view_role,
'chronograph': chronograph_role,
'chronograph_view': chronograph_view_role,
'Administrator': Administrator_role,
'Administrator': Administrator_role + whitelist('yearlyPaymentsPercentageRange'),
'default': schematics_default_role,
'contracting': whitelist('doc_id', 'owner'),
}
Expand Down
2 changes: 2 additions & 0 deletions openprocurement/tender/esco/tests/lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
tender_1lot_fundingKind_default,
tender_2lot_fundingKind_default,
tender_lot_yearlyPaymentsPercentageRange,
tender_lot_fundingKind_yppr,
# TenderLotFeatureBidderResourceTest
create_tender_feature_bid_invalid,
create_tender_feature_bid,
Expand Down Expand Up @@ -102,6 +103,7 @@ class TenderLotResourceTest(BaseESCOContentWebTest):
test_tender_1lot_fundingKind_default = snitch(tender_1lot_fundingKind_default)
test_tender_2lot_fundingKind_default = snitch(tender_2lot_fundingKind_default)
test_tender_lot_yearlyPaymentsPercentageRange = snitch(tender_lot_yearlyPaymentsPercentageRange)
test_tender_lot_fundingKind_yppr = snitch(tender_lot_fundingKind_yppr)


class TenderLotEdgeCasesTest(BaseESCOContentWebTest, TenderLotEdgeCasesTestMixin):
Expand Down
167 changes: 165 additions & 2 deletions openprocurement/tender/esco/tests/lot_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def tender_lot_yearlyPaymentsPercentageRange(self):
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'when fundingKind is budget, yearlyPaymentsPercentageRange should be less or equal 0.8, and more or equal 0'],
[u'when tender fundingKind is budget, yearlyPaymentsPercentageRange should be less or equal 0.8, and more or equal 0'],
u'location': u'body', u'name': u'yearlyPaymentsPercentageRange'}
])

Expand All @@ -480,10 +480,173 @@ def tender_lot_yearlyPaymentsPercentageRange(self):
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'when fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'],
[u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'],
u'location': u'body', u'name': u'yearlyPaymentsPercentageRange'}
])


def tender_lot_fundingKind_yppr(self):
# create no lot tender
data = deepcopy(self.initial_data)
response = self.app.post_json('/tenders', {'data': data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['yearlyPaymentsPercentageRange'], 0.8)
self.assertEqual(response.json['data']['fundingKind'], 'other')
tender_id = response.json['data']['id']
tender_token = response.json['access']['token']

# try to add one lot (not valid)
lot = deepcopy(self.test_lots_data[0])
lot['fundingKind'] = 'budget'
lot['yearlyPaymentsPercentageRange'] = 0.6
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(
tender_id, tender_token), {'data': lot}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'],
u'location': u'body', u'name': u'yearlyPaymentsPercentageRange'}
])

# change lot yearlyPaymentsPercentageRange data to valid and add lot
lot['yearlyPaymentsPercentageRange'] = 0.8
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(
tender_id, tender_token), {'data': lot})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['yearlyPaymentsPercentageRange'], 0.8)
# lot fundingKind is 'other' - same as on tender
self.assertEqual(response.json['data']['fundingKind'], 'other')
lot1_id = response.json['data']['id']

# we can not change fundingKind - it should be same as tender
response = self.app.patch_json('/tenders/{}/lots/{}?acc_token={}'.format(
tender_id, lot1_id, tender_token), {'data': {'fundingKind': 'budget'}})
self.assertEqual(response.status, '200 OK')
self.assertIn('fundingKind', response.json['data'])
self.assertEqual(response.json['data']['fundingKind'], 'other')

response = self.app.patch_json('/tenders/{}/lots/{}?acc_token={}'.format(
tender_id, lot1_id, tender_token), {'data': {
'yearlyPaymentsPercentageRange': 0.6, 'fundingKind': 'budget'}}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'],
u'location': u'body', u'name': u'yearlyPaymentsPercentageRange'}
])

# add second not valid lot
lot = deepcopy(self.test_lots_data[0])
lot['fundingKind'] = 'budget'
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(
tender_id, tender_token), {'data': lot}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'lot funding kind should be identical to tender funding kind'],
u'location': u'body', u'name': u'lots'}
])

lot['fundingKind'] = 'other'
lot['yearlyPaymentsPercentageRange'] = 0.6
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(
tender_id, tender_token), {'data': lot}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description':
[u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8'],
u'location': u'body', u'name': u'yearlyPaymentsPercentageRange'}
])

# change lot yearlyPaymentsPercentageRange data to valid and add second lot
lot['yearlyPaymentsPercentageRange'] = 0.8
response = self.app.post_json('/tenders/{}/lots?acc_token={}'.format(
tender_id, tender_token), {'data': lot})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['yearlyPaymentsPercentageRange'], 0.8)
self.assertEqual(response.json['data']['fundingKind'], 'other')

# try to create not valid 1 lot tender
data = deepcopy(self.initial_data)
lot['fundingKind'] = 'budget'
lot['yearlyPaymentsPercentageRange'] = 0.6
data['lots'] = [lot]

response = self.app.post_json('/tenders', {'data': data}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [
{u'yearlyPaymentsPercentageRange': [u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8']}],
u'location': u'body', u'name': u'lots'}
])

# change lot yearlyPaymentsPercentageRange data to valid and create 1 lot tender
data['lots'][0]['yearlyPaymentsPercentageRange'] = 0.8
response = self.app.post_json('/tenders', {'data': data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['yearlyPaymentsPercentageRange'], 0.8)
self.assertEqual(response.json['data']['fundingKind'], 'other')
self.assertEqual(response.json['data']['lots'][0]['yearlyPaymentsPercentageRange'], 0.8)
# lot fundingKind is 'other' - same as on tender
self.assertEqual(response.json['data']['lots'][0]['fundingKind'], 'other')

# try to create not valid 2 lot tender
data = deepcopy(self.initial_data)
lot['fundingKind'] = 'budget'
lot['yearlyPaymentsPercentageRange'] = 0.6
data['lots'] = [lot, deepcopy(lot)]

response = self.app.post_json('/tenders', {'data': data}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [
{u'yearlyPaymentsPercentageRange': [u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8']},
{u'yearlyPaymentsPercentageRange': [u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8']}],
u'location': u'body', u'name': u'lots'}
])

data['lots'][0]['yearlyPaymentsPercentageRange'] = 0.8
response = self.app.post_json('/tenders', {'data': data}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [
{u'yearlyPaymentsPercentageRange': [u'when tender fundingKind is other, yearlyPaymentsPercentageRange should be equal 0.8']}],
u'location': u'body', u'name': u'lots'}
])

# change lot yearlyPaymentsPercentageRange data to valid and create 2 lot tender
data['lots'][1]['yearlyPaymentsPercentageRange'] = 0.8
response = self.app.post_json('/tenders', {'data': data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['data']['yearlyPaymentsPercentageRange'], 0.8)
self.assertEqual(response.json['data']['fundingKind'], 'other')
self.assertEqual(response.json['data']['lots'][0]['yearlyPaymentsPercentageRange'], 0.8)
# lot fundingKind is 'other' - same as on tender
self.assertEqual(response.json['data']['lots'][0]['fundingKind'], 'other')
self.assertEqual(response.json['data']['lots'][1]['yearlyPaymentsPercentageRange'], 0.8)
# lot fundingKind is 'other' - same as on tender
self.assertEqual(response.json['data']['lots'][1]['fundingKind'], 'other')


# Tender Lot Feature Resource Test


Expand Down

0 comments on commit c4aeb29

Please sign in to comment.