How to use the jsonmodels.models.Base function in jsonmodels

To help you get started, we’ve selected a few jsonmodels examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jazzband / jsonmodels / tests / test_schema.py View on Github external
def test_model1(self):

        class Person(models.Base):

            name = fields.StringField(required=True)
            surname = fields.StringField(required=True)
            age = fields.IntField()

        alan = Person()
        schema = alan.to_json_schema()

        pattern = get_fixture('schema1.json')
        self.assertTrue(compare_schemas(pattern, schema))
github jazzband / jsonmodels / tests / test_data_initialization.py View on Github external
def test_int_field_parsing():

    class Counter(models.Base):
        value = fields.IntField()

    counter0 = Counter(value=None)
    assert counter0.value is None
    counter1 = Counter(value=1)
    assert isinstance(counter1.value, int)
    assert counter1.value == 1
    counter2 = Counter(value='2')
    assert isinstance(counter2.value, int)
    assert counter2.value == 2
    if not six.PY3:
        counter3 = Counter(value=long(3))  # noqa
        assert isinstance(counter3.value, int)
        assert counter3.value == 3
github jazzband / jsonmodels / tests / test_circular_references.py View on Github external
from jsonmodels import models, fields
from jsonmodels.utilities import compare_schemas

from .utilities import get_fixture


class Primary(models.Base):

    name = fields.StringField()
    secondary = fields.EmbeddedField('Secondary')


class Secondary(models.Base):

    data = fields.IntField()
    first = fields.EmbeddedField('Primary')


def test_generate_circular_schema():
    schema = Primary.to_json_schema()

    pattern = get_fixture('schema_circular.json')
    assert compare_schemas(pattern, schema) is True
github jazzband / jsonmodels / tests / test_struct.py View on Github external
def test_to_struct_nested_1():

    class Car(models.Base):

        brand = fields.StringField()

    class ParkingPlace(models.Base):

        location = fields.StringField()
        car = fields.EmbeddedField(Car)

    place = ParkingPlace()
    place.location = 'never never land'

    pattern = {
        'location': 'never never land',
    }
    assert pattern == place.to_struct()
github jazzband / jsonmodels / tests / test_jsonmodels.py View on Github external
class Secondary(models.Base):

        data = fields.IntField()

    class Primary(models.Base):

        name = fields.StringField()
        secondary = fields.EmbeddedField(Secondary, required=True)

    entity = Primary()
    with pytest.raises(errors.ValidationError):
        entity.validate()
    entity.secondary = Secondary()
    entity.validate()

    class Primary(models.Base):

        name = fields.StringField()
        secondary = fields.EmbeddedField(Secondary, required=False)

    entity = Primary()
    entity.validate()

    entity.secondary = None
    entity.validate()
github saphetor / varsome-api-client-python / varsome_api / models / elements / dbnsfp.py View on Github external
required=False)
    phastcons20way_mammalian_rankscore = fields.ListField(items_types=(float,),
                                                          help_text="phastCons20way mammalian rankscore",
                                                          required=False, nullable=True)
    phastcons100way_vertebrate = fields.ListField(items_types=(float,),
                                                  help_text="phastCons100way vertebrate", required=False, nullable=True)
    phastcons100way_vertebrate_rankscore = fields.ListField(items_types=(float,),
                                                            help_text="phastCons100way vertebrate rankscore",
                                                            required=False, nullable=True)
    vest3_score = fields.ListField(items_types=(float,), help_text="VEST3 score",
                                   required=False)
    vest3_rankscore = fields.ListField(items_types=(float,),
                                       help_text="VEST3 rankscore", required=False, nullable=True)


class DBscSNV(models.Base):
    version = fields.StringField(help_text="Version")
    ada_score = fields.ListField(items_types=(float, ), help_text='ADA Score', required=False, nullable=True)
    rf_score = fields.ListField(items_types=(float,), help_text='RF Score', required=False, nullable=True)
github openstack / dragonflow / dragonflow / db / model_framework.py View on Github external
>>> _normalize_tuple(['a', 'b'])
       ('a', 'b')
    """
    if isinstance(v, six.string_types):
        return v,

    return tuple(v)


def is_submodel(instance):
    return (isinstance(instance, ModelBase) or
            hasattr(instance, 'get_object'))


class _CommonBase(models.Base):
    '''Base class for extending jsonmodels' Base

    Here we add common facilities needed to support:

     * Event registration/dispatch
     * CRUD hooks
     * Serialization
     * Indexes
     * Unset field detection
    '''
    def __init__(self, **kwargs):
        for key in kwargs:
            if key not in self._field_names:
                raise TypeError(
                    _('{field} is not a field of {model}').format(
                        field=key,
github saphetor / varsome-api-client-python / varsome_api / models / elements / gnomad.py View on Github external
# 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 GnomADCoverage(models.Base):
    version = fields.StringField(help_text="Version")
    coverage_mean = fields.ListField(help_text="Mean coverage",
                                     items_types=(float, type(None)), required=False, nullable=True)
    coverage_median = fields.ListField(help_text="Median coverage",
                                       items_types=(float, type(None)), required=False, nullable=True)
    coverage_20_frequency = fields.ListField(help_text="Proportion of samples with over 20x",
                                             items_types=(float, type(None)),
                                             required=False, nullable=True)


class GnomAD(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)
github saphetor / varsome-api-client-python / varsome_api / models / elements / ncbi.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.

from jsonmodels import models, fields

from varsome_api.models.fields import DictField

__author__ = "ckopanos"


class DbSNP(models.Base):
    version = fields.StringField(help_text="Version")
    rsid = fields.ListField(items_types=(int,), help_text="RS ID")


class ClinVar2(models.Base):
    version = fields.StringField(help_text="Version")
    review_status = fields.StringField(help_text="Review status", required=False, nullable=True)
    review_stars = fields.IntField(help_text="Review stars", required=False, nullable=True)
    variation_id = fields.IntField(help_text="Variation ID", required=False, nullable=True)
    num_submitters = fields.IntField(help_text="Number of submitters", required=False, nullable=True)
    pub_med_references = fields.ListField(items_types=(int,), help_text="PubMed references", required=False,
                                          nullable=True)
    clinical_significance = fields.ListField(items_types=(str,), help_text="Clinical significance", required=False,
                                             nullable=True)
    last_evaluation = fields.StringField(help_text="Last evaluation", required=False, nullable=True)
    origin = fields.ListField(items_types=(str,), help_text="Origin", required=False, nullable=True)
    accessions = fields.ListField(items_types=(dict,), help_text="Accessions", required=False, nullable=True)
    main_data = fields.StringField(help_text="Main data point", required=False, nullable=True)