Beispiel #1
0
def test_wrap_schema_class_with_metadata():
    class TestSchema(RecordBaseSchema):
        pass

    data = {
        "metadata": {
            "heroes": [{
                "name": "Jessica Jones"
            }, {
                "name": "Frank Castle"
            }],
            "description": "A list of heroes",
        }
    }
    schema = wrap_schema_class_with_metadata(TestSchema)

    result = schema().dump(data).data

    assert data == result
Beispiel #2
0
def test_wrap_schema_class_with_metadata_with_extra_fields_and_exclude():
    class TestSchema(RecordBaseSchema):
        class Meta:
            exclude = ["ignore_field"]

    created_date_time = datetime.strptime("2019-01-01", "%Y-%m-%d")
    updated_date_time = datetime.strptime("2019-01-02", "%Y-%m-%d")

    data = {
        "pid": Mock(object_uuid="0000-0000-0000-0000", pid_value="666"),
        "created": created_date_time,
        "updated": updated_date_time,
        "metadata": {
            "heroes": [{
                "name": "Jessica Jones"
            }, {
                "name": "Frank Castle"
            }],
            "description": "A list of heroes",
            "ignore_field": "I am a useless field.",
        },
    }

    expected_data = {
        "metadata": {
            "heroes": [{
                "name": "Jessica Jones"
            }, {
                "name": "Frank Castle"
            }],
            "description": "A list of heroes",
        },
        "created": "2019-01-01 00:00:00",
        "updated": "2019-01-02 00:00:00",
        "id": "666",
        "uuid": "0000-0000-0000-0000",
    }

    schema = wrap_schema_class_with_metadata(TestSchema)

    result = schema().dump(data).data

    assert expected_data == result
Beispiel #3
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import search_responsify

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.experiments import ExperimentsPublicSchema
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import JSONSerializer

experiments_json = JSONSerializer(
    wrap_schema_class_with_metadata(ExperimentsPublicSchema),
    index_name="records-experiments",
)

experiments_json_response = record_responsify(experiments_json,
                                              "application/json")

experiments_json_response_search = search_responsify(experiments_json,
                                                     "application/json")
Beispiel #4
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import search_responsify

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.jobs import JobsPublicSchema
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import JSONSerializer

jobs_json = JSONSerializer(wrap_schema_class_with_metadata(JobsPublicSchema),
                           index_name="records-jobs")

jobs_json_response = record_responsify(jobs_json, "application/json")

jobs_json_response_search = search_responsify(jobs_json, "application/json")
Beispiel #5
0
from inspirehep.accounts.api import is_superuser_or_cataloger_logged_in
from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.institutions import InstitutionsPublicSchema
from inspirehep.records.marshmallow.institutions.base import InstitutionsAdminSchema
from inspirehep.records.marshmallow.institutions.ui import (
    InstitutionsDetailSchema,
    InstitutionsListSchema,
)
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

institutions_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(InstitutionsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(InstitutionsPublicSchema)),
])

institutions_json_response = record_responsify(institutions_json,
                                               "application/json")

institutions_json_response_search = search_responsify(institutions_json,
                                                      "application/json")

institutions_json_detail = JSONSerializer(
    wrap_schema_class_with_metadata(InstitutionsDetailSchema))
institutions_json_detail_response = record_responsify(
    institutions_json_detail, "application/vnd+inspire.record.ui+json")
Beispiel #6
0
    ConditionalMultiSchemaJSONSerializer,
    JSONSerializer,
    JSONSerializerFacets,
    JSONSerializerLiteratureSearch,
)

# Facets
facets_json = JSONSerializerFacets(Schema)
facets_json_response_search = search_responsify(facets_json, "application/json")

# Literature
literature_json_search = ConditionalMultiSchemaJSONSerializer(
    [
        (
            lambda _: is_superuser_or_cataloger_logged_in(),
            wrap_schema_class_with_metadata(LiteratureAdminSchema),
        ),
        (None, wrap_schema_class_with_metadata(LiteraturePublicListSchema)),
    ]
)

literature_json = ConditionalMultiSchemaJSONSerializer(
    [
        (
            lambda _: is_superuser_or_cataloger_logged_in(),
            wrap_schema_class_with_metadata(LiteratureAdminSchema),
        ),
        (None, wrap_schema_class_with_metadata(LiteraturePublicSchema)),
    ]
)
from inspirehep.accounts.api import is_superuser_or_cataloger_logged_in
from inspirehep.records.marshmallow.authors import (
    AuthorsAdminSchema,
    AuthorsDetailSchema,
    AuthorsListSchema,
    AuthorsOnlyControlNumberSchema,
    AuthorsPublicSchema,
)
from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

authors_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(AuthorsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(AuthorsPublicSchema)),
])
authors_json_response = record_responsify(authors_json, "application/json")
authors_json_response_search = search_responsify(authors_json,
                                                 "application/json")

authors_json_detail = JSONSerializer(
    wrap_schema_class_with_metadata(AuthorsDetailSchema))
authors_json_detail_response = record_responsify(
    authors_json_detail, "application/vnd+inspire.record.ui+json")

authors_json_list = JSONSerializer(
    wrap_schema_class_with_metadata(AuthorsListSchema))
