Esempio n. 1
0
class UserScheme(BaseModelScheme):
    user_id = Str()

    email = Email(required=True,
                  allow_none=False,
                  validate=[
                      validate.Email(error='Incorrect email address'),
                      lambda value: _valid_unique('User', 'email', value)
                  ])
    password = Str(validate=[validate.Length(max=72)])
    is_admin = Bool()
    last_login = DateTime()
    is_active = Bool()
    created_on = DateTime()
    phone = Str(required=True,
                allow_none=False,
                validate=[
                    validate.Regexp(PHONE_REGEXP),
                    lambda value: _valid_unique('User', 'phone', value)
                ])

    logo_file_uuid = FileSchemeField(model.FileModel,
                                     'User',
                                     'logo',
                                     required=False)
    logo = Nested('FileModelScheme', many=False)

    class Meta:
        model = model.User
        fields = ('email', 'passwd', 'is_admin', 'is_active', 'logo_file_uuid')
class ExtractROISchema(Schema):
    """This ROI format is the expected input of AllenSDK's extract_traces
    'rois' field
    """

    id = Int(required=True,
             description=("Unique ID of the ROI, gets overwritten writting "
                          "to LIMS"))
    x = Int(required=True,
            description="X location of top left corner of ROI in pixels")
    y = Int(required=True,
            description="Y location of top left corner of ROI in pixels")
    width = Int(required=True, description="Width of the ROI in pixels")
    height = Int(required=True, description="Height of the ROI in pixels")
    mask = List(List(Bool),
                required=False,
                description=("Bool nested list describing which pixels "
                             "in the ROI area are part of the cell"
                             "'mask' and 'mask_matrix' are aliases and "
                             "one must be specified."))
    mask_matrix = List(List(Bool),
                       required=False,
                       description=("Bool nested list describing which pixels "
                                    "in the ROI area are part of the cell"
                                    "'mask' and 'mask_matrix' are aliases and "
                                    "one must be specified."))
    valid = Bool(required=False,
                 description=("Boolean indicating if the ROI is a valid "
                              "cell or not. 'valid' and 'valid_roi' are "
                              "aliases and one must be specified."))
    valid_roi = Bool(required=False,
                     description=("Boolean indicating if the ROI is a valid "
                                  "cell or not. 'valid' and 'valid_roi' are "
                                  "aliases and one must be specified."))

    @post_load
    def check_aliases(self, data, **kwargs):
        # decrosstalk strategy using 'mask_matrix' and 'valid_roi'
        # trace_extraction strategy using 'mask' and 'valid'
        def check(k1, k2):
            if (k1 not in data) & (k2 not in data):
                raise ValidationError(f"one of {k1} or {k2} needed")
            if (k1 in data) & (k2 in data):
                if data[k1] != data[k2]:
                    raise ValidationError(f"{k1} and {k2} provided, "
                                          "but they differ")

        check("valid_roi", "valid")
        check("mask_matrix", "mask")
        return data
Esempio n. 3
0
class LicenseSwitchSchemeModify(LicenseSwitchScheme):
    ip = Str(validate=[validate.Length(max=16), validate.Regexp(IP_REGEXP)])
    enabled = Bool(attribute='is_enabled')

    class Meta:
        model = model.LicenseSwitch
        fields = ('package_switch_uuid', 'ip', 'enabled', 'end_time')
Esempio n. 4
0
class Product(Schema):
    class Meta:
        ordered = True

    _id = UUID(required=False, allow_none=False, missing=uuid.uuid4)
    name = String(required=True,
                  description='Nome do produto.',
                  validate=Length(min=1, max=1000))
    description = String(required=True,
                         description='Descrição do produto.',
                         validate=Length(min=1, max=1000))
    price = Float(required=True, description='Valor do produto.')
    enabled = Bool(required=False,
                   description='Se o produto está ativado ou desativado.',
                   missing=True)
    created_at = DateTime(required=False,
                          allow_none=True,
                          description='Criado em.',
                          missing=datetime.now,
                          format=DATETIME_FORMAT)
    updated_at = DateTime(required=False,
                          allow_none=True,
                          description='Atualizado em.',
                          format=DATETIME_FORMAT)
    deleted_at = DateTime(required=False,
                          allow_none=True,
                          description='Deletado em.',
                          format=DATETIME_FORMAT)
