Skip to content

Commit

Permalink
Merge branch 'a465585129744890_bids_invalidation'
Browse files Browse the repository at this point in the history
  • Loading branch information
annawzz committed Oct 30, 2017
2 parents 86cf78a + 6a1b5a3 commit 1e33e63
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
2 changes: 2 additions & 0 deletions openprocurement/tender/esco/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def validate_annualCostsReduction(self, data, value):
if len(value) != 21:
raise ValidationError('annual costs reduction should be set for 21 period')

@bids_validation_wrapper
def validate_yearlyPaymentsPercentage(self, data, value):
if get_tender(data['__parent__']).fundingKind == 'other' and (value < Decimal('0.8') or value > Decimal('1')):
raise ValidationError('yearlyPaymentsPercentage should be greater than 0.8 and less than 1')
Expand All @@ -237,6 +238,7 @@ class LotValue(BaseLotValue):

value = ModelType(ESCOValue, required=True)

@bids_validation_wrapper
def validate_value(self, data, value):
if value and isinstance(data['__parent__'], Model) and (data['__parent__'].status not in ('invalid', 'deleted', 'draft')) and data['relatedLot']:
lots = [i for i in get_tender(data['__parent__']).lots if i.id == data['relatedLot']]
Expand Down
15 changes: 9 additions & 6 deletions openprocurement/tender/esco/tests/bid_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,15 @@ def bids_invalidation_on_tender_change(self):
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'pending')

# update tender. we can set value that is less than a value in bids as
# they will be invalidated by this request
# update tender. we can set yearlyPaymentsPercentageRange value
# that is less than a value in bids as they will be invalidated by this request
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(
self.tender_id, self.tender_token), {"data": {"description": "new description"}})
self.tender_id, self.tender_token), {'data': {
'yearlyPaymentsPercentageRange': 0.7,
'fundingKind': 'budget'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["description"], "new description")
self.assertEqual(response.json['data']["yearlyPaymentsPercentageRange"], 0.7)
self.assertEqual(response.json['data']["fundingKind"], "budget")

# check bids status
for bid_id, token in bids_access.items():
Expand Down Expand Up @@ -826,7 +829,7 @@ def bids_invalidation_on_tender_change(self):
data = deepcopy(self.test_bids_data[0])
data['value'] = {
"annualCostsReduction": [200] * 21,
"yearlyPaymentsPercentage": 0.8,
"yearlyPaymentsPercentage": 0.7,
"contractDuration": {"years": 10, "days": 15}
}
response = self.app.post_json('/tenders/{}/bids'.format(self.tender_id), {'data': data})
Expand All @@ -840,7 +843,7 @@ def bids_invalidation_on_tender_change(self):
'tenderers': self.test_bids_data[1]['tenderers'],
"value": {
"annualCostsReduction": [200] * 21,
"yearlyPaymentsPercentage": 0.8,
"yearlyPaymentsPercentage": 0.7,
"contractDuration": {"years": 10, "days": 15}
}}})

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 @@ -59,6 +59,7 @@
# TenderLotBidResourceTest
create_tender_bid_invalid,
patch_tender_bid,
bids_invalidation_on_lot_change,
)
from openprocurement.tender.esco.utils import to_decimal

Expand Down Expand Up @@ -137,6 +138,7 @@ class TenderLotBidResourceTest(BaseESCOContentWebTest):

test_create_tender_bid_invalid = snitch(create_tender_bid_invalid)
test_patch_tender_bid = snitch(patch_tender_bid)
test_bids_invalidation_on_lot_change = snitch(bids_invalidation_on_lot_change)


class TenderLotFeatureBidResourceTest(BaseESCOContentWebTest):
Expand Down
40 changes: 40 additions & 0 deletions openprocurement/tender/esco/tests/lot_blanks.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,46 @@ def patch_tender_bid(self):
self.assertEqual(response.json['errors'][0]["description"],
"Can't update bid in current (unsuccessful) tender status")


def bids_invalidation_on_lot_change(self):
bids_access = {}

lot_id = self.initial_lots[0]['id']
response = self.app.post_json('/tenders/{}/bids'.format(self.tender_id), {'data': {
'selfEligible': True, 'selfQualified': True,
'tenderers': self.test_bids_data[0]["tenderers"],
'lotValues': [{"value": self.test_bids_data[0]['value'], 'relatedLot': lot_id}]}})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
bid = response.json['data']
bid_token = response.json['access']['token']

# check initial status
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(
self.tender_id, bid['id'], bid_token))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'pending')

# update tender (with fundingKind budget we can set not 0.8 in yppr field)
response = self.app.patch_json('/tenders/{}?acc_token={}'.format(
self.tender_id, self.tender_token), {'data': {'fundingKind': 'budget'}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["fundingKind"], "budget")

# update lot. we can set yppr that is less than a value in bids as
# they will be invalidated by this request
response = self.app.patch_json('/tenders/{}/lots/{}?acc_token={}'.format(
self.tender_id, lot_id, self.tender_token), {"data": {"yearlyPaymentsPercentageRange": 0.1}})
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']["yearlyPaymentsPercentageRange"], 0.1)

# check bids status
response = self.app.get('/tenders/{}/bids/{}?acc_token={}'.format(
self.tender_id, bid['id'], bid_token))
self.assertEqual(response.status, '200 OK')
self.assertEqual(response.json['data']['status'], 'invalid')


# TenderLotFeatureBidResourceTest


Expand Down

0 comments on commit 1e33e63

Please sign in to comment.