コード例 #1
0
def test_lazy_strings_are_serialized():
    serializer = JSONSerializer()
    lazy = {"key": _("Lazy")}
    list_lazy = [{"key": _("Lazy1")}, {"key": _("Lazy2")}]

    assert '{"key": "Lazy"}' == serializer.serialize_object(lazy)
    assert '[{"key": "Lazy1"}, {"key": "Lazy2"}]' == serializer.serialize_object_list(
        list_lazy)
コード例 #2
0
class FileActionResourceConfig(RecordResourceConfig, ActionResourceConfig):
    """Record resource config."""

    request_loaders = {
        "application/json": RequestLoader(deserializer=JSONDeserializer()),
        "application/octet-stream": RequestStreamLoader(),
    }

    response_handlers = {
        "application/json": RecordFileResponse(JSONSerializer()),
    }

    list_route = "/records/<pid_value>/files/<key>/<action>"
    action_commands = {
        'create': {
            'commit': 'commit_file'
        },
        'read': {
            'content': 'get_file_content'
        },
        'update': {
            'content': 'set_file_content'
        },
        'delete': {}
    }
コード例 #3
0
ファイル: app.py プロジェクト: lnielsen/sprint-training
class MyResourceConfig(ResourceConfig):
    item_route = "/records/<id>"
    list_route = "/records/"

    response_handlers = {
        "application/json": Response(JSONSerializer()),
        "text/plain": Response(PlainTextSerializer())
    }
コード例 #4
0
class CustomRecordResourceConfig(RecordResourceConfig):
    """Custom record resource config."""

    item_route = "/serialization_test/records/<pid_value>"
    list_route = "/serialization_test/records"
    response_handlers = {
        "application/json": Response(JSONSerializer()),
        "application/xml": Response(XMLSerializer())
    }
コード例 #5
0
class RecordResourceConfig(ResourceConfig):
    """Record resource config."""

    list_route = "/records"
    item_route = f"{list_route}/<pid_value>"

    links_config = {"record": RecordLinksSchema, "search": SearchLinksSchema}

    request_url_args_parser = {"search": URLArgsParser(SearchURLArgsSchema)}

    request_headers_parser = {
        "update": HeadersParser(RequestHeadersSchema, allow_unknown=False),
        "delete": HeadersParser(RequestHeadersSchema, allow_unknown=False)
    }

    response_handlers = {"application/json": RecordResponse(JSONSerializer())}

    error_map = {
        RevisionIdMismatchError:
        create_errormap_handler(lambda e: HTTPJSONException(
            code=412,
            description=e.description,
        )),
        QuerystringValidationError:
        create_errormap_handler(
            HTTPJSONException(
                code=400,
                description="Invalid querystring parameters.",
            )),
        PermissionDeniedError:
        create_errormap_handler(
            HTTPJSONException(
                code=403,
                description="Permission denied.",
            )),
        PIDDeletedError:
        create_errormap_handler(
            HTTPJSONException(
                code=410,
                description="The record has been deleted.",
            )),
        PIDDoesNotExistError:
        create_errormap_handler(
            HTTPJSONException(
                code=404,
                description="The pid does not exist.",
            )),
        PIDUnregistered:
        create_errormap_handler(
            HTTPJSONException(
                code=404,
                description="The pid is not registered.",
            )),
        PIDRedirectedError:
        create_pid_redirected_error_handler(),
    }
コード例 #6
0
class RecordResourceConfig(BaseRecordResourceConfig):
    """Projects resource configuration."""

    resource_name = 'projects'
    list_route = '/projects/'
    item_route = f'{list_route}/<pid_value>'

    response_handlers = {
        'application/json':
        RecordResponse(JSONSerializer()),
        'text/csv':
        StreamResponse(CSVSerializer(csv_included_fields=[
            'pid', 'name', 'description', 'startDate', 'endDate'
        ]),
                       filename='projects.csv')
    }
