Skip to content

Commit

Permalink
Added CPV group items validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kroman0 committed Feb 10, 2015
1 parent 464ff64 commit 13fad24
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/openprocurement/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ class Options:
contracts = ListType(ModelType(Contract), default=list())


def validate_cpv_group(items, *args):
if items and len(set([i.classification.id[:3] for i in items])) != 1:
raise ValidationError(u"CPV group of items be identical")


plain_role = (blacklist('_attachments', 'revisions', 'dateModified') + schematics_embedded_role)
create_role = (blacklist('owner_token', 'owner', '_attachments', 'revisions', 'dateModified', 'doc_id', 'tenderID', 'bids', 'documents', 'awards', 'questions', 'complaints', 'auctionUrl', 'status', 'auctionPeriod', 'awardPeriod', 'procurementMethod', 'awardCriteria', 'submissionMethod') + schematics_embedded_role)
edit_role = (blacklist('owner_token', 'owner', '_attachments', 'revisions', 'dateModified', 'doc_id', 'tenderID', 'bids', 'documents', 'awards', 'questions', 'complaints', 'auctionUrl', 'auctionPeriod', 'awardPeriod', 'procurementMethod', 'awardCriteria', 'submissionMethod', 'mode') + schematics_embedded_role)
Expand Down Expand Up @@ -461,7 +466,7 @@ def __local_roles__(self):
description_en = StringType()
description_ru = StringType()
tenderID = StringType() # TenderID should always be the same as the OCID. It is included to make the flattened data structure more convenient.
items = ListType(ModelType(Item), required=True, min_size=1) # The goods and services to be purchased, broken into line items wherever possible. Items should not be duplicated, but a quantity of 2 specified instead.
items = ListType(ModelType(Item), required=True, min_size=1, validators=[validate_cpv_group]) # The goods and services to be purchased, broken into line items wherever possible. Items should not be duplicated, but a quantity of 2 specified instead.
value = ModelType(Value, required=True) # The total estimated value of the procurement.
procurementMethod = StringType(choices=['open', 'selective', 'limited'], default='open') # Specify tendering method as per GPA definitions of Open, Selective, Limited (http://www.wto.org/english/docs_e/legal_e/rev-gpr-94_01_e.htm)
procurementMethodRationale = StringType() # Justification of procurement method, especially in the case of Limited tendering.
Expand Down
14 changes: 14 additions & 0 deletions src/openprocurement/api/tests/tender.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,20 @@ def test_create_tender_invalid(self):
{u'description': {u'contactPoint': {u'email': [u'telephone or email should be present']}}, u'location': u'body', u'name': u'procuringEntity'}
])

data = test_tender_data["items"][0].copy()
classification = data['classification'].copy()
classification["id"] = u'19212310-1'
data['classification'] = classification
test_tender_data["items"] = [test_tender_data["items"][0], data]
response = self.app.post_json(request_path, {'data': test_tender_data}, status=422)
test_tender_data["items"] = test_tender_data["items"][:1]
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'], [
{u'description': [u'CPV group of items be identical'], u'location': u'body', u'name': u'items'}
])

def test_create_tender_generated(self):
data = test_tender_data.copy()
#del data['awardPeriod']
Expand Down

0 comments on commit 13fad24

Please sign in to comment.