Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global: upgrade for invenio os2 support #2797

Draft
wants to merge 6 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions cap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ def _(x):
APP_ALLOWED_HOSTS.append(host.strip())
else:
APP_ALLOWED_HOSTS.append(hosts)
# OAI-PMH
# =======
OAISERVER_ID_PREFIX = 'oai:analysispreservation.cern.ch:'

# Debug
# =====
Expand Down Expand Up @@ -465,6 +462,10 @@ def _(x):
RECORDS_REST_FACETS = {'deposits': CAP_FACETS, 'records': CAP_FACETS}

#: Records REST API endpoints.

# Mapping of values of the defined query arg to valid mimetypes for records/search serializers.
REST_MIMETYPE_QUERY_ARG_NAME = 'format'

RECORDS_REST_ENDPOINTS = copy.deepcopy(RECORDS_REST_ENDPOINTS)

RECORDS_REST_ENDPOINTS['recid'].update(
Expand All @@ -485,6 +486,12 @@ def _(x):
':record_form_json_v1_response'
),
},
'default_media_type': 'application/json',
'record_serializers_aliases': {
'get-json': 'application/json',
'get-basic': 'application/basic+json',
'get-form': 'application/form+json',
},
'search_serializers': {
'application/json': (
'cap.modules.records.serializers' ':record_json_v1_search'
Expand All @@ -493,6 +500,10 @@ def _(x):
'cap.modules.records.serializers' ':basic_json_v1_search'
),
},
'search_serializers_aliases': {
'list-json': 'application/json',
'list-basic': 'application/basic+json',
},
'read_permission_factory_imp': check_oauth2_scope(
lambda record: ReadRecordPermission(record).can(), write_scope.id
),
Expand Down Expand Up @@ -729,6 +740,14 @@ def _(x):
':repositories_json_v1_response'
),
},
'default_media_type': 'application/json',
'record_serializers_aliases': {
'get-json': 'application/json',
'get-basic': 'application/basic+json',
'get-permissions': 'application/permissions+json',
'get-form': 'application/form+json',
'get-repositories': 'application/repositories+json',
},
'search_serializers': {
'application/json': (
'cap.modules.deposit.serializers' ':deposit_json_v1_search'
Expand All @@ -737,6 +756,10 @@ def _(x):
'cap.modules.records.serializers' ':basic_json_v1_search'
),
},
'search_serializers_aliases': {
'list-json': 'application/json',
'list-basic': 'application/basic+json',
},
'files_serializers': {
'application/json': (
'cap.modules.deposit.serializers:files_response'
Expand Down
4 changes: 3 additions & 1 deletion cap/modules/deposit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,9 @@ def get_record(cls, id_, with_deleted=False):
deposit = super(CAPDeposit, cls).get_record(
id_=id_, with_deleted=with_deleted
)
deposit["_files"] = deposit.files.dumps()
deposit["_files"] = []
if deposit.files is not None:
deposit["_files"] = deposit.files.dumps()
return deposit

@classmethod
Expand Down
40 changes: 40 additions & 0 deletions cap/modules/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,46 @@ def RECORD_ACTION_NEEDS(id):
class CAPRecord(Record):
"""Record API class for CAP."""

@classmethod
def create_bucket(cls, data):
"""Create a bucket for this record.

Override this method to provide more advanced bucket creation
capabilities. This method may return a new or existing bucket, or may
return None, in case no bucket should be created.
"""
return None

@classmethod
def load_bucket(cls, record):
"""Load the bucket id from the record metadata.

Override this method to provide custom behavior for retrieving the
bucket id from the record metadata. By default the bucket id is
retrieved from the ``_bucket`` key. If you override this method, make
sure you also override :py:data:`Record.dump_bucket()`.

:param record: A record instance.
"""
return

@classmethod
def dump_bucket(cls, data, bucket):
"""Dump the bucket id into the record metadata.

Override this method to provide custom behavior for storing the bucket
id in the record metadata. By default the bucket id is stored in the
``_bucket`` key. If you override this method, make sure you also
override :py:data:`Record.load_bucket()`.

This method is called after the bucket is created, but before the
record is created in the database.

:param data: A dictionary of the record metadata.
:param bucket: The created bucket for the record.
"""
pass

def get_record_metadata(self):
"""Get Record Metadata instance for deposit."""
return RecordMetadata.query.filter_by(id=self.id).one_or_none()
Expand Down
21 changes: 10 additions & 11 deletions requirements-local-forks.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
-e git+https://github.com/cernanalysispreservation/invenio-celery.git@mock/v1.1.1#egg=invenio-celery
-e git+https://github.com/inveniosoftware/invenio-logging@94bc56117593eae62ba975d576e8c7b991311c0d#egg=invenio-logging[sentry,sentry-sdk]
-e git+https://github.com/cernanalysispreservation/[email protected]#egg=invenio-oauthclient
-e git+https://github.com/cernanalysispreservation/[email protected]#egg=invenio-userprofiles
-e git+https://github.com/cernanalysispreservation/invenio-indexer.git@os-2-new#egg=invenio-indexer
-e git+https://github.com/cernanalysispreservation/[email protected]#egg=invenio-jsonschemas
-e git+https://github.com/cernanalysispreservation/invenio-oaiserver.git@os-2-new#egg=invenio-oaiserver
-e git+https://github.com/parths007/invenio-records-rest.git@os-2-new#egg=invenio-records-rest
-e git+https://github.com/parths007/[email protected]#egg=invenio-search[opensearch2]
-e git+https://github.com/cernanalysispreservation/invenio-files-rest.git@mock/v1.0.5#egg=invenio-files-rest
-e git+https://github.com/cernanalysispreservation/invenio-records-files.git@new#egg=invenio-records-files
# -e git+https://github.com/cernanalysispreservation/invenio-celery.git@mock/v1.1.1#egg=invenio-celery
# -e git+https://github.com/inveniosoftware/invenio-logging@94bc56117593eae62ba975d576e8c7b991311c0d#egg=invenio-logging[sentry,sentry-sdk]
-e git+https://github.com/parths007/[email protected]#egg=invenio-oauthclient
-e git+https://github.com/parths007/[email protected]#egg=invenio-userprofiles
-e git+https://github.com/parths007/[email protected]#egg=invenio-indexer
-e git+https://github.com/parths007/[email protected]#egg=invenio-jsonschemas
#-e git+https://github.com/parths007/invenio-records-rest.git@os-2-new#egg=invenio-records-rest
#-e git+https://github.com/parths007/[email protected]#egg=invenio-search[opensearch2]
-e git+https://github.com/parths007/[email protected]#egg=invenio-files-rest
#-e git+https://github.com/cernanalysispreservation/invenio-records-files.git@new#egg=invenio-records-files
-e git+https://github.com/cernanalysispreservation/invenio-deposit.git@os-2#egg=invenio-deposit
-e git+https://github.com/cernanalysispreservation/invenio-query-parser.git@os#egg=invenio-query-parser
31 changes: 17 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

# CAP specific libraries
'jsonref>=1.0.0',
'dojson==1.4.0',
'jsonresolver>=0.3.2',
'PyGithub>=1.35',
'python-gitlab>=1.0.2',
Expand All @@ -76,28 +77,27 @@
'reana-client==0.8.1',
'reana-commons[yadage,snakemake]==0.8.4',

# Invenio Base Deps
# Invenio Base Deps
'invenio-base==1.2.5',
'invenio-admin==1.1.2',
'invenio-assets==1.1.3',
'invenio-assets==1.2.2',
'invenio-formatter==1.0.2',
'invenio-mail==1.0.2',
'invenio-rest==1.1.2',
'invenio-theme==1.1.4',
'invenio-celery@git+https://github.com/cernanalysispreservation/invenio-celery.git@mock/v1.1.1#egg=invenio-celery',
'invenio-logging[sentry,sentry-sdk] @ git+https://github.com/inveniosoftware/invenio-logging@94bc56117593eae62ba975d576e8c7b991311c0d',
'invenio-theme==1.3.4',
'invenio-celery==1.2.5',
'invenio-logging[sentry,sentry-sdk]==1.3.2',

# Invenio Auth Deps
'invenio-access==1.3.0',
'invenio-accounts==1.1.1',
'invenio-accounts==1.2.1',
'invenio-oauth2server==1.0.4',
'invenio-oauthclient @ git+https://github.com/cernanalysispreservation/invenio-oauthclient.git@v1.1.3',
'invenio-userprofiles @ git+https://github.com/cernanalysispreservation/invenio-userprofiles.git@v1.0.1',
'invenio-oauthclient @ git+https://github.com/parths007/invenio-oauthclient.git@v1.2.1',
'invenio-userprofiles @ git+https://github.com/parths007/invenio-userprofiles.git@v1.2.4',

# Invenio Metadata Deps
'invenio-indexer @ git+https://github.com/cernanalysispreservation/invenio-indexer.git@os-2-new',
'invenio-jsonschemas @ git+https://github.com/cernanalysispreservation/[email protected]',
'invenio-oaiserver @ git+https://github.com/cernanalysispreservation/invenio-oaiserver.git@os-2-new',
'invenio-indexer @ git+https://github.com/parths007/[email protected]',
'invenio-jsonschemas @ git+https://github.com/parths007/[email protected]',
'invenio-pidstore==1.1.0',
'invenio-records-rest @ git+https://github.com/parths007/invenio-records-rest.git@os-2-new',
'invenio-records-ui==1.0.1',
Expand All @@ -106,8 +106,8 @@
'invenio-search @ git+https://github.com/parths007/[email protected]#egg=invenio-search',

# Invenio Files deps
'invenio-files-rest @ git+https://github.com/cernanalysispreservation/invenio-files-rest.git@mock/v1.0.5',
'invenio-records-files @ git+https://github.com/cernanalysispreservation/invenio-records-files.git@new#egg=invenio-records-files',
'invenio-files-rest @ git+https://github.com/parths007/invenio-files-rest.git@v1.1.1',
'invenio-records-files>=1.2.1',

# Database deps
'invenio-db[postgresql,versioning]==1.0.13',
Expand All @@ -116,7 +116,10 @@
'invenio-deposit @ git+https://github.com/cernanalysispreservation/invenio-deposit.git@os-2',
'invenio-accounts-rest==1.0.0a4',
'invenio-query-parser @ git+https://github.com/cernanalysispreservation/invenio-query-parser.git@os',
'invenio[auth,base,metadata,postgresql]==3.2.0',
'invenio-app>=1.2.3,<1.3.0',
'invenio-cache>=1.0.0,<1.1.0',
'invenio-config>=1.0.2,<1.1.0',
'invenio-i18n==1.2.0',
]

packages = find_packages()
Expand Down
38 changes: 38 additions & 0 deletions tests/integration/deposits/test_get_deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,44 @@ def test_get_deposit_when_owner_returns_deposit(
assert resp.status_code == 200


def test_get_deposit_with_serializer_arg(
client, users, auth_headers_for_user, create_deposit
):
user = users['alice_user']
deposit = create_deposit(user, 'alice')

# test get-json: 'application/json'
resp_1 = client.get(
'/deposits/{}/?format=get-json'.format(deposit['_deposit']['id']),
headers=auth_headers_for_user(user),
)
assert resp_1.status_code == 200

# test get-basic: 'application/basic+json'
resp_2 = client.get(
'/deposits/{}/?format=get-basic'.format(deposit['_deposit']['id']),
headers=auth_headers_for_user(user),
)
assert resp_2.status_code == 200
assert list(resp_2.json.keys()) == ['created', 'metadata', 'pid', 'updated']

# test get-permissions: 'application/permissions+json'
resp_3 = client.get(
'/deposits/{}/?format=get-permissions'.format(deposit['_deposit']['id']),
headers=auth_headers_for_user(user),
)
assert resp_3.status_code == 200
assert list(resp_3.json.keys()) == ['permissions']

# test get-repositories: 'application/repositories+json'
resp_3 = client.get(
'/deposits/{}/?format=get-repositories'.format(deposit['_deposit']['id']),
headers=auth_headers_for_user(user),
)
assert resp_3.status_code == 200
assert list(resp_3.json.keys()) == ['webhooks']


def test_get_deposit_when_other_member_of_collaboration_returns_403(
client, users, auth_headers_for_user, create_deposit
):
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/test_get_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,42 @@ def test_get_record_when_owner_returns_record(
assert resp.status_code == 200


def test_get_record_with_serializer_arg(
client, db, users, auth_headers_for_user, create_deposit
):
owner = users['cms_user']
deposit = create_deposit(
owner,
'cms-analysis',
{
'$schema': 'https://analysispreservation.cern.ch/schemas/deposits/records/cms-analysis-v1.0.0.json',
'basic_info': {
'analysis_number': 'dream_team',
},
},
experiment='CMS',
files={'file_1.txt': BytesIO(b'Hello world!')},
publish=True,
)

recid = deposit['control_number']

# test get-json: 'application/json'
resp_1 = client.get(
'/records/{}/?format=get-json'.format(recid),
headers=[('Accept', 'application/json')] + auth_headers_for_user(owner),
)
assert resp_1.status_code == 200

# test get-basic: 'application/basic+json'
resp_2 = client.get(
'/records/{}/?format=get-basic'.format(recid),
headers=[('Accept', 'application/json')] + auth_headers_for_user(owner),
)
assert resp_2.status_code == 200
assert list(resp_2.json.keys()) == ['created', 'metadata', 'pid', 'recid','updated']


def test_get_record_when_superuser_returns_record(
client, db, users, auth_headers_for_user, auth_headers_for_superuser, create_deposit
):
Expand Down
Loading