Esempio n. 5
0
class PreQuestionSchema(Schema):
    nodeId = Str()
    slug = Str()
    langauge = Str()
    text = Str()
    randomize = Bool()
    addedOn = DateTime()
Esempio n. 6
0
def app_config(app_config):
    """Override conftest.py's app_config
    """
    # Added custom configuration
    app_config['RDM_RECORDS_METADATA_NAMESPACES'] = {
        'dwc': {
            '@context': 'https://example.com/dwc/terms'
        },
        'nubiomed': {
            '@context': 'https://example.com/nubiomed/terms'
        }
    }

    app_config['RDM_RECORDS_METADATA_EXTENSIONS'] = {
        'dwc': {
            'family': {
                'elasticsearch': 'keyword',
                'marshmallow': SanitizedUnicode(required=True)
            },
            'behavior': {
                'elasticsearch': 'text',
                'marshmallow': SanitizedUnicode()
            }
        },
        'nubiomed': {
            'right_or_wrong': {
                'elasticsearch': 'boolean',
                'marshmallow': Bool()
            }
        }
    }

    return app_config
Esempio n. 7
0
class LicenseSwitchScheme(BaseModelScheme):
    user_email = Str(validate=[validate.Length(max=128)])
    type = Int()
    ip = Str(required=True,
             allow_none=False,
             validate=[validate.Length(max=16),
                       validate.Regexp(IP_REGEXP)])
    switch_port = Int()
    minute_count = Int()
    amount = Int()
    license_switch_uuid = Str(validate=[validate.Length(max=36)])
    package_switch_uuid = Str(validate=[
        validate.Length(max=36),
        lambda value: _valid('PackageSwitch', 'package_switch_uuid', value)
    ])
    user_uuid = Str(validate=[
        validate.Length(
            max=36), lambda value: _valid('User', 'user_uuid', value)
    ])
    start_time = DateTime()
    end_time = DateTime()
    duration = Choice()
    ordered_amount = Int()
    cost = Float()
    package = Nested('PackageSwitchScheme', many=False)
    enabled = Bool()
    switch_uuid = Str(validate=[
        validate.Length(
            max=64), lambda value: _valid('DnlLicenseInfo', 'uuid', value)
    ])

    class Meta:
        model = model.LicenseSwitch
        fields = ('package_switch_uuid', 'ip', 'start_time', 'duration',
                  'switch_uuid')
Esempio n. 8
0
class EmbargoSchema(Schema):
    """Schema for an embargo on the record."""

    active = Bool(allow_none=True, missing=None)
    until = ISODateString(allow_none=True, missing=None)
    reason = SanitizedUnicode(allow_none=True, missing=None)

    @validates_schema
    def validate_embargo(self, data, **kwargs):
        """Validate that the properties are consistent with each other."""
        if data.get("until") is not None:
            until_date = arrow.get(data.get("until"))
        else:
            until_date = None

        if data.get("active", False):
            if until_date is None or until_date < arrow.utcnow():
                raise ValidationError(
                    _("Embargo end date must be set to a future date "
                      "if active is True."),
                    field_name="until",
                )

        elif data.get("active", None) is not None:
            if until_date is not None and until_date > arrow.utcnow():
                raise ValidationError(
                    _("Embargo end date must be unset or in the past "
                      "if active is False."),
                    field_name="until",
                )
Esempio n. 9
0
class UserScheme(BaseModelScheme):
    passwd = Str()
    is_admin = Bool()
    is_active = Bool()
    email = Email(allow_none=True,
                  validate=[
                      validate.Email(error='Incorrect email address'),
                      lambda value: _valid_unique('User', 'email', value)
                  ])
    logo_file_uuid = FileSchemeField(model.FileModel,
                                     'User',
                                     'logo',
                                     required=False)

    class Meta:
        model = model.User
        fields = ('passwd', 'is_admin', 'email', 'is_active')
