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_fields_can_have_different_names():
class Human(models.Base):
name = fields.StringField()
surname = fields.StringField(name='second-name')
chuck = Human(name='Chuck', surname='Testa')
assert chuck.to_struct() == {'name': 'Chuck', 'second-name': 'Testa'}
def test_model2(self):
class Car(models.Base):
brand = fields.StringField(required=True)
registration = fields.StringField(required=True)
class Toy(models.Base):
name = fields.StringField(required=True)
class Kid(models.Base):
name = fields.StringField(required=True)
surname = fields.StringField(required=True)
age = fields.IntField()
toys = fields.ListField(Toy)
class Person(models.Base):
name = fields.StringField(required=True)
surname = fields.StringField(required=True)
def test_validation():
validator1 = FakeValidator()
validator2 = FakeValidator()
called = []
arg = []
def validator3(value):
called.append(1)
arg.append(value)
class Person(models.Base):
name = fields.StringField(
required=True, validators=[validator1, validator2])
surname = fields.StringField(required=True)
age = fields.IntField(validators=validator3)
cash = fields.FloatField()
person = Person()
person.name = 'John'
person.surname = 'Smith'
person.age = 33
person.cash = 123567.89
validator1.assert_called_once_with('John')
validator2.assert_called_once_with('John')
assert 1 == sum(called)
assert 33 == arg.pop()
def test_regex_validator(self):
class Person(models.Base):
name = fields.StringField(
validators=validators.Regex('^some pattern$'))
schema = Person.to_json_schema()
pattern = get_fixture('schema_pattern.json')
self.assertTrue(compare_schemas(pattern, schema))
def test_model_with_constructors(self):
class Car(models.Base):
def __init__(self, some_value):
pass
brand = fields.StringField(required=True)
registration = fields.StringField(required=True)
class Toy(models.Base):
def __init__(self, some_value):
pass
name = fields.StringField(required=True)
class Kid(models.Base):
def __init__(self, some_value):
pass
name = fields.StringField(required=True)
surname = fields.StringField(required=True)
class GWASDetails(models.Base):
gwas_symbol = fields.StringField(help_text="GWAS symbol", required=False, nullable=True)
date = fields.StringField(help_text="Date", required=False, nullable=True)
study = fields.StringField(help_text="Study", required=False, nullable=True)
disease_or_trait = fields.StringField(help_text="Disease or trait", required=False, nullable=True)
mapped_traits = fields.ListField(items_types=(str,), help_text="Mapped trait", required=False, nullable=True)
mapped_trait_urls = fields.ListField(items_types=(str,), help_text="Mapped trait URL", required=False,
nullable=True)
strongest_snp_risk_allele = fields.StringField(help_text="Strongest SNP risk allele", required=False, nullable=True)
odds_ratio = fields.FloatField(help_text="Odds ratio", required=False, nullable=True)
p_value = fields.StringField(help_text="p value", required=False, nullable=True)
confidence_range_95_low = fields.FloatField(help_text="Confidence range 95% low", required=False, nullable=True)
confidence_range_95_high = fields.FloatField(help_text="Confidence range 95% high", required=False, nullable=True)
confidence_comment = fields.StringField(help_text="Confidence comment", required=False, nullable=True)
initial_sample_size = fields.StringField(help_text="Initial sample size", required=False, nullable=True)
replication_sample_size = fields.StringField(help_text="Replication sample size", required=False, nullable=True)
pub_med_references = fields.ListField(items_types=(int,), help_text="PubMed References", required=False,
nullable=True)
class GWAS(models.Base):
version = fields.StringField(help_text="Version")
items = fields.ListField(help_text='Details', items_types=(GWASDetails,))
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'}
class Cosmic(models.Base):
version = fields.StringField(help_text="Version")
primary_site = fields.ListField(items_types=(str,), help_text="Primary site", required=False, nullable=True)
pub_med_references = fields.ListField(items_types=(int,), help_text="PUBMED References", required=False,
nullable=True)
class CosmicLicensedDrugEntry(models.Base):
drug_name = fields.StringField(help_text="Drug name", required=False, nullable=True)
somatic_status = fields.StringField(help_text="Somatic status", required=False, nullable=True)
zygosity = fields.StringField(help_text="Zygosity", required=False, nullable=True)
gene = fields.StringField(help_text="Gene", required=False, nullable=True)
transcript = fields.StringField(help_text="Transcript", required=False, nullable=True)
census_gene = fields.StringField(help_text="Census gene", required=False, nullable=True)
pub_med_references = fields.ListField(items_types=(int,), help_text="PUBMED References", required=False,
nullable=True)
histology_freq = fields.ListField(items_types=(float,), help_text="Histology frequency", required=False,
nullable=True)
tissue_freq = fields.ListField(items_types=(float,), help_text="Tissue frequency", required=False, nullable=True)
class CosmicLicensedDetails(models.Base):
entry_type = fields.StringField(help_text="Entry type", required=False, nullable=True)
cosmic_id = fields.ListField(items_types=(str, dict,), help_text="Cosmic ID", required=False, nullable=True)
pub_med_references = fields.ListField(items_types=(int,), help_text="PUBMED References", required=False,
nullable=True)
histology_freq = fields.ListField(items_types=(int, str, float), help_text="Histology frequency", required=False,
nullable=True)
genome_wide_screen_freq = fields.ListField(items_types=(int, str, float), help_text="Histology frequency", required=False,
nullable=True)
import dragonflow.db.model_framework as mf
from dragonflow.db.models import host_route
from dragonflow.db.models import mixins
# NOTE(xiaohui):
# As both BGPSpeaker and BGPPeer from neutron don't have revision_num now,
# skip adding version to db modles.
@mf.register_model
@mf.construct_nb_db_model
class BGPPeer(mf.ModelBase, mixins.Topic, mixins.Name):
table_name = "bgp_peer"
peer_ip = df_fields.IpAddressField(required=True)
remote_as = fields.IntField(required=True)
auth_type = fields.StringField()
password = fields.StringField()
@mf.register_model
@mf.construct_nb_db_model(indexes={'peer_id': 'peers.id'})
class BGPSpeaker(mf.ModelBase, mixins.Topic, mixins.Name):
table_name = "bgp_speaker"
local_as = fields.IntField(required=True)
peers = df_fields.ReferenceListField(BGPPeer)
host_routes = fields.ListField(host_route.HostRoute)
prefix_routes = fields.ListField(host_route.HostRoute)
ip_version = fields.IntField(required=True)
def remove_peer(self, peer_id):
self.peers[:] = [peer for peer in self.peers if peer.id != peer_id]
mut_rate = fields.IntField(help_text="Mutation rate", required=False, nullable=True)
pub_med_references = fields.ListField(items_types=(int,), help_text="PubMed References", required=False,
nullable=True)
sample_source = fields.StringField(help_text="Sample source", required=False, nullable=True)
stage = fields.StringField(help_text="Stage", required=False, nullable=True)
structural_motif = fields.StringField(help_text="Structural Motif", required=False, nullable=True)
topography = fields.StringField(help_text="Topography", required=False, nullable=True)
class TP53Germline(models.Base):
version = fields.StringField(help_text="Version")
items = fields.ListField(help_text='Details', items_types=(TP53GermlineDetails,))
class TP53Somatic(models.Base):
version = fields.StringField(help_text="Version")
items = fields.ListField(help_text='Details', items_types=(TP53SomaticDetails,))