Skip to content

Commit

Permalink
Merge pull request #43 from gorserg/single_feature_value_limit
Browse files Browse the repository at this point in the history
single feature value up to 0.99
  • Loading branch information
kroman0 committed Jul 29, 2016
2 parents 7b9870f + f49c89e commit 81e3ba1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
11 changes: 9 additions & 2 deletions openprocurement/tender/competitivedialogue/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from datetime import timedelta
from schematics.types import StringType
from schematics.types import StringType, FloatType
from schematics.exceptions import ValidationError
from zope.interface import implementer
from pyramid.security import Allow
from schematics.types.compound import ModelType
from schematics.types.serializable import serializable
from openprocurement.api.models import ITender, Identifier, Model, Value, get_tender
from openprocurement.api.models import ITender, Identifier, Model, Value, validate_values_uniq, get_tender, validate_features_uniq, Feature as BaseFeature, FeatureValue as BaseFeatureValue
from openprocurement.api.utils import calculate_business_date, get_now
from openprocurement.tender.openua.models import (SifterListType, Item as BaseItem, Tender as BaseTenderUA,
TENDER_PERIOD as TENDERING_DURATION_UA, Lot as BaseLotUA)
Expand Down Expand Up @@ -117,6 +117,12 @@ class Options:
def validate_parameters(self, data, parameters):
pass # remove validation on stage 1

class FeatureValue(BaseFeatureValue):
value = FloatType(required=True, min_value=0.0, max_value=FEATURES_MAX_SUM)

class Feature(BaseFeature):
enum = ListType(ModelType(FeatureValue), default=list(), min_size=1, validators=[validate_values_uniq])

lot_roles = {
'create': whitelist('id', 'title', 'title_en', 'title_ru', 'description', 'description_en', 'description_ru', 'value', 'guarantee', 'minimalStep'),
'edit': whitelist('title', 'title_en', 'title_ru', 'description', 'description_en', 'description_ru', 'value', 'guarantee', 'minimalStep'),
Expand All @@ -140,6 +146,7 @@ class Tender(BaseTenderEU):
filter_by='status', filter_in_values=['invalid', 'deleted'])
TenderID = StringType(required=False)
stage2TenderID = StringType(required=False)
features = ListType(ModelType(Feature), validators=[validate_features_uniq])

class Options:
roles = roles.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def test_tender_features_invalid(self):
"title": u"Потужність всмоктування",
"enum": [
{
"value": 0.5,
"value": 1.0,
"title": u"До 1000 Вт"
},
{
Expand All @@ -715,7 +715,7 @@ def test_tender_features_invalid(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.3.']}]}],
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.99.']}]}],
u'location': u'body',
u'name': u'features'}
])
Expand Down Expand Up @@ -2394,7 +2394,7 @@ def test_tender_features_invalid(self):
"title": u"Потужність всмоктування",
"enum": [
{
"value": 0.5,
"value": 1.0,
"title": u"До 1000 Вт"
},
{
Expand All @@ -2409,7 +2409,7 @@ def test_tender_features_invalid(self):
self.assertEqual(response.content_type, 'application/json')
self.assertEqual(response.json['status'], 'error')
self.assertEqual(response.json['errors'], [
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.3.']}]}],
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.99.']}]}],
u'location': u'body',
u'name': u'features'}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,13 +776,13 @@ def test_tender_features_invalid(self):
{u'description': [{u'relatedItem': [u'relatedItem should be one of items']}], u'location': u'body', u'name': u'features'}
])
data['features'][0]["relatedItem"] = "1"
data['features'][0]["enum"][0]["value"] = 0.5
data['features'][0]["enum"][0]["value"] = 1.0
response = self.app.post_json('/tenders', {'data': 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'], [
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.3.']}]}], u'location': u'body', u'name': u'features'}
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.99.']}]}], u'location': u'body', u'name': u'features'}
])
data['features'][0]["enum"][0]["value"] = 0.15
response = self.app.post_json('/tenders', {'data': data}, status=422)
Expand Down Expand Up @@ -2065,13 +2065,13 @@ def test_tender_features_invalid(self):
{u'description': [{u'relatedItem': [u'relatedItem should be one of items']}], u'location': u'body', u'name': u'features'}
])
data['features'][0]["relatedItem"] = "1"
data['features'][0]["enum"][0]["value"] = 0.5
data['features'][0]["enum"][0]["value"] = 1.0
response = self.app.post_json('/tenders', {'data': 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'], [
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.3.']}]}], u'location': u'body', u'name': u'features'}
{u'description': [{u'enum': [{u'value': [u'Float value should be less than 0.99.']}]}], u'location': u'body', u'name': u'features'}
])
data['features'][0]["enum"][0]["value"] = 0.15
response = self.app.post_json('/tenders', {'data': data}, status=422)
Expand Down

0 comments on commit 81e3ba1

Please sign in to comment.