Skip to content

Commit

Permalink
Merge pull request #29 from raccoongang/jcdb2dev37_lot_exposition_per…
Browse files Browse the repository at this point in the history
…iod_validation

tender period validation acceleration fix and test
  • Loading branch information
leits committed Oct 10, 2017
2 parents 2b79396 + c5787f1 commit c32ab54
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openprocurement/auctions/dgf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def validate_tenderPeriod(self, data, period):
return
if (data.get('revisions')[0].date if data.get('revisions') else get_now()) < MINIMAL_EXPOSITION_REQUIRED_FROM:
return
if calculate_business_date(period.startDate, MINIMAL_EXPOSITION_PERIOD) > period.endDate:
if calculate_business_date(period.startDate, MINIMAL_EXPOSITION_PERIOD, data) > period.endDate:
raise ValidationError(u"tenderPeriod should be greater than 6 days")

def validate_value(self, data, value):
Expand Down
5 changes: 4 additions & 1 deletion openprocurement/auctions/dgf/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
)


DEFAULT_ACCELERATION = 1440


now = datetime.now()
test_organization = {
"name": u"Державне управління справами",
Expand Down Expand Up @@ -77,7 +80,7 @@
"procurementMethodType": "dgfOtherAssets",
}
if SANDBOX_MODE:
test_auction_data['procurementMethodDetails'] = 'quick, accelerator=1440'
test_auction_data['procurementMethodDetails'] = 'quick, accelerator={}'.format(DEFAULT_ACCELERATION)
test_features_auction_data = test_auction_data.copy()
test_features_item = test_features_auction_data['items'][0].copy()
test_features_item['id'] = "1"
Expand Down
38 changes: 32 additions & 6 deletions openprocurement/auctions/dgf/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openprocurement.api.utils import ROUTE_PREFIX
from openprocurement.api.models import get_now, SANDBOX_MODE, TZ
from openprocurement.auctions.dgf.models import DGFOtherAssets, DGFFinancialAssets, DGF_ID_REQUIRED_FROM, CLASSIFICATION_PRECISELY_FROM
from openprocurement.auctions.dgf.tests.base import test_auction_data, test_financial_auction_data, test_organization, test_financial_organization, BaseWebTest, BaseAuctionWebTest
from openprocurement.auctions.dgf.tests.base import test_auction_data, test_financial_auction_data, test_organization, test_financial_organization, BaseWebTest, BaseAuctionWebTest, DEFAULT_ACCELERATION


class AuctionTest(BaseWebTest):
Expand Down Expand Up @@ -360,6 +360,31 @@ def test_listing_draft(self):
self.assertEqual(set([i['dateModified'] for i in response.json['data']]), set([i['dateModified'] for i in auctions]))
self.assertEqual([i['dateModified'] for i in response.json['data']], sorted([i['dateModified'] for i in auctions]))

def test_create_auction_validation_accelerated(self):
request_path = '/auctions'
now = get_now()
data = self.initial_data.copy()
auction_data = deepcopy(self.initial_data)
if SANDBOX_MODE:
startDate = (now + timedelta(days=8) / DEFAULT_ACCELERATION).isoformat()
else:
startDate = (now + timedelta(days=8)).isoformat()
auction_data['auctionPeriod'] = {'startDate': startDate}
response = self.app.post_json(request_path, {'data': auction_data}, status=201)
auction = response.json['data']
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
tender_period_startDate = parse_date(auction['tenderPeriod']['startDate'], None)
if not tender_period_startDate.tzinfo:
tender_period_startDate = TZ.localize(tender_period_startDate)
tender_period_endDate = parse_date(auction['tenderPeriod']['endDate'], None)
if not tender_period_endDate.tzinfo:
tender_period_endDate = TZ.localize(tender_period_endDate)
if SANDBOX_MODE:
self.assertLess((tender_period_endDate - tender_period_startDate), timedelta(days=8) / DEFAULT_ACCELERATION)
else:
self.assertLess((tender_period_endDate - tender_period_startDate), timedelta(days=8))

def test_create_auction_invalid(self):
request_path = '/auctions'
response = self.app.post(request_path, 'data', status=415)
Expand Down Expand Up @@ -517,11 +542,12 @@ def test_create_auction_invalid(self):
{u'description': [u'period should begin after auctionPeriod'], u'location': u'body', u'name': u'awardPeriod'}
])

# Lot exposition time period validation
data = self.initial_data['auctionPeriod']
self.initial_data['auctionPeriod'] = {'startDate': (now + timedelta(days=5)).isoformat()}
response = self.app.post_json(request_path, {'data': self.initial_data}, status=422)
self.initial_data['auctionPeriod'] = data
auction_data = deepcopy(self.initial_data)
if SANDBOX_MODE:
auction_data['auctionPeriod'] = {'startDate': (now + timedelta(days=5) / DEFAULT_ACCELERATION).isoformat()}
else:
auction_data['auctionPeriod'] = {'startDate': (now + timedelta(days=5)).isoformat()}
response = self.app.post_json(request_path, {'data': auction_data}, status=422)
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
Expand Down

0 comments on commit c32ab54

Please sign in to comment.