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_bool_field():
field = fields.BoolField()
class Person(models.Base):
is_programmer = field
person = Person()
assert person.is_programmer is None
person.is_programmer = True
assert person.is_programmer is True
person.is_programmer = False
assert person.is_programmer is False
assert field.parse_value(True) is True
assert field.parse_value('something') is True
def test_bool_field(self):
class Person(models.Base):
has_childen = fields.BoolField()
schema = Person.to_json_schema()
pattern = get_fixture('schema5.json')
self.assertTrue(compare_schemas(pattern, schema))
'lswitch_id': 'lswitch.id',
'ip,lswitch': ('ips', 'lswitch.id'),
'switch,owner': ('lswitch.unique_key', 'device_owner')
})
class LogicalPort(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic,
mixins.UniqueKey, mixins.BasicEvents):
table_name = "lport"
ips = df_fields.ListOfField(df_fields.IpAddressField())
subnets = df_fields.ReferenceListField(Subnet)
macs = df_fields.ListOfField(df_fields.MacAddressField())
enabled = fields.BoolField()
binding = fields.EmbeddedField(PortBinding)
lswitch = df_fields.ReferenceField(LogicalSwitch)
security_groups = df_fields.ReferenceListField(secgroups.SecurityGroup)
allowed_address_pairs = fields.ListField(AddressPair)
port_security_enabled = fields.BoolField()
device_owner = fields.StringField()
device_id = fields.StringField()
qos_policy = df_fields.ReferenceField(qos.QosPolicy)
dhcp_params = fields.EmbeddedField(DhcpParams)
binding_vnic_type = df_fields.EnumField(portbindings.VNIC_TYPES)
@property
def ip(self):
try:
return self.ips[0]
except IndexError:
return None
@property
def mac(self):
try:
nullable=True)
whole_exome_freq = fields.ListField(items_types=(str, int, float,), help_text="Whole exome frequency", required=False,
nullable=True)
whole_genome_reseq_freq = fields.ListField(items_types=(str, int, float,), help_text="Whole genome reseq frequency",
required=False, nullable=True)
resistance_mutation = fields.ListField(items_types=(str,), help_text="Resistance mutation", required=False,
nullable=True)
drug_entries = fields.ListField(items_types=(CosmicLicensedDrugEntry,), help_text="Drug entries", required=False,
nullable=True)
class ComsicPublicDetails(models.Base):
num_samples = fields.IntField(help_text='Number of samples')
id = fields.StringField(help_text='Cosmic ID')
is_consistent = fields.BoolField(help_text='Cosmic ID is consistent across databases')
class CosmicPublic(models.Base):
version = fields.StringField(help_text="Version")
items = fields.ListField(items_types=(ComsicPublicDetails, ), help_text="Details", required=False, nullable=True)
class CosmicLicensed(models.Base):
version = fields.StringField(help_text="Version")
items = fields.ListField(items_types=(CosmicLicensedDetails,), help_text="Details")
LOG = log.getLogger(__name__)
@mf.register_model
@mf.construct_nb_db_model(
indexes={
'network_type': 'network_type',
'physical_network': 'physical_network',
},
)
class LogicalSwitch(mf.ModelBase, mixins.Name, mixins.Version, mixins.Topic,
mixins.UniqueKey, mixins.BasicEvents):
table_name = "lswitch"
is_external = fields.BoolField()
mtu = fields.IntField()
segmentation_id = fields.IntField()
# TODO(oanson) Validate network_type
network_type = fields.StringField()
# TODO(oanson) Validate physical_network
physical_network = fields.StringField()
qos_policy = df_fields.ReferenceField(qos.QosPolicy)
@mf.register_model
@mf.construct_nb_db_model(
indexes={
'lswitch': 'lswitch.id',
},
)
class Subnet(mf.ModelBase, mixins.Name, mixins.Topic, mixins.Version,
from jsonmodels import models, fields
__author__ = "ckopanos"
class TranscriptItem(models.Base):
name = fields.StringField(help_text="Transcript")
coding_impact = fields.StringField(help_text="Coding impact", required=False, nullable=True)
function = fields.ListField(help_text="Function", items_types=(str,), required=False, nullable=True)
hgvs = fields.StringField(required=False, help_text="HGVS cDNA level", nullable=True)
hgvs_p1 = fields.StringField(required=False, nullable=True)
hgvs_p3 = fields.StringField(required=False, nullable=True)
hgvs_notation = fields.StringField(help_text="HGVS notation", required=False, nullable=True)
location = fields.StringField(help_text="Location", required=False, nullable=True)
coding_location = fields.StringField(help_text="Coding location", required=False, nullable=True)
canonical = fields.BoolField(help_text="Canonical", required=False, nullable=True)
gene_symbol = fields.StringField(help_text="Gene symbol", required=False, nullable=True)
class Transcript(models.Base):
items = fields.ListField(help_text='Transcripts', items_types=(TranscriptItem,), required=False)
version = fields.StringField(help_text="Version")
def _specify_field_type(field):
if isinstance(field, fields.StringField):
return {'type': 'string'}
elif isinstance(field, fields.IntField):
return {'type': 'integer'}
elif isinstance(field, fields.FloatField):
return {'type': 'float'}
elif isinstance(field, fields.BoolField):
return {'type': 'boolean'}
if field in six.string_types:
return STRING_TYPE, None
elif isinstance(field, field_types.EnumField):
field_type = ENUM_TYPE
restrictions = list(field._valid_values)
return field_type, restrictions
elif isinstance(field, field_types.ReferenceField):
model = field._model
return model.__name__, None
elif isinstance(field, fields.StringField):
return STRING_TYPE, None
elif isinstance(field, fields.IntField):
return NUMBER_TYPE, None
elif isinstance(field, fields.FloatField):
return FLOAT_TYPE, None
elif isinstance(field, fields.BoolField):
return BOOL_TYPE, None
elif isinstance(field, fields.BaseField):
return STRING_TYPE, None
else:
return field.__name__, None