Esempio n. 10
0
class RegisterConfig(ConfMetaSchema):
    multicluster_name = Str()
    stateful = Bool()
    register = Nested(Register, many=True)

    dependencies = Nested("RegisterConfig",
                          many=True,
                          exclude=("dependencies", ))
Esempio n. 11
0
class Register(ConfMetaSchema):
    module = Str()
    cluster_name = Str()
    args = List(Str())
    kwargs = Dict()
    provisioner = Str()
    exec_filter = Nested(ExecFilter())
    stateful = Bool()

    dependencies = Nested("Register", many=True, exclude=("dependencies", ))
class DatasetSchema(Schema):
    author = Str()
    author_email = Str()
    creator_user_id = UUID()
    extras = Nested(ExtraSchema, many=True)
    groups = Nested(CategorySchema, many=True)
    license_id = Str()
    license_title = Str()
    license_url = URL()
    maintainer = Str()
    maintainer_email = Str()
    created = DateTime(data_key='metadata_created')
    modified = DateTime(data_key='metadata_modified', allow_none=True)
    slug = Str(data_key='name')
    notes = Str()
    num_resources = Int()
    num_tags = Int()
    ext_ident = Str(data_key='id', validate=validate.Length(max=36))
    isopen = Bool()
    organization = Nested(OrganizationSchema, many=False)
    owner_org = UUID()
    private = Bool()
    relationships_as_object = Nested(RelationshipObjectSchema, many=True)
    relationships_as_subject = Nested(RelationshipSubjectSchema, many=True)
    resources = Nested(ResourceSchema, many=True)
    revision_id = UUID()
    status = Str(data_key='state')
    tags = Nested(TagSchema, many=True)
    title = Str()
    type = Str()
    url = Str()
    version = Str()

    class Meta:
        exclude = [
            'author', 'author_email', 'creator_user_id', 'extras', 'groups',
            'license_title', 'license_url', 'maintainer', 'maintainer_email',
            'num_resources', 'num_tags', 'isopen', 'owner_org', 'private',
            'relationships_as_object', 'relationships_as_subject',
            'revision_id', 'type', 'status', 'url', 'version'
        ]
        ordered = True
        unknown = EXCLUDE
Esempio n. 13
0
class PackageSwitchMinuteScheme(BaseModelScheme):
    package_switch_uuid = Str(validate=[validate.Length(max=36)])
    package_name = Str(validate=[validate.Length(max=64)])
    amount = Int()
    enabled = Bool()
    rate_per_minute = Float()

    class Meta:
        model = model.PackageSwitch
        fields = ('package_switch_uuid', 'package_name', 'amount', 'enabled',
                  'rate_per_minute')
Esempio n. 14
0
class Algorithm_Catalog_Parameter_Schema(Schema):
    """Algorithm parameter."""

    id = Str(required=True, example='frequency', description='Parameter id.')
    type = Str(required=True, enum=PARAMETER_TYPES, example=PARAMETER_TYPES[0],
               description='Parameter type.', validate=validate.OneOf(PARAMETER_TYPES))
    list = Bool(default=False, example=True, description='Indicate if the parameter can have multiple values.')
    values = List_or_One(Str, example='mysql', description='Possible values if the parameter type is choice.')
    encoding_scheme = Str(default='base64', example='base64', description='Encoding scheme used to store the binary data')
    description = Str(example='Enable the algorithm.', description='Short description of the parameter.')
    example = Raw(example='10s', description='Example of parameter value.')
Esempio n. 15
0
class Base_Response_Schema(Schema):
    """Response for the item creation."""

    status = Str(required=True, enum=RESPONSE_STATUS, example=RESPONSE_STATUS[0],
                 description='HTTP Status Code phrase.', validate=validate.OneOf(RESPONSE_STATUS))
    error = Bool(default=False, example=False, description='Indicate the presence of an error')
    message = Str(required=True, example='Request not valid: two ids provided.',
                  description='Human readable message that describes the status of the operation.')
    exception = Nested(Exception_Response_Schema, description='Message of the occurred exception.')
    code = Integer(required=True, enum=RESPONSE_CODES, example=RESPONSE_CODES[0],
                   description='HTTP Status Code.', validate=validate.OneOf(RESPONSE_CODES))
