Esempio n. 1
0
 def test_formatted_field_translates_to_array(self):
     field = fields.List(fields.String)
     res = swagger.field2property(field)
     assert res['type'] == 'array'
     assert res['items'] == swagger.field2property(fields.String())
Esempio n. 2
0
 class TestSchema(Schema):
     name = fields.List(fields.String(), required=True)
        cred_def.assign_thread_from(context.message)
        await responder.send_reply(cred_def)


CredDefGetList, CredDefGetListSchema = generate_model_schema(
    name='CredDefGetList',
    handler='acapy_plugin_toolbox.credential_definitions'
    '.CredDefGetListHandler',
    msg_type=CRED_DEF_GET_LIST,
    schema={})

CredDefList, CredDefListSchema = generate_model_schema(
    name='CredDefList',
    handler='acapy_plugin_toolbox.util.PassHandler',
    msg_type=CRED_DEF_LIST,
    schema={
        'results': fields.List(fields.Nested(CredDefRecordSchema),
                               required=True)
    })


class CredDefGetListHandler(BaseHandler):
    """Handler for get schema list request."""
    @admin_only
    async def handle(self, context: RequestContext, responder: BaseResponder):
        """Handle get schema list request."""
        records = await CredDefRecord.query(context, {})
        cred_def_list = CredDefList(results=records)
        cred_def_list.assign_thread_from(context.message)
        await responder.send_reply(cred_def_list)
Esempio n. 4
0
class SwitchListResponseSchema(Schema):
    count = fields.Integer()
    result = fields.List(fields.String)
Esempio n. 5
0
class DocumentSchemaV1(RecordMetadataSchemaJSONV1):
    """Document schema."""
    class Meta:
        """Meta attributes for the schema."""

        unknown = EXCLUDE

    abstract = fields.Str()
    alternative_abstracts = fields.List(fields.Str())
    alternative_identifiers = fields.List(fields.Nested(IdentifierSchema))
    alternative_titles = fields.List(fields.Nested(AlternativeTitleSchema))
    authors = fields.List(fields.Nested(AuthorSchema), required=True)
    conference_info = fields.Nested(ConferenceInfoSchema)
    copyrights = fields.List(fields.Nested(CopyrightsSchema))
    cover_metadata = fields.Dict()
    created_by = fields.Nested(ChangedBySchema)
    curated = fields.Bool()
    document_type = fields.Str(required=True,
                               validate=validate.OneOf(
                                   Document.DOCUMENT_TYPES))
    edition = fields.Str()
    extensions = fields.Method('dump_extensions', 'load_extensions')
    identifiers = fields.List(fields.Nested(IdentifierSchema))
    imprint = fields.Nested(ImprintSchema)
    internal_notes = fields.List(fields.Nested(InternalNoteSchema))
    keywords = fields.List(fields.Nested(KeywordSchema))
    languages = fields.List(fields.Str())
    licenses = fields.List(fields.Str())
    note = fields.Str()
    number_of_pages = fields.Str()
    other_authors = fields.Bool()
    publication_info = fields.List(fields.Nested(PublicationInfoSchema))
    publication_year = fields.Str(required=True)
    restricted = fields.Bool(missing=False)
    source = fields.Str()
    subjects = fields.List(fields.Nested(SubjectSchema))
    table_of_content = fields.List(fields.Str())
    tags = fields.List(fields.Str())
    title = fields.Str(required=True)
    updated_by = fields.Nested(ChangedBySchema)
    urls = fields.List(fields.Nested(UrlSchema))

    def dump_extensions(self, obj):
        """Dumps the extensions value.

        :params obj: content of the object's 'extensions' field
        """
        ExtensionSchema = current_app.extensions["invenio-app-ils"] \
                                     .document_metadata_extensions \
                                     .to_schema()
        return ExtensionSchema().dump(obj)

    def load_extensions(self, value):
        """Loads the 'extensions' field.

        :params value: content of the input's 'extensions' field
        """
        ExtensionSchema = current_app.extensions["invenio-app-ils"] \
                                     .document_metadata_extensions \
                                     .to_schema()
        return ExtensionSchema().load(value)

    @pre_load
    def preload_fields(self, data, **kwargs):
        """Automatically inject system fields."""
        record = self.context.get("record")
        data.update(set_changed_by(data, record))
        data.update(preserve_cover_metadata(data, record))
        return data
