Skip to content

Commit

Permalink
Merge branch 'a312620117236937_block_cpv'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed May 31, 2017
2 parents 3555803 + f05c748 commit 549f980
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}

setup(name='openprocurement.api',
version='2.3.54',
version='2.3.57',
description='openprocurement.api',
long_description=README,
classifiers=[
Expand Down
12 changes: 12 additions & 0 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
CANT_DELETE_PERIOD_START_DATE_FROM = datetime(2016, 8, 30, tzinfo=TZ)
BID_LOTVALUES_VALIDATION_FROM = datetime(2016, 10, 24, tzinfo=TZ)
CPV_ITEMS_CLASS_FROM = datetime(2017, 1, 1, tzinfo=TZ)
CPV_BLOCK_FROM = datetime(2017, 6, 1, tzinfo=TZ)
ITEMS_LOCATION_VALIDATION_FROM = datetime(2016, 11, 22, tzinfo=TZ)

coordinates_reg_exp = re.compile(r'-?\d{1,3}\.\d+|-?\d{1,3}')
Expand Down Expand Up @@ -97,6 +98,12 @@ def get_tender(model):
return model


def get_schematics_document(model):
while not isinstance(model, SchematicsDocument):
model = model.__parent__
return model


class ListType(BaseListType):

def export_loop(self, list_instance, field_converter,
Expand Down Expand Up @@ -315,6 +322,11 @@ def validate_id(self, data, code):
elif data.get('scheme') == u'ДК021' and code not in DK_CODES:
raise ValidationError(BaseType.MESSAGES['choices'].format(unicode(DK_CODES)))

def validate_scheme(self, data, scheme):
schematics_document = get_schematics_document(data['__parent__'])
if (schematics_document.get('revisions')[0].date if schematics_document.get('revisions') else get_now()) > CPV_BLOCK_FROM and scheme != u'ДК021':
raise ValidationError(BaseType.MESSAGES['choices'].format(unicode([u'ДК021'])))


class Unit(Model):
"""Description of the unit which the good comes in e.g. hours, kilograms. Made up of a unit name, and the value of a single unit."""
Expand Down
2 changes: 1 addition & 1 deletion src/openprocurement/api/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
{
"description": u"футляри до державних нагород",
"classification": {
"scheme": u"CPV",
"scheme": u"ДК021",
"id": u"44617100-9",
"description": u"Cartons"
},
Expand Down
12 changes: 7 additions & 5 deletions src/openprocurement/api/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import timedelta

from openprocurement.api import ROUTE_PREFIX
from openprocurement.api.models import Tender, get_now, CANT_DELETE_PERIOD_START_DATE_FROM, CPV_ITEMS_CLASS_FROM, ITEMS_LOCATION_VALIDATION_FROM, coordinates_reg_exp
from openprocurement.api.models import Tender, get_now, CANT_DELETE_PERIOD_START_DATE_FROM, CPV_ITEMS_CLASS_FROM, CPV_BLOCK_FROM, ITEMS_LOCATION_VALIDATION_FROM, coordinates_reg_exp
from openprocurement.api.tests.base import test_tender_data, test_organization, BaseWebTest, BaseTenderWebTest
from uuid import uuid4

Expand Down Expand Up @@ -601,7 +601,7 @@ def test_create_tender_invalid(self):
])

cpv = test_tender_data["items"][0]['classification']["id"]
test_tender_data["items"][0]['classification']["id"] = u'60173000-1'
test_tender_data["items"][0]['classification']["id"] = u'160173000-1'
response = self.app.post_json(request_path, {'data': test_tender_data}, status=422)
test_tender_data["items"][0]['classification']["id"] = cpv
self.assertEqual(response.status, '422 Unprocessable Entity')
Expand All @@ -612,10 +612,12 @@ def test_create_tender_invalid(self):
self.assertIn("Value must be one of [u", response.json['errors'][0][u'description'][0][u'classification'][u'id'][0])

cpv = test_tender_data["items"][0]['classification']["id"]
test_tender_data["items"][0]['classification']["scheme"] = u'ДК021'
if get_now() < CPV_BLOCK_FROM:
test_tender_data["items"][0]['classification']["scheme"] = u'CPV'
test_tender_data["items"][0]['classification']["id"] = u'00000000-0'
response = self.app.post_json(request_path, {'data': test_tender_data}, status=422)
test_tender_data["items"][0]['classification']["scheme"] = u'ДК021'
if get_now() < CPV_BLOCK_FROM:
test_tender_data["items"][0]['classification']["scheme"] = u'CPV'
test_tender_data["items"][0]['classification']["id"] = cpv
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
Expand Down Expand Up @@ -1311,7 +1313,7 @@ def test_patch_tender(self):
self.assertEqual(len(response.json['data']['items']), 1)

response = self.app.patch_json('/tenders/{}'.format(tender['id']), {'data': {'items': [{"classification": {
"scheme": "CPV",
"scheme": "ДК021",
"id": "55523100-3",
"description": "Послуги з харчування у школах"
}}]}})
Expand Down

0 comments on commit 549f980

Please sign in to comment.