Esempio n. 16
0
class Agent_Catalog_Action_Config_Schema(Schema):
    """Agent action configuration."""

    cmd = Str(required=True,
              example='service filebeat start',
              description='Action command.')
    args = List_or_One(Str,
                       example='-v',
                       description='Action command argument')
    daemon = Bool(default=False,
                  example=True,
                  description='Execute the command as daemon.')
Esempio n. 17
0
class JobsSerializer(Schema):
    company = Str(required=True)
    company_logo = Str(required=True)
    company_url = Str(required=True)
    created_at = Str(required=True)
    description = Str(required=True)
    fulltime = Bool(required=True)
    how_to_apply = Str(required=True)
    id = UUID(required=True)
    location = Str(required=True)
    title = Str(required=True)

    fulltime = Function(lambda obj: obj["type"] == "Full Time", data_key="fulltime")
Esempio n. 18
0
class UserInfoScheme(BaseModelScheme):
    first_name = Str(allow_none=True, required=False)
    last_name = Str(allow_none=True, required=False)
    passwd = Str(required=True)
    email = Email(validate=[
        validate.Email(error='Incorrect email address'),
        lambda value: _valid_unique('User', 'email', value)
    ])
    logo_file_uuid = FileSchemeField(model.FileModel,
                                     'User',
                                     'logo',
                                     required=False)
    alert_payment_received = Bool()
    alert_license_expired = Bool()
    alert_license_will_expired = Bool()
    alert_license_purchased = Bool()

    class Meta:
        model = model.User
        fields = ('passwd', 'email', 'alert_payment_received',
                  'alert_license_expired', 'alert_license_will_expired',
                  'alert_license_purchased', 'logo_file_uuid', 'first_name',
                  'last_name')
Esempio n. 19
0
class ConfigPaymentScheme(BaseModelScheme):
    id = Int()
    charge_type = Choice()
    stripe_email = Str(validate=[validate.Length(max=64)])
    stripe_skey = Str(validate=[validate.Length(max=64)])
    stripe_pkey = Str(validate=[validate.Length(max=64)])
    stripe_svc_charge = Float()
    stripe_test_mode = Bool()
    paypal_email = Str(validate=[validate.Length(max=64)])
    paypal_skey = Str(validate=[validate.Length(max=128)])
    paypal_client_id = Str(validate=[validate.Length(max=128)])
    paypal_svc_charge = Float()
    paypal_test_mode = Bool()
    confirm_enabled = Bool()
    email_confirm_to = Str(validate=[validate.Length(max=64)])
    notification_enabled = Bool()
    email_cc_to = Str(validate=[validate.Length(max=64)])

    class Meta:
        model = model.ConfigPayment
        fields = (
            'charge_type',
            'stripe_skey',
            'stripe_pkey',
            'stripe_svc_charge',
            'stripe_test_mode',
            'paypal_email',
            'paypal_skey',
            'paypal_client_id',
            'paypal_svc_charge',
            'paypal_test_mode',
            'confirm_enabled',
            'email_confirm_to',
            'notification_enabled',
            'email_cc_to',
        )
class ResourceSchema(ResourceMixin, Schema):
    mimetype = Str(allow_none=True)
    cache_last_updated = Str(allow_none=True)
    cache_url = Str(allow_none=True)
    created = DateTime()
    description = Str()
    hash = Str()
    ext_ident = Str(data_key='id', validate=validate.Length(max=36))
    modified = DateTime(data_key='last_modified', allow_none=True)
    mimetype_inner = Str(allow_none=True)
    title = Str(data_key='name')
    format = Str()
    link = URL(data_key='url')
    datastore_active = Bool()
    package_id = UUID()
    position = Int()
    resource_type = Str(allow_none=True)
    revision_id = UUID()
    size = Str(allow_none=True)
    state = Str()
    url_type = Str(allow_none=True)

    class Meta:
        fields = ('created', 'modified', 'ext_ident', 'title', 'description',
                  'link', 'format')
        unknown = EXCLUDE

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # TODO: Does it makes sense to validate format here? Disabled for now.
        self.format_validation = False

    @validates_schema
    def validate_format(self, data, **kwargs):
        value = data.get('format')
        if self.format_validation and value and value not in SUPPORTED_RESOURCE_FORMATS:
            error = _('Unsupported format: %(format)s.') % {'format': value}
            raise ValidationError(error, field_name='format')

    @pre_load
    def prepare_data(self, data, **kwargs):
        if 'format' in data:
            value = data['format'].lower()
            if value not in SUPPORTED_RESOURCE_FORMATS:
                value = ''
            data['format'] = value
        return data