Esempio n. 6
0
class DatasetFilesListResponse(Schema):
    """Response schema for dataset files list view."""

    short_name = fields.String(required=True)
    files = fields.List(fields.Nested(DatasetFileDetails), required=True)
Esempio n. 7
0
class DatasetUnlinkResponse(Schema):
    """Dataset unlink files response."""

    unlinked = fields.List(fields.String())
class ApplicationSchema(Schema):
    applicationUuid = fields.UUID()
    unicastAddresses = fields.List(fields.Integer())
class ModelSchema(Schema):
    id = fields.Integer()
    configuration = fields.Dict()
    sensorDescriptors = fields.List(fields.Dict())
Esempio n. 10
0
class PaginationSchema(ma.Schema):
    class Meta:
        fields = ('items', 'has_prev', 'next_num', 'prev_num', 'page', 'pages',
                  'has_next', 'total')

    items = mafields.List(mafields.Nested(JobSchema))
Esempio n. 11
0
class LanguagesSchema(Schema):
    items = fields.List(fields.Nested(LanguageSchema()), data_key="languages")
    page = fields.Int()
    pages = fields.Int()
    total = fields.Int()
Esempio n. 12
0
class TableLogSchema(BaseSchema):
    table = fields.List(custom_fields.NativeOrPrettyDict())
    indices = fields.List(fields.Integer(), allow_none=True)
    display_index = fields.Boolean()
    columns = fields.List(fields.String(), allow_none=False)
class SchemaWithIntegerList(Schema):
    int_list = fields.List(fields.Integer())
Esempio n. 14
0
def test_swagger_tools_validate():
    spec = APISpec(
        title='Pets',
        version='0.1',
        plugins=['apispec.ext.marshmallow'],
    )

    spec.definition('Category', schema=CategorySchema)
    spec.definition('Pet',
                    schema=PetSchema,
                    extra_fields={'discriminator': 'name'})

    spec.add_path(
        view=None,
        path='/category/{category_id}',
        operations={
            'get': {
                'parameters': [
                    {
                        'name': 'q',
                        'in': 'query',
                        'type': 'string'
                    },
                    {
                        'name': 'category_id',
                        'in': 'path',
                        'required': True,
                        'type': 'string'
                    },
                    field2parameter(
                        field=fields.List(
                            fields.Str(),
                            validate=validate.OneOf(['freddie', 'roger']),
                            location='querystring',
                        ),
                        name='body',
                        use_refs=False,
                    ),
                ] + swagger.schema2parameters(PageSchema, default_in='query'),
                'responses': {
                    200: {
                        'schema': PetSchema,
                        'description': 'A pet',
                    },
                },
            },
            'post': {
                'parameters': ([{
                    'name': 'category_id',
                    'in': 'path',
                    'required': True,
                    'type': 'string'
                }] + swagger.schema2parameters(
                    CategorySchema, spec=spec, default_in='body')),
                'responses': {
                    201: {
                        'schema': PetSchema,
                        'description': 'A pet',
                    },
                },
            }
        },
    )
    try:
        utils.validate_swagger(spec)
    except exceptions.SwaggerError as error:
        pytest.fail(str(error))
class IATIQueryResponse(IATIQuery):
    timestamp = fields.String(required=True)
    # TODO: implement versioning feature
    # version = fields.String(required=True)
    processed_query = fields.String(required=False)
    results = fields.List(fields.Nested(IATIResult))
Esempio n. 16
0
class GetMultipleRecordsForOcaSchema(Schema):
    oca_schema_base_dris = fields.List(fields.Str(required=True))
Esempio n. 17
0
class DatasetListResponse(Schema):
    """Response schema for dataset list view."""

    datasets = fields.List(fields.Nested(DatasetDetails), required=True)
