Skip to content

Commit

Permalink
A535578546521788 address location validation (#58)
Browse files Browse the repository at this point in the history
* Prepare openprocurement.auctions.dgf 1.1.0-sale.

* Add validators for item.address and item.location

* Add tests for item.address and item.location validators

* Remove CPV/CAV code based validation for item.location

* Typo fix
  • Loading branch information
yarsanich committed Feb 6, 2018
1 parent b086781 commit a56f95b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
5 changes: 5 additions & 0 deletions openprocurement/auctions/dgf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def read_json(name):
CLASSIFICATION_PRECISELY_FROM = datetime(2017, 7, 19, tzinfo=TZ)
DGF_ID_REQUIRED_FROM = datetime(2017, 1, 1, tzinfo=TZ)
DGF_DECISION_REQUIRED_FROM = datetime(2017, 1, 1, tzinfo=TZ)
DGF_ADDRESS_REQUIRED_FROM = datetime(2017, 2, 7, tzinfo=TZ)
ENQUIRY_END_EDITING_AND_VALIDATION_REQUIRED_FROM = datetime(2018, 01, 22, tzinfo=TZ)

#codes
CAVPS_CODES = read_json('cav_ps.json')
CPVS_CODES = read_json('cpvs.json')
ORA_CODES[0:0] = ["UA-IPN", "UA-FIN"]

#code units
CPV_NON_SPECIFIC_LOCATION_UNITS = ('71', '72', '73', '75', '76', '77', '79', '80', '85', '90', '92', '98')
CAV_NON_SPECIFIC_LOCATION_UNITS = ('07', '08')
12 changes: 11 additions & 1 deletion openprocurement/auctions/dgf/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
DOCUMENT_TYPE_URL_ONLY, CLASSIFICATION_PRECISELY_FROM,
DGF_ID_REQUIRED_FROM, CAVPS_CODES,
CPVS_CODES, ORA_CODES, MINIMAL_EXPOSITION_PERIOD,
MINIMAL_EXPOSITION_REQUIRED_FROM, MINIMAL_PERIOD_FROM_ENQUIRY_END,
MINIMAL_EXPOSITION_REQUIRED_FROM,
CPV_NON_SPECIFIC_LOCATION_UNITS,
CAV_NON_SPECIFIC_LOCATION_UNITS,
DGF_ADDRESS_REQUIRED_FROM,
MINIMAL_PERIOD_FROM_ENQUIRY_END,
ENQUIRY_END_EDITING_AND_VALIDATION_REQUIRED_FROM
)

Expand Down Expand Up @@ -93,6 +97,12 @@ class Options:
address = ModelType(Address)
location = ModelType(Location)

def validate_address(self, data, address):
if (data.get('revisions')[0].date if data.get('revisions') else get_now()) > DGF_ADDRESS_REQUIRED_FROM:
if (data['classification']['scheme'] == u'CAV-PS' and data['classification']['id'].startswith(CAV_NON_SPECIFIC_LOCATION_UNITS) or
data['classification']['scheme'] == u'CPV' and data['classification']['id'].startswith(CPV_NON_SPECIFIC_LOCATION_UNITS)):
raise ValidationError(u'This field is required.')


class Identifier(BaseIdentifier):
scheme = StringType(required=True, choices=ORA_CODES)
Expand Down
58 changes: 51 additions & 7 deletions openprocurement/auctions/dgf/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

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, DGF_ADDRESS_REQUIRED_FROM
from openprocurement.auctions.dgf.constants import MINIMAL_PERIOD_FROM_ENQUIRY_END, ENQUIRY_END_EDITING_AND_VALIDATION_REQUIRED_FROM
from openprocurement.auctions.dgf.models import DGFOtherAssets, DGFFinancialAssets, DGF_ID_REQUIRED_FROM, CLASSIFICATION_PRECISELY_FROM
from openprocurement.auctions.dgf.tests.base import test_auction_maximum_data, test_auction_data, test_financial_auction_data, test_organization, test_financial_organization, BaseWebTest, BaseAuctionWebTest, DEFAULT_ACCELERATION, test_bids, test_financial_bids


