Skip to content

Commit

Permalink
docs: add docstrings and correct styling
Browse files Browse the repository at this point in the history
  • Loading branch information
rekt-hard committed Mar 7, 2022
1 parent a34ab43 commit e9fa14b
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 65 deletions.
12 changes: 8 additions & 4 deletions invenio_rdm_records/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
from flask import flash, g, request, session
from flask_babelex import _
from flask_principal import identity_loaded
from invenio_rdm_records.oaiserver.resources.config import OAIPMHServerResourceConfig
from invenio_rdm_records.oaiserver.resources.resources import OAIPMHServerResource
from invenio_rdm_records.oaiserver.services.config import OAIPMHServerServiceConfig
from invenio_rdm_records.oaiserver.services.services import OAIPMHServerService
from invenio_records_resources.resources.files import FileResource
from invenio_records_resources.services import FileService
from invenio_vocabularies.contrib.affiliations import AffiliationsResource, \
Expand All @@ -28,6 +24,14 @@
SubjectsResourceConfig, SubjectsService, SubjectsServiceConfig
from itsdangerous import SignatureExpired

from invenio_rdm_records.oaiserver.resources.config import \
OAIPMHServerResourceConfig
from invenio_rdm_records.oaiserver.resources.resources import \
OAIPMHServerResource
from invenio_rdm_records.oaiserver.services.config import \
OAIPMHServerServiceConfig
from invenio_rdm_records.oaiserver.services.services import OAIPMHServerService

from . import config
from .resources import RDMDraftFilesResourceConfig, \
RDMParentRecordLinksResource, RDMParentRecordLinksResourceConfig, \
Expand Down
19 changes: 6 additions & 13 deletions invenio_rdm_records/oaiserver/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@

import marshmallow as ma
from flask_babelex import lazy_gettext as _
from flask_resources import (
HTTPJSONException,
ResourceConfig,
create_error_handler,
)
from flask_resources import HTTPJSONException, ResourceConfig, \
create_error_handler
from invenio_records_resources.resources.errors import ErrorHandlersMixin
from invenio_records_resources.resources.records.args import (
SearchRequestArgsSchema,
)
from invenio_records_resources.resources.records.args import \
SearchRequestArgsSchema

from ..services.errors import (
OAIPMHError,
OAIPMHSetDoesNotExistError,
OAIPMHSetIDDoesNotExistError,
)
from ..services.errors import OAIPMHError, OAIPMHSetDoesNotExistError, \
OAIPMHSetIDDoesNotExistError