class DenseROISchema(Schema):
    """This ROI format is the expected output of Segmentation/Binarization
    and the expected input of Feature_extraction/Classification.
    """

    id = Int(required=True,
             description=("Unique ID of the ROI, gets overwritten writting "
                          "to LIMS"))
    x = Int(required=True,
            description="X location of top left corner of ROI in pixels")
    y = Int(required=True,
            description="Y location of top left corner of ROI in pixels")
    width = Int(required=True, description="Width of the ROI in pixels")
    height = Int(required=True, description="Height of the ROI in pixels")
    valid_roi = Bool(required=True,
                     description=("Boolean indicating if the ROI is a valid "
                                  "cell or not"))
    mask_matrix = List(List(Bool),
                       required=True,
                       description=("Bool nested list describing which pixels "
                                    "in the ROI area are part of the cell"))
    max_correction_up = Float(required=True,
                              description=("Max correction in pixels in the "
                                           "up direction"))
    max_correction_down = Float(required=True,
                                description=("Max correction in pixels in the "
                                             "down direction"))
    max_correction_left = Float(required=True,
                                description=("Max correction in pixels in the "
                                             "left direction"))
    max_correction_right = Float(required=True,
                                 description="Max correction in the pixels in "
                                 "the right direction")
    mask_image_plane = Int(required=True,
                           description=("The old segmentation pipeline stored "
                                        "overlapping ROIs on separate image "
                                        "planes. For compatibility purposes, "
                                        "this field must be kept, but will "
                                        "always be set to zero for the new "
                                        "updated pipeline"))
    exclusion_labels = List(Str,
                            required=True,
                            description=("LIMS ExclusionLabel names used to "
                                         "track why a given ROI is not "
                                         "considered a valid_roi. (examples: "
                                         "motion_border, "
                                         "classified_as_not_cell)"))
Esempio n. 22
0
class PackageSwitchScheme(BaseModelScheme):
    package_switch_uuid = Str(validate=[validate.Length(max=36)])
    package_name = Str(validate=[validate.Length(max=64)])
    type = Choice()
    sub_type = Choice()
    switch_port = Int()
    minute_count = Int()
    amount = Int()
    enabled = Bool()
    start_date = DateTime()
    expire_date = DateTime()
    licenses = Nested('LicenseSwitchScheme', many=True)

    class Meta:
        model = model.PackageSwitch
        fields = ('package_name', 'type', 'sub_type', 'switch_port',
                  'minute_count', 'amount', 'enabled', 'start_date',
                  'expire_date')
def app_config(app_config):
    """Override conftest.py's app_config
    """
    app_config['ILS_RECORDS_METADATA_NAMESPACES'] = {
        "document": {
            "accelerator_experiments": {
                "@context": "https://example.com/accelerator_experiments/terms"
            },
            "standard_status": {
                "@context": "https://example.com/standard_status/terms"
            },
        }
    }

    app_config['ILS_RECORDS_METADATA_EXTENSIONS'] = {
        "document": {
            "accelerator_experiments:accelerator": {
                "elasticsearch": "keyword",
                "marshmallow": SanitizedUnicode(required=True)
            },
            'accelerator_experiments:project': {
                'elasticsearch': 'text',
                'marshmallow': SanitizedUnicode()
            },
            'accelerator_experiments:number_in_sequence': {
                'elasticsearch': 'long',
                'marshmallow': Integer()
            },
            'accelerator_experiments:scientific_sequence': {
                'elasticsearch': 'long',
                'marshmallow': List(Integer())
            },
            'standard_status:original_presentation_date': {
                'elasticsearch': 'date',
                'marshmallow': DateString()
            },
            'standard_status:right_or_wrong': {
                'elasticsearch': 'boolean',
                'marshmallow': Bool()
            }
        }
    }

    return app_config