コード例 #7
0
class RecordResourceConfig(BaseRecordResourceConfig):
    """HEP Valais Projects resource configuration."""

    response_handlers = {
        'application/json':
        RecordResponse(JSONSerializer()),
        'text/csv':
        StreamResponse(CSVSerializer(csv_included_fields=[
            'pid', 'name', 'approvalDate', 'projectSponsor', 'statusHep',
            'mainTeam', 'innerSearcher', 'secondaryTeam', 'externalPartners',
            'status', 'startDate', 'endDate', 'description', 'keywords',
            'realizationFramework', 'funding_funder_type',
            'funding_funder_name', 'funding_funder_number',
            'funding_fundingReceived', 'actorsInvolved', 'benefits',
            'impactOnFormation', 'impactOnProfessionalEnvironment',
            'impactOnPublicAction', 'promoteInnovation',
            'relatedToMandate_mandate', 'relatedToMandate_name',
            'relatedToMandate_briefDescription', 'educationalDocument',
            'searchResultsValorised'
        ]),
                       filename='projects.csv')
    }
コード例 #8
0
class RecordResourceConfig(ResourceConfig):
    """Record resource config."""

    list_route = "/records"
    item_route = f"{list_route}/<pid_value>"

    links_config = {
        "record": ItemLinksSchema.create(template='/api/records/{pid_value}'),
        "search": SearchLinksSchema.create(template='/api/records{?params*}'),
    }

    request_url_args_parser = {
        "search": URLArgsParser(SearchURLArgsSchema)
    }

    request_headers_parser = {
        "search": HeadersParser(None),
        "update": HeadersParser(RequestHeadersSchema),
        "delete": HeadersParser(RequestHeadersSchema),
    }

    response_handlers = {
        "application/json": RecordResponse(JSONSerializer())
    }

    error_map = {
        ValidationError: create_errormap_handler(
            lambda e: HTTPJSONValidationException(e)
        ),
        RevisionIdMismatchError: create_errormap_handler(
            lambda e: HTTPJSONException(
                code=412,
                description=e.description,
            )
        ),
        QuerystringValidationError: create_errormap_handler(
            HTTPJSONException(
                code=400,
                description="Invalid querystring parameters.",
            )
        ),
        PermissionDeniedError: create_errormap_handler(
            HTTPJSONException(
                code=403,
                description="Permission denied.",
            )
        ),
        PIDDeletedError: create_errormap_handler(
            HTTPJSONException(
                code=410,
                description="The record has been deleted.",
            )
        ),
        PIDAlreadyExists: create_errormap_handler(
            HTTPJSONException(
                code=400,
                description="The persistent identifier is already registered.",
            )
        ),
        PIDDoesNotExistError: create_errormap_handler(
            HTTPJSONException(
                code=404,
                description="The persistent identifier does not exist.",
            )
        ),
        PIDUnregistered: create_errormap_handler(
            HTTPJSONException(
                code=404,
                description="The persistent identifier is not registered.",
            )
        ),
        PIDRedirectedError: create_pid_redirected_error_handler(),
        NoResultFound: create_errormap_handler(
            HTTPJSONException(
                code=404,
                description="Not found.",
            )
        ),
    }
コード例 #9
0
def test_prettyprint():
    app = Flask("test")
    with app.test_request_context("/?prettyprint=1"):
        serializer = JSONSerializer()
        assert '{\n  "key": "1"\n}' == serializer.serialize_object(
            {"key": "1"})
コード例 #10
0
ファイル: config.py プロジェクト: astrowq/invenio-rdm-records
        "commit":
        FileItemLink(
            template="/api/records/{pid_value}/draft/files/{key}/commit"),
    })

RecordListFilesLinks = LinksSchema.create(
    links={"self": ItemLink(template="/api/records/{pid_value}/files")})

DraftListFilesLinks = LinksSchema.create(
    links={"self": ItemLink(template="/api/records/{pid_value}/draft/files")})

#
# Response handlers
#
record_serializers = {
    "application/json": RecordResponse(JSONSerializer()),
    "application/vnd.inveniordm.v1+json": RecordResponse(UIJSONSerializer())
}


#
# Records and record versions
#
class RDMRecordResourceConfig(RecordResourceConfig):
    """Record resource configuration."""

    list_route = "/records"

    item_route = "/records/<pid_value>"

    links_config = {