oaipmh_error_handlers = {
**ErrorHandlersMixin.error_handlers,
Expand Down
18 changes: 5 additions & 13 deletions invenio_rdm_records/oaiserver/resources/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,24 @@

from flask import abort, g
from flask.globals import request
from flask_resources import (
Resource,
resource_requestctx,
response_handler,
route,
)
from flask_resources import Resource, resource_requestctx, response_handler, \
route
from invenio_records_resources.resources.errors import ErrorHandlersMixin
from invenio_records_resources.resources.records.resource import (
request_data,
request_headers,
request_search_args,
request_view_args,
)
from invenio_records_resources.resources.records.resource import \
request_data, request_headers, request_search_args, request_view_args
from invenio_records_resources.resources.records.utils import es_preference


class OAIPMHServerResource(ErrorHandlersMixin, Resource):
"""OAI-PMH server resource."""

def __init__(self, config, service):
"""Constructor."""
super().__init__(config)
self.service = service

def create_url_rules(self):
"""Create the URL rules for the OAI-PMH server resource."""

routes = self.config.routes
url_rules = [
route("GET", routes["set-prefix"] + routes["list"], self.search),
Expand Down
24 changes: 9 additions & 15 deletions invenio_rdm_records/oaiserver/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
from sqlalchemy import asc, desc

from ..services.links import OAIPMHSetLink
from ..services.permissions import (
OAIPMHServerPermissionPolicy,
)
from ..services.results import (
OAIMetadataFormatItem,
OAIMetadataFormatList,
OAISetItem,
OAISetList,
)
from ..services.permissions import OAIPMHServerPermissionPolicy
from ..services.results import OAIMetadataFormatItem, OAIMetadataFormatList, \
OAISetItem, OAISetList


class SearchOptions:
Expand Down Expand Up @@ -71,9 +65,9 @@ class SearchOptions:
class OAIPMHMetadataFormat(Schema):
"""Marshmallow schema for OAI-PMH metadata format."""

id = fields.Str(metadata={'read_only':True} )
schema = fields.URL(metadata={'read_only':True})
namespace = fields.URL(metadata={'read_only':True})
id = fields.Str(metadata={'read_only': True})
schema = fields.URL(metadata={'read_only': True})
namespace = fields.URL(metadata={'read_only': True})


class OAIPMHSetSchema(Schema):
Expand All @@ -83,9 +77,9 @@ class OAIPMHSetSchema(Schema):
name = SanitizedUnicode(required=True, validate=validate.Length(min=1))
search_pattern = SanitizedUnicode(required=True)
spec = SanitizedUnicode(required=True, validate=validate.Length(min=1))
created = fields.DateTime(metadata={'read_only':True})
updated = fields.DateTime(metadata={'read_only':True})
id = fields.Int(metadata={'read_only':True})
created = fields.DateTime(metadata={'read_only': True})
updated = fields.DateTime(metadata={'read_only': True})
id = fields.Int(metadata={'read_only': True})


class OAIPMHSetUpdateSchema(Schema):
Expand Down
1 change: 1 addition & 0 deletions invenio_rdm_records/oaiserver/services/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class OAIPMHError(Exception):
"""Base class for OAI-PMH errors."""

def __init__(self, description, *args: object):
"""Constructor."""
self.description = description
super().__init__(*args)

Expand Down
7 changes: 2 additions & 5 deletions invenio_rdm_records/oaiserver/services/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
"""Permissions for OAI-PMH service."""

from invenio_records_permissions import BasePermissionPolicy
from invenio_records_permissions.generators import (
Admin,
AnyUser,
SystemProcess,
)
from invenio_records_permissions.generators import Admin, AnyUser, \
SystemProcess


class OAIPMHServerPermissionPolicy(BasePermissionPolicy):
Expand Down
Empty file.
7 changes: 3 additions & 4 deletions invenio_rdm_records/oaiserver/services/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
"""Result items for OAI-PMH services."""

from invenio_records_resources.pagination import Pagination
from invenio_records_resources.services.base.results import (
ServiceItemResult,
ServiceListResult,
)
from invenio_records_resources.services.base.results import \
ServiceItemResult, ServiceListResult


class BaseServiceItemResult(ServiceItemResult):
"""Single result item."""

def __init__(self, service, identity, item, links_tpl, schema=None):
"""Constructor."""
self._identity = identity
self._item = item
self._schema = schema or service.schema
Expand Down
20 changes: 10 additions & 10 deletions invenio_rdm_records/oaiserver/services/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
from invenio_oaiserver.models import OAISet
from invenio_records_resources.services import Service
from invenio_records_resources.services.base import LinksTemplate
from invenio_records_resources.services.records.schema import (
ServiceSchemaWrapper,
)
from invenio_records_resources.services.records.schema import \
ServiceSchemaWrapper
from invenio_records_resources.services.uow import unit_of_work
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import text

from invenio_rdm_records.oaiserver.services.errors import (
OAIPMHSetDoesNotExistError,
OAIPMHSetIDDoesNotExistError,
OAIPMHSetSpecAlreadyExistsError,
)

from invenio_rdm_records.oaiserver.services.uow import OAISetCommitOp, OAISetDeleteOp
from invenio_rdm_records.oaiserver.services.errors import \
OAIPMHSetDoesNotExistError, OAIPMHSetIDDoesNotExistError, \
OAIPMHSetSpecAlreadyExistsError
from invenio_rdm_records.oaiserver.services.uow import OAISetCommitOp, \
OAISetDeleteOp


class OAIPMHServerService(Service):
"""OAI-PMH service."""

def __init__(self, config):
"""Init service with config."""
super().__init__(config)

@property
Expand All @@ -53,6 +51,7 @@ def links_item_tpl(self):
)

def _get_one(self, raise_error=True, **kwargs):
"""Retrieve set based on provided arguments."""
set = None
errors = []
try:
Expand Down Expand Up @@ -102,6 +101,7 @@ def read(self, identity, id_):
)

def search(self, identity, params):
"""Perform search over OAI sets."""
self.require_permission(identity, 'read')

search_params = self._get_search_params(params)
Expand Down
4 changes: 4 additions & 0 deletions invenio_rdm_records/oaiserver/services/uow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ class OAISetCommitOp(Operation):
"""OAI-PMH set add/update operation."""

def __init__(self, oai_set):
"""Initialize the set commit operation."""
super().__init__()
self._oai_set = oai_set

def on_register(self, uow):
"""Add set to db session."""
db.session.add(self._oai_set)


class OAISetDeleteOp(Operation):
"""OAI-PMH set delete operation."""

def __init__(self, oai_set):
"""Initialize the set delete operation."""
super().__init__()
self._oai_set = oai_set

def on_register(self, uow):
"""Hard delete set."""
db.session.delete(self._oai_set)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def minimal_community():

@pytest.fixture()
def minimal_oai_set():
"""Data for a minimal OAI-PMH set"""
"""Data for a minimal OAI-PMH set."""
return {
"name": "name",
"spec": "spec",
Expand Down

0 comments on commit e9fa14b

Please sign in to comment.