Expand Down Expand Up @@ -641,6 +641,50 @@ def test_required_dgf_id(self):
self.assertIn('dgfID', auction)
self.assertEqual(data['dgfID'], auction['dgfID'])

@unittest.skipIf(get_now() < DGF_ADDRESS_REQUIRED_FROM, "Can`t create auction without item.address only from {}".format(DGF_ADDRESS_REQUIRED_FROM))
def test_required_dgf_item_address(self):
auction_data = deepcopy(self.initial_data)
del auction_data['items'][0]['address']

# CAV-PS non specific location code test
auction_data['items'][0]['classification'] = {
"scheme": u"CAV-PS",
"id": u"07227000-6",
"description": u"Застава - Інше"
}
response = self.app.post_json('/auctions', {'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')
self.assertEqual(response.json['errors'], [{"location": "body", "name": "items", "description": [{"address": ["This field is required."]}]}])

# CPV non specific location code test
auction_data['items'][0]['classification'] = {
"scheme": u"CPV",
"id": u"90470000-2",
"description": u"Послуги з чищення каналізаційних колекторів"
}
response = self.app.post_json('/auctions', {'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')
self.assertEqual(response.json['errors'], [{"location": "body", "name": "items", "description": [{"address": ["This field is required."]}]}])

auction_data['items'][0]['classification'] = {
"scheme": u"CPV",
"id": u"34965000-9",
"description": u"Всебічно направлений далекомірний радіомаяк"
}
item = deepcopy(auction_data['items'][0])
item['classification'] = {
"scheme": u"CAV-PS",
"id": u"04210000-3",
"description": u"Промислова нерухомість"
}
auction_data['items'].append(item)
response = self.app.post_json('/auctions', {'data': auction_data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')

def test_create_auction_auctionPeriod(self):
data = self.initial_data.copy()
Expand Down Expand Up @@ -828,31 +872,31 @@ def test_additionalClassifications(self):
# CAV-PS classification test
auction_data['items'][0]['classification'] = {
"scheme" : u"CAV-PS",
"id": u"07227000-6",
"description": u"Застава - Інше"
"id": u"04210000-3",
"description": u"Промислова нерухомість"
}
response = self.app.post_json('/auctions', {'data': auction_data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
data = response.json['data']
self.assertEqual(data['items'][0]['classification']['scheme'], 'CAV-PS')
self.assertEqual(data['items'][0]['classification']['id'], '07227000-6')
self.assertEqual(data['items'][0]['classification']['id'], '04210000-3')

# CAV-PS and CPV classification in different items
auction_data = deepcopy(self.initial_data)
item = deepcopy(auction_data['items'][0])
item['classification'] = {
"scheme" : u"CAV-PS",
"id": u"07227000-6",
"description": u"Застава - Інше"
"id": u"04210000-3",
"description": u"Промислова нерухомість"
}
auction_data['items'].append(item)
response = self.app.post_json('/auctions', {'data': auction_data})
self.assertEqual(response.status, '201 Created')
self.assertEqual(response.content_type, 'application/json')
data = response.json['data']
self.assertEqual(data['items'][1]['classification']['scheme'], 'CAV-PS')
self.assertEqual(data['items'][1]['classification']['id'], '07227000-6')
self.assertEqual(data['items'][1]['classification']['id'], '04210000-3')
self.assertEqual(data['items'][0]['classification']['scheme'], 'CPV')
self.assertEqual(data['items'][0]['classification']['id'], '66113000-5')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os

version = '1.0.19-sale'
version = '1.1.0-sale'

entry_points = {
'openprocurement.auctions.core.plugins': [
Expand Down

0 comments on commit a56f95b

Please sign in to comment.