Skip to content

Commit

Permalink
Merge branch 'a282234899292081_dk021'
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Apr 4, 2017
2 parents 40c7369 + e8e70d9 commit 3d09953
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 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.47',
version='2.3.52',
description='openprocurement.api',
long_description=README,
classifiers=[
Expand Down
1 change: 1 addition & 0 deletions src/openprocurement/api/dk021.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def read_json(name):

CPV_CODES = read_json('cpv.json')
CPV_CODES.append('99999999-9')
DK_CODES = read_json('dk021.json')
#DKPP_CODES = read_json('dkpp.json')
ORA_CODES = [i['code'] for i in read_json('OrganisationRegistrationAgency.json')['data']]
WORKING_DAYS = read_json('working_days.json')
Expand Down Expand Up @@ -305,8 +306,14 @@ class Classification(Model):


class CPVClassification(Classification):
scheme = StringType(required=True, default=u'CPV', choices=[u'CPV'])
id = StringType(required=True, choices=CPV_CODES)
scheme = StringType(required=True, default=u'CPV', choices=[u'CPV', u'ДК021'])
id = StringType(required=True)

def validate_id(self, data, code):
if data.get('scheme') == u'CPV' and code not in CPV_CODES:
raise ValidationError(BaseType.MESSAGES['choices'].format(unicode(CPV_CODES)))
elif data.get('scheme') == u'ДК021' and code not in DK_CODES:
raise ValidationError(BaseType.MESSAGES['choices'].format(unicode(DK_CODES)))


class Unit(Model):
Expand Down
24 changes: 24 additions & 0 deletions src/openprocurement/api/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,30 @@ def test_create_tender_invalid(self):
{u'description': [u'CPV group of items be identical'], u'location': u'body', u'name': u'items'}
])

cpv = test_tender_data["items"][0]['classification']["id"]
test_tender_data["items"][0]['classification']["id"] = u'60173000-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')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertIn(u'classification', response.json['errors'][0][u'description'][0])
self.assertIn(u'id', response.json['errors'][0][u'description'][0][u'classification'])
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'
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'
test_tender_data["items"][0]['classification']["id"] = cpv
self.assertEqual(response.status, '422 Unprocessable Entity')
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertIn(u'classification', response.json['errors'][0][u'description'][0])
self.assertIn(u'id', response.json['errors'][0][u'description'][0][u'classification'])
self.assertIn("Value must be one of [u", response.json['errors'][0][u'description'][0][u'classification'][u'id'][0])

data = test_tender_data["items"][0].copy()
classification = data['classification'].copy()
classification["id"] = u'33600000-6'
Expand Down

0 comments on commit 3d09953

Please sign in to comment.