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_list_field_types_when_assigning():
class Wheel(models.Base):
pass
class Wheel2(models.Base):
pass
class Car(models.Base):
wheels = fields.ListField(items_types=[Wheel])
viper = Car()
viper.wheels.append(Wheel())
viper.wheels[0] = Wheel()
with pytest.raises(errors.ValidationError):
viper.wheels[1] = Wheel2
def test_regex_validator():
class Person(models.Base):
name = fields.StringField(
validators=validators.Regex('^[a-z]+$', ignorecase=True))
person = Person()
with pytest.raises(errors.ValidationError):
person.name = '123'
person.name = 'Jimmy'
secondary = fields.EmbeddedField('...tests.test_lazy_loading.Secondary')
class Seventh(models.Base):
name = fields.StringField()
secondary = fields.EmbeddedField('....tests.test_lazy_loading.Secondary')
class Eighth(models.Base):
name = fields.StringField()
secondary = fields.EmbeddedField('.SomeWrongEntity')
class Secondary(models.Base):
data = fields.IntField()
@pytest.mark.parametrize(['model'], [
(Primary,),
(Third,),
(Fourth,),
(Fifth,),
(Sixth,),
])
def test_embedded_model(model):
entity = model()
assert entity.secondary is None
entity.name = 'chuck'
entity.secondary = Secondary()
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')
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'}
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)
loh_freq = fields.ListField(items_types=(int, str, float), help_text="LOH frequency", required=False, nullable=True)
age_freq = fields.ListField(items_types=(int, str, float), help_text="Age frequency", required=False, nullable=True)
zygosity_freq = fields.ListField(items_types=(int, str, float), help_text="Zygosity frequency", required=False,
nullable=True)
tumour_origin_freq = fields.ListField(items_types=(int, str, float,), help_text="Tumour original frequency", required=False,
nullable=True)
somatic_status_freq = fields.ListField(items_types=(int, str, float), help_text="Somatic status frequency", required=False,
nullable=True)
class AddressPair(models.Base):
ip_address = df_fields.IpAddressField(required=True)
mac_address = df_fields.MacAddressField(required=True)
class DhcpParams(models.Base):
opts = df_fields.DhcpOptsDictField()
siaddr = df_fields.IpAddressField()
BINDING_CHASSIS = 'chassis'
BINDING_VTEP = 'vtep'
class PortBinding(models.Base):
type = df_fields.EnumField((BINDING_CHASSIS, BINDING_VTEP), required=True)
chassis = df_fields.ReferenceField(core.Chassis)
vtep_address = df_fields.IpAddressField()
@property
def ip(self):
if self.type == BINDING_CHASSIS:
return self.chassis.ip
elif self.type == BINDING_VTEP:
return self.vtep_address
return None
@property
def is_local(self):
if self.type == BINDING_CHASSIS:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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")
log.debug('Loaded file %s (%s)' % (path, content_type))
return web.Response(body=data, content_type=content_type)
class StringChoiceField(fields.StringField):
def __init__(self, choices=None, *args, **kw):
self.choices = choices or []
super().__init__(*args, **kw)
def validate(self, value):
if value not in self.choices:
raise ValidationError('invalid choice value')
super().validate(value)
class Jsep(models.Base):
type = StringChoiceField(choices=['offer', 'answer'], required=True)
sdp = fields.StringField(required=True)
class Candidate(models.Base):
candidate = fields.StringField(required=True)
sdpMid = fields.StringField(required=True)
sdpMLineIndex = fields.IntField(required=True)
class YoPayload(models.Base):
yo = fields.StringField(required=True)
jsep = fields.EmbeddedField(Jsep)
candidate = fields.EmbeddedField(Candidate)
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from jsonmodels import models, fields
__author__ = "ckopanos"
class ExAC(models.Base):
version = fields.StringField(help_text="Version")
ac = fields.IntField(help_text="Allele Count", required=False, nullable=True)
an = fields.IntField(help_text="Allele Number", required=False, nullable=True)
ac_adj = fields.FloatField(help_text="Allele Count", required=False, nullable=True)
an_adj = fields.FloatField(help_text="Allele Number", required=False, nullable=True)
af = fields.FloatField(help_text="Allele Frequency", required=False, nullable=True)
ac_afr = fields.IntField(help_text="Allele Count African", required=False, nullable=True)
ac_amr = fields.IntField(help_text="Allele Count American", required=False, nullable=True)
ac_asj = fields.IntField(help_text="Allele Count Ashkenazi Jewish", required=False, nullable=True)
ac_eas = fields.IntField(help_text="Allele Count East Asian", required=False, nullable=True)
ac_fin = fields.IntField(help_text="Allele Count European (Finnish)", required=False, nullable=True)
ac_nfe = fields.IntField(help_text="Allele Count European (Non-Finnish)", required=False, nullable=True)
ac_oth = fields.IntField(help_text="Allele Count Other", required=False, nullable=True)
ac_sas = fields.IntField(help_text="Allele Count South Asian", required=False, nullable=True)
ac_male = fields.IntField(help_text="Allele Count Male", required=False, nullable=True)
ac_female = fields.IntField(help_text="Allele Count Female", required=False, nullable=True)