Esempio n. 24
0
def app_config(app_config):
    """Override conftest.py's app_config"""
    app_config["ILS_RECORDS_METADATA_NAMESPACES"] = {
        "document": {
            "accelerator_experiments": {
                "@context": "https://example.com/accelerator_experiments/terms"
            },
            "standard_status": {
                "@context": "https://example.com/standard_status/terms"
            },
        }
    }

    app_config["ILS_RECORDS_METADATA_EXTENSIONS"] = {
        "document": {
            "accelerator_experiments_accelerator": {
                "elasticsearch": "keyword",
                "marshmallow": SanitizedUnicode(required=True),
            },
            "accelerator_experiments_project": {
                "elasticsearch": "text",
                "marshmallow": SanitizedUnicode(),
            },
            "accelerator_experiments_number_in_sequence": {
                "elasticsearch": "long",
                "marshmallow": Integer(),
            },
            "accelerator_experiments_scientific_sequence": {
                "elasticsearch": "long",
                "marshmallow": List(Integer()),
            },
            "standard_status_original_presentation_date": {
                "elasticsearch": "date",
                "marshmallow": DateString(),
            },
            "standard_status_right_or_wrong": {
                "elasticsearch": "boolean",
                "marshmallow": Bool(),
            },
        }
    }

    return app_config
Esempio n. 25
0
class eBPF_Program_Catalog_Parameter_Schema(Schema):
    """eBPF program configuration."""

    id = Str(required=True, example='interface', description='Parameter id.')
    type = Str(required=True,
               description='Parameter type.',
               enum=PARAMETER_TYPES,
               example='integer',
               validate=validate.OneOf(PARAMETER_TYPES))
    list = Bool(
        default=False,
        example=True,
        description='Indicate if the parameter can have multiple values.')
    values = List_or_One(
        Str,
        example='yes',
        description='Possible values if the parameter type is choice.')
    description = Str(example='Network Interface to attach.',
                      description='Short description of the parameter.')
    example = Raw(example='eno0', description='Example of parameter value.')
def app_config(app_config):
    """Override conftest.py's app_config
    """
    # Added custom configuration
    app_config['RDM_RECORDS_METADATA_NAMESPACES'] = {
        'dwc': {
            '@context': 'https://example.com/dwc/terms'
        },
        'nubiomed': {
            '@context': 'https://example.com/nubiomed/terms'
        }
    }

    app_config['RDM_RECORDS_METADATA_EXTENSIONS'] = {
        'dwc:family': {
            'elasticsearch': 'keyword',
            'marshmallow': SanitizedUnicode(required=True)
        },
        'dwc:behavior': {
            'elasticsearch': 'text',
            'marshmallow': SanitizedUnicode()
        },
        'nubiomed:number_in_sequence': {
            'elasticsearch': 'long',
            'marshmallow': Integer()
        },
        'nubiomed:scientific_sequence': {
            'elasticsearch': 'long',
            'marshmallow': List(Integer())
        },
        'nubiomed:original_presentation_date': {
            'elasticsearch': 'date',
            'marshmallow': DateString()
        },
        'nubiomed:right_or_wrong': {
            'elasticsearch': 'boolean',
            'marshmallow': Bool()
        }
    }

    return app_config
Esempio n. 27
0
class ExtractROISchema(Schema):
    """This ROI format is the expected input of AllenSDK's extract_traces
    'rois' field
    """

    id = Int(required=True,
             description=("Unique ID of the ROI, get's overwritten writting "
                          "to LIMS"))
    x = Int(required=True,
            description="X location of top left corner of ROI in pixels")
    y = Int(required=True,
            description="Y location of top left corner of ROI in pixels")
    width = Int(required=True, description="Width of the ROI in pixels")
    height = Int(required=True, description="Height of the ROI in pixels")
    valid = Bool(required=True,
                 description=("Boolean indicating if the ROI is a valid "
                              "cell or not"))
    mask = List(List(Bool),
                required=True,
                description=("Bool nested list describing which pixels "
                             "in the ROI area are part of the cell"))
