Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_validate_required_on_init():
class Foo(Model):
bar = BooleanType(required=True)
baz = BooleanType()
foo = Foo({'baz': 0}, partial=True, validate=True)
foo.bar = 1
assert foo.serialize() == {'bar': True, 'baz': False}
profile = StringType(serialize_when_none=False)
class_path = StringType(serialize_when_none=False)
template_path = StringType(serialize_when_none=False)
description = StringType(serialize_when_none=False)
requires = ListType(StringType, serialize_when_none=False)
required_by = ListType(StringType, serialize_when_none=False)
locked = BooleanType(default=False)
enabled = BooleanType(default=True)
protected = BooleanType(default=False)
variables = DictType(AnyType, serialize_when_none=False)
parameters = DictType(AnyType, serialize_when_none=False)
tags = DictType(StringType, serialize_when_none=False)
stack_policy_path = StringType(serialize_when_none=False)
in_progress_behavior = StringType(serialize_when_none=False)
def validate_class_path(self, data, value):
if value and data["template_path"]:
raise ValidationError(
event_id = StringType()
market_id = StringType()
selection_id = IntType()
handicap = FloatType()
bet_id = StringType()
placed_date = DateTimeType()
persistence_type = EnumType(constants.PersistenceType)
order_type = EnumType(constants.OrderType)
side = EnumType(constants.Side)
item_description = ModelType(ItemDescription)
price_requested = FloatType()
settled_date = DateTimeType()
bet_count = IntType()
commission = FloatType()
price_matched = FloatType()
price_reduced = BooleanType()
size_settled = FloatType()
profit = FloatType()
size_cancelled = FloatType()
class ClearedOrderSummaryReport(BetfairModel):
cleared_orders = ListType(ModelType(ClearedOrderSummary), required=True)
more_available = BooleanType(required=True)
# Instruction reports
class BaseInstructionReport(BetfairModel):
status = EnumType(constants.InstructionReportStatus, required=True)
error_code = EnumType(constants.InstructionReportErrorCode)
LOG = logging.getLogger(__name__)
class _SortedListType(schematics.types.ListType):
def convert(self, value, context=None):
value = super(_SortedListType, self).convert(value, context=context)
return sorted(value)
class Requirement(schematics.models.Model):
version = schematics.types.StringType(required=True)
is_direct = schematics.types.BooleanType(required=True)
source = schematics.types.StringType(required=True)
dependencies = _SortedListType(
schematics.types.StringType,
default=[],
)
class Environment(schematics.models.Model):
sys_platform = schematics.types.StringType()
python_version = schematics.types.IntType(choices=[2, 3])
requirements = schematics.types.DictType(
schematics.types.ModelType(Requirement),
default={},
)
cpv_validator,
validate_uniq,
validate_dkpp,
)
from openprocurement.api.models.roles import (
item_roles,
related_process_roles,
)
schematics_default_role = SchematicsDocument.Options.roles['default'] + blacklist("__parent__")
schematics_embedded_role = SchematicsDocument.Options.roles['embedded'] + blacklist("__parent__")
class Value(BasicValue):
valueAddedTaxIncluded = BooleanType(required=True, default=True)
# The currency in 3-letter ISO 4217 format.
currency = StringType(required=True, default=DEFAULT_CURRENCY, max_length=3, min_length=3)
class FeatureValue(Model):
value = FloatType(required=True, min_value=0.0, max_value=0.3)
title = StringType(required=True, min_length=1)
title_en = StringType()
title_ru = StringType()
description = StringType()
description_en = StringType()
description_ru = StringType()
def validate_values_uniq(values, *args):
cachedBalance = FloatType()
masterCategoryId = StringType()
isResolvedConflict = BooleanType()
note = StringType()
class MasterCategory(Category):
deleteable = BooleanType()
expanded = BooleanType()
subCategories = ListType(ModelType(SubCategory))
class Account(DeletableEntity):
accountName = StringType()
accountType = StringType()
hidden = BooleanType()
onBudget = BooleanType()
lastReconciledDate = DateType()
lastReconciledBalance = FloatType()
lastEnteredCheckNumber = FloatType()
sortableIndex = IntType()
note = StringType()
class PayeeLocation(DeletableEntity):
parentPayeeId = StringType()
latitude = FloatType()
longitude = FloatType()
isResolvedConflict = BooleanType()
class PayeeRenameConditions(DeletableEntity):
def to_patch(self, role=None):
"""
Return data as it would be validated. No filtering of output unless
role is defined.
"""
field_converter = lambda field, value: field.to_primitive(value)
data = export_loop(self.__class__, self, field_converter, role=role, raise_error_on_role=True, print_none=True)
return data
class Value(Model):
amount = FloatType(required=True, min_value=0) # Amount as a number.
currency = StringType(required=True, default=u'UAH', max_length=3, min_length=3) # The currency in 3-letter ISO 4217 format.
valueAddedTaxIncluded = BooleanType(required=True, default=True)
class Period(Model):
"""The period when the tender is open for submissions. The end date is the closing date for tender submissions."""
startDate = IsoDateTimeType() # The state date for the period.
endDate = IsoDateTimeType() # The end date for the period.
def validate_startDate(self, data, value):
if value and data.get('endDate') and data.get('endDate') < value:
raise ValidationError(u"period should begin before its end")
class PeriodEndRequired(Period):
endDate = IsoDateTimeType(required=True) # The end date for the period.
class ExchangePrices(BetfairModel):
available_to_back = ListType(ModelType(PriceSize))
available_to_lay = ListType(ModelType(PriceSize))
traded_volume = ListType(ModelType(PriceSize))
class Order(BetfairModel):
bet_id = StringType(required=True)
order_type = EnumType(constants.OrderType, required=True)
status = EnumType(constants.OrderStatus, required=True)
persistence_type = EnumType(constants.PersistenceType, required=True)
side = EnumType(constants.Side, required=True)
price = FloatType(required=True)
size = FloatType(required=True)
bsp_liability = BooleanType(required=True)
placed_date = DateTimeType(required=True)
avg_price_matched = FloatType()
size_matched = FloatType()
size_remaining = FloatType()
size_lapsed = FloatType()
size_cancelled = FloatType()
size_voided = FloatType()
class Match(BetfairModel):
bet_id = StringType()
match_id = StringType()
side = EnumType(constants.Side, required=True)
price = FloatType(required=True)
size = FloatType(required=True)
match_date = DateTimeType()