Esempio n. 18
0
class DocumentSchemaV1(RecordMetadataSchemaJSONV1):
    """Document schema."""
    class Meta:
        """Meta attributes for the schema."""

        unknown = EXCLUDE

    abstract = fields.Str()
    alternative_abstracts = fields.List(fields.Str())
    alternative_identifiers = fields.List(fields.Nested(IdentifierSchema))
    alternative_titles = fields.List(fields.Nested(AlternativeTitleSchema))
    authors = fields.List(fields.Nested(AuthorSchema), required=True)
    conference_info = fields.Nested(ConferenceInfoSchema)
    copyrights = fields.List(fields.Nested(CopyrightsSchema))
    created = fields.Nested(DocumentChangedBySchema)
    curated = fields.Bool()
    document_type = fields.Str()
    edition = fields.Str()
    identifiers = fields.List(fields.Nested(IdentifierSchema))
    imprints = fields.List(fields.Nested(ImprintSchema))
    internal_notes = fields.List(fields.Nested(InternalNoteSchema))
    keywords = fields.Nested(KeywordSchema)
    languages = fields.List(fields.Str())
    licenses = fields.List(fields.Nested(LicenseSchema))
    note = fields.Str()
    number_of_pages = fields.Str()
    other_authors = fields.Bool()
    publication_info = fields.List(fields.Nested(PublicationInfoSchema))
    source = fields.Str()
    subjects = fields.List(fields.Nested(SubjectSchema))
    table_of_content = fields.List(fields.Str())
    tag_pids = fields.List(fields.Str())
    title = fields.Str(required=True)
    updated = fields.Nested(DocumentChangedBySchema)
    urls = fields.List(fields.Nested(UrlSchema))
Esempio n. 19
0
class DatasetEditResponse(Schema):
    """Dataset edit metadata response."""

    edited = fields.Dict(required=True)
    warnings = fields.List(fields.String())
Esempio n. 20
0
 def test_bad_list_field(self):
     with pytest.raises(MarshallingError):
         fields.List("string")
     with pytest.raises(MarshallingError):
         fields.List(UserSerializer)
Esempio n. 21
0
class SwitchFullListResponseSchema(Schema):
    result = fields.List(fields.Nested(SwitchScheme))
Esempio n. 22
0
def test_required_list_field_failure():
    user_data = {"name": "Rosie"}
    field = fields.List(fields.String, required=True)
    with pytest.raises(MarshallingError) as excinfo:
        field.output('relatives', user_data)
    assert '{0!r} is a required field'.format('relatives') in str(excinfo)
Esempio n. 23
0
class ItemListSchema(Schema):
    updated_time = fields.DateTime()
    items = fields.List(fields.Str())
Esempio n. 24
0
class BlogSerializer(Serializer):
    title = fields.String()
    user = fields.Nested(UserSerializer)
    collaborators = fields.Nested(UserSerializer, many=True)
    categories = fields.List(fields.String)
    id = fields.String()
Esempio n. 25
0
 class QueryParamsSchema(Schema):
     query_param = fields.List(fields.String(), required=True)
Esempio n. 26
0
class SRUSchema(Marc21Schema):
    """SRU marshmallow schema."""

    identifiedBy = fields.List(fields.Dict())
    language = fields.List(fields.Dict())
    title = fields.List(fields.Dict())
    abstracts = fields.List(fields.Dict())
    contentNote = fields.List(fields.Str())
    contribution = fields.List(fields.Dict())
    extent = fields.Str()
    dissertation = fields.Dict()
    additionalMaterials = fields.Str()
    formats = fields.List(fields.Str())
    otherMaterialCharacteristics = fields.Str()
    editionStatement = fields.Dict()
    documentType = fields.Str()
    provisionActivity = fields.List(fields.Dict())
    notes = fields.List(fields.Str())
    series = fields.List(fields.Dict())
    partOf = fields.List(fields.Dict())

    @pre_dump
    def process(self, obj, **kwargs):
        """All the process is done by overdo."""
        return overdo.do(obj)
Esempio n. 27
0
def test_unpack_list():
    app = Flask(__name__)
    api = Api(app)
    result = unpack_list(ma.List(ma.Integer()), api=api)

    assert result
Esempio n. 28
0
class ProjectCreateSchema(ProjectSchema):

    id = fields.Int(allow_none=True)
    chroots = fields.List(fields.Str())
Esempio n. 29
0
 class SchemaWithList(m.Schema):
     items = f.List(f.Nested(MySchema))
Esempio n. 30
0
class CredentialDefinitionsCreatedResultsSchema(OpenAPISchema):
    """Results schema for cred-defs-created request."""

    credential_definition_ids = fields.List(
        fields.Str(description="Credential definition identifiers", **INDY_CRED_DEF_ID)
    )