Esempio n. 28
0
class PackageLrnScheme(BaseModelScheme):
    package_lrn_uuid = Str(validate=[validate.Length(max=36)])
    package_name = Str(validate=[validate.Length(max=64)])
    cps = Int()
    type = Choice()
    lrn_port = Int()
    dip_count = Int()
    amount = Int()
    enabled = Bool()
    create_on = DateTime()
    licenses = Nested('LicenseLrnScheme', many=True)

    class Meta:
        model = model.PackageLrn
        fields = (
            'package_name',
            'cps',
            'type',
            'lrn_port',
            'dip_count',
            'amount',
            'enabled',
        )
Esempio n. 29
0
class Agent_Catalog_Parameter_Schema(Schema):
    """Agent parameter."""

    id = Str(required=True, example='log-period', description='Parameter id.')
    type = Str(required=True,
               enum=PARAMETER_TYPES,
               example=PARAMETER_TYPES[0],
               description='Parameter type.',
               validate=validate.OneOf(PARAMETER_TYPES))
    config = Nested(Agent_Catalog_Parameter_Config_Schema,
                    unknown='INCLUDE',
                    required=True,
                    description='Parameter configuration.')
    list = Bool(
        default=False,
        example=True,
        description='Indicate if the parameter can have multiple values.')
    values = List_or_One(
        Str,
        example='mysql',
        description='Possible values if the parameter type is choice.')
    description = Str(example='Enable the agent.',
                      description='Short description of the parameter.')
    example = Raw(example='10s', description='Example of parameter value.')
Esempio n. 30
0
def test_extensions():
    """Test metadata extensions schema."""
    ILS_RECORDS_METADATA_NAMESPACES = {
        "accelerator_experiments": {
            "@context": "https://example.com/accelerator_experiments/terms"
        },
        "standard_status": {
            "@context": "https://example.com/standard_status/terms"
        },
    }

    ILS_RECORDS_METADATA_EXTENSIONS = {
        "accelerator_experiments_accelerator": {
            "elasticsearch": "keyword",
            "marshmallow": SanitizedUnicode(required=True),
        },
        "accelerator_experiments_project": {
            "elasticsearch": "text",
            "marshmallow": SanitizedUnicode(),
        },
        "accelerator_experiments_number_in_sequence": {
            "elasticsearch": "long",
            "marshmallow": Integer(),
        },
        "accelerator_experiments_scientific_sequence": {
            "elasticsearch": "long",
            "marshmallow": List(Integer()),
        },
        "standard_status_original_presentation_date": {
            "elasticsearch": "date",
            "marshmallow": DateString(),
        },
        "standard_status_right_or_wrong": {
            "elasticsearch": "boolean",
            "marshmallow": Bool(),
        },
    }

    extensions = MetadataExtensions(
        ILS_RECORDS_METADATA_NAMESPACES, ILS_RECORDS_METADATA_EXTENSIONS
    )
    ExtensionsSchema = extensions.to_schema()

    # Minimal if not absent
    valid_minimal = {"accelerator_experiments_accelerator": "LHCb"}

    data = ExtensionsSchema().load(valid_minimal)

    assert data == valid_minimal

    # Full
    valid_full = {
        "accelerator_experiments_accelerator": "LHCb",
        "accelerator_experiments_project": "A project for experiment.",
        "accelerator_experiments_number_in_sequence": 3,
        "accelerator_experiments_scientific_sequence": [1, 1, 2, 3, 5, 8],
        "standard_status_original_presentation_date": "2019-02-14",
        "standard_status_right_or_wrong": True,
    }

    data = ExtensionsSchema().load(valid_full)

    assert data == valid_full

    # Invalid
    invalid_number_in_sequence = {
        "accelerator_experiments_accelerator": "LHCb",
        "accelerator_experiments_scientific_sequence": [1, "l", 2, 3, 5, 8],
    }
    with pytest.raises(ValidationError):
        data = ExtensionsSchema().load(invalid_number_in_sequence)