authors_json_list_response = search_responsify(
Beispiel #8
0
from inspirehep.accounts.api import is_superuser_or_cataloger_logged_in
from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.experiments.base import (
    ExperimentsAdminSchema,
    ExperimentsPublicSchema,
)
from inspirehep.records.marshmallow.experiments.ui import (
    ExperimentsDetailSchema,
    ExperimentsListSchema,
)
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

experiments_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(ExperimentsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(ExperimentsPublicSchema)),
])

experiments_json_response = record_responsify(experiments_json,
                                              "application/json")

experiments_json_response_search = search_responsify(experiments_json,
                                                     "application/json")

experiments_json_detail = JSONSerializer(
    wrap_schema_class_with_metadata(ExperimentsDetailSchema))
experiments_json_detail_response = record_responsify(
    experiments_json_detail, "application/vnd+inspire.record.ui+json")
Beispiel #9
0
from inspirehep.records.marshmallow.seminars.base import (
    SeminarsAdminSchema,
    SeminarsPublicSchema,
)
from inspirehep.records.marshmallow.seminars.ui import (
    SeminarsDetailSchema,
    SeminarsListSchema,
)
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

seminars_json = ConditionalMultiSchemaJSONSerializer(
    [
        (
            lambda _: is_superuser_or_cataloger_logged_in(),
            wrap_schema_class_with_metadata(SeminarsAdminSchema),
        ),
        (None, wrap_schema_class_with_metadata(SeminarsPublicSchema)),
    ]
)
seminars_json_response = record_responsify(seminars_json, "application/json")
seminars_json_response_search = search_responsify(seminars_json, "application/json")

seminars_json_detail = JSONSerializer(
    wrap_schema_class_with_metadata(SeminarsDetailSchema)
)
seminars_json_detail_response = record_responsify(
    seminars_json_detail, "application/vnd+inspire.record.ui+json"
)

seminars_json_list = JSONSerializer(
Beispiel #10
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import search_responsify

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.journals import JournalsPublicSchema
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import JSONSerializer

journals_json = JSONSerializer(
    wrap_schema_class_with_metadata(JournalsPublicSchema),
    index_name="records-journals")

journals_json_response = record_responsify(journals_json, "application/json")

journals_json_response_search = search_responsify(journals_json,
                                                  "application/json")
Beispiel #11
0
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import search_responsify

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.jobs import JobsPublicSchema
from inspirehep.records.marshmallow.jobs.ui import JobsDetailSchema, JobsListSchema
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import JSONSerializer

jobs_json = JSONSerializer(
    wrap_schema_class_with_metadata(JobsPublicSchema), index_name="records-jobs"
)

jobs_json_response = record_responsify(jobs_json, "application/json")

jobs_json_response_search = search_responsify(jobs_json, "application/json")

jobs_json_detail = JSONSerializer(wrap_schema_class_with_metadata(JobsDetailSchema))
jobs_json_detail_response = record_responsify(
    jobs_json_detail, "application/vnd+inspire.record.ui+json"
)
jobs_json_list = JSONSerializer(
    wrap_schema_class_with_metadata(JobsListSchema), index_name="records-jobs"
)
jobs_json_list_response = search_responsify(
    jobs_json_list, "application/vnd+inspire.record.ui+json"
Beispiel #12
0
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

from invenio_records_rest.serializers.response import search_responsify

from inspirehep.records.marshmallow.base import wrap_schema_class_with_metadata
from inspirehep.records.marshmallow.institutions import InstitutionsPublicSchema
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import JSONSerializer

institutions_json = JSONSerializer(
    wrap_schema_class_with_metadata(InstitutionsPublicSchema),
    index_name="records-institutions",
)

institutions_json_response = record_responsify(institutions_json,
                                               "application/json")

institutions_json_response_search = search_responsify(institutions_json,
                                                      "application/json")
Beispiel #13
0
from inspirehep.records.marshmallow.seminars.base import (
    SeminarsAdminSchema,
    SeminarsPublicListSchema,
    SeminarsPublicSchema,
)
from inspirehep.records.marshmallow.seminars.ui import (
    SeminarsDetailSchema,
    SeminarsListSchema,
)
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

seminars_json_search = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(SeminarsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(SeminarsPublicListSchema)),
])

seminars_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(SeminarsAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(SeminarsPublicSchema)),
])

seminars_json_response = record_responsify(seminars_json, "application/json")
seminars_json_response_search = search_responsify(seminars_json_search,
                                                  "application/json")
Beispiel #14
0
from inspirehep.records.marshmallow.conferences.base import (
    ConferencesAdminSchema,
    ConferencesPublicListSchema,
    ConferencesPublicSchema,
)
from inspirehep.records.marshmallow.conferences.ui import (
    ConferencesDetailSchema,
    ConferencesListSchema,
)
from inspirehep.records.serializers.response import record_responsify
from inspirehep.serializers import ConditionalMultiSchemaJSONSerializer, JSONSerializer

conferences_json = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(ConferencesAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(ConferencesPublicSchema)),
])
conferences_json_search = ConditionalMultiSchemaJSONSerializer([
    (
        lambda _: is_superuser_or_cataloger_logged_in(),
        wrap_schema_class_with_metadata(ConferencesAdminSchema),
    ),
    (None, wrap_schema_class_with_metadata(ConferencesPublicListSchema)),
])
conferences_json_response = record_responsify(conferences_json,
                                              "application/json")
conferences_json_response_search = search_responsify(conferences_json_search,
                                                     "application/json")