diff --git a/oarepo_communities/cf/workflows.py b/oarepo_communities/cf/workflows.py index 060229b..f7ab918 100644 --- a/oarepo_communities/cf/workflows.py +++ b/oarepo_communities/cf/workflows.py @@ -14,13 +14,13 @@ def __init__(self, **kwargs: Any) -> None: class WorkflowCF(KeywordCF): - def __init__(self, name: str, **kwargs) -> None: + def __init__(self, name: str, **kwargs: Any) -> None: super().__init__(name, field_cls=WorkflowSchemaField, **kwargs) # hack to get lazy choices serialized to JSON class LazyChoices(list): - def __init__(self, func): + def __init__(self, func: callable): self._func = func def __iter__(self): diff --git a/oarepo_communities/ext.py b/oarepo_communities/ext.py index 560eb84..5959233 100644 --- a/oarepo_communities/ext.py +++ b/oarepo_communities/ext.py @@ -16,7 +16,6 @@ #--- from flask import Flask from typing import Any -from invenio_records_resources.records import Record diff --git a/oarepo_communities/resolvers/communities.py b/oarepo_communities/resolvers/communities.py index a3e8268..32ffdae 100644 --- a/oarepo_communities/resolvers/communities.py +++ b/oarepo_communities/resolvers/communities.py @@ -40,11 +40,7 @@ def pick_resolved_fields(self, identity: Identity, resolved_dict: dict) -> dict: class CommunityRoleResolver(EntityResolver): - """Community entity resolver. - - The entity resolver enables Invenio-Requests to understand communities as - receiver and topic of a request. - """ + """Community role entity resolver.""" type_id = "community_role" """Type identifier for this resolver.""" diff --git a/oarepo_communities/resolvers/ui.py b/oarepo_communities/resolvers/ui.py index 0dcc427..df7ead8 100644 --- a/oarepo_communities/resolvers/ui.py +++ b/oarepo_communities/resolvers/ui.py @@ -18,6 +18,7 @@ class CommunityRoleUIResolver(OARepoUIResolver): + """UI resolver for community role entity references.""" def _get_community_label(self, record: dict, reference: dict[str, str]) -> str: if ( "metadata" not in record or "title" not in record["metadata"] diff --git a/oarepo_communities/resources/community_records/resource.py b/oarepo_communities/resources/community_records/resource.py index ad5c9eb..00387fc 100644 --- a/oarepo_communities/resources/community_records/resource.py +++ b/oarepo_communities/resources/community_records/resource.py @@ -10,7 +10,7 @@ class CommunityRecordsResource(RecordResource): - """RDM community's records resource.""" + """Communities-specific records resource.""" def create_url_rules(self) -> list[dict]: """Create the URL rules for the record resource.""" diff --git a/oarepo_communities/services/community_inclusion/service.py b/oarepo_communities/services/community_inclusion/service.py index 6f29478..ab44073 100644 --- a/oarepo_communities/services/community_inclusion/service.py +++ b/oarepo_communities/services/community_inclusion/service.py @@ -11,7 +11,7 @@ from oarepo_communities.errors import CommunityNotIncludedException #--- -from invenio_records_resources.records import Record +from invenio_drafts_resources.records import Record from invenio_records_resources.services.records.service import RecordService from invenio_records_resources.services.uow import UnitOfWork diff --git a/oarepo_communities/services/community_records/service.py b/oarepo_communities/services/community_records/service.py index 61fc671..1ca801c 100644 --- a/oarepo_communities/services/community_records/service.py +++ b/oarepo_communities/services/community_records/service.py @@ -26,7 +26,6 @@ #--- from typing import Any - from flask_principal import Identity from invenio_records_resources.services.base.links import LinksTemplate from invenio_records_resources.services.records.results import ( @@ -49,14 +48,6 @@ def community_record_schema(self) -> ServiceSchemaWrapper: """Returns the community schema instance.""" return ServiceSchemaWrapper(self, schema=self.config.community_record_schema) - """ - params: dict[str, Any] | None = None, - search_preference: Any | None = None, - expand: bool = False, - extra_filter: Query | None = None, - **kwargs: Any, - """ - def _search( self, identity: Identity, diff --git a/oarepo_communities/services/components/include.py b/oarepo_communities/services/components/include.py index f5e5f50..6333732 100644 --- a/oarepo_communities/services/components/include.py +++ b/oarepo_communities/services/components/include.py @@ -10,7 +10,7 @@ #--- from typing import Any from flask_principal import Identity -from invenio_records_resources.records import Record +from invenio_drafts_resources.records import Record class CommunityInclusionComponent(ServiceComponent): diff --git a/oarepo_communities/services/links.py b/oarepo_communities/services/links.py index 7cd61e6..c62b9e8 100644 --- a/oarepo_communities/services/links.py +++ b/oarepo_communities/services/links.py @@ -6,7 +6,7 @@ from uritemplate import URITemplate #--- -from invenio_records_resources.records import Record +from invenio_drafts_resources.records import Record class CommunitiesLinks(Link): @@ -20,7 +20,7 @@ def __init__( self._when_func = when self._vars_func = vars - def expand(self, obj: Record, context) -> dict: + def expand(self, obj: Record, context: dict) -> dict: """Expand the URI Template.""" ids = obj.parent.communities.ids links = {} diff --git a/oarepo_communities/services/permissions/generators.py b/oarepo_communities/services/permissions/generators.py index 62dceec..ed80281 100644 --- a/oarepo_communities/services/permissions/generators.py +++ b/oarepo_communities/services/permissions/generators.py @@ -21,7 +21,7 @@ #--- from typing import Any from flask_principal import Need -from invenio_drafts_resources.records import Record as RecordWithDraft #should probably replace with drafts record where parent is expected +from invenio_drafts_resources.records import Record from flask_principal import Identity def _user_in_community_need(user, community): @@ -59,7 +59,7 @@ def needs(self, **kwargs: Any) -> list[Need]: class CommunityWorkflowPermission(WorkflowPermission): - def _get_workflow_id(self, record: RecordWithDraft = None, **kwargs: Any) -> str: + def _get_workflow_id(self, record: Record = None, **kwargs: Any) -> str: # todo - check the record branch too? idk makes more sense to not use the default community's workflow, there is a deeper problem if there's no workflow on the record try: return super()._get_workflow_id(record=None, **kwargs) @@ -75,7 +75,7 @@ def _get_workflow_id(self, record: RecordWithDraft = None, **kwargs: Any) -> str raise MissingWorkflowError("Workflow not defined on record.") -def convert_community_ids_to_uuid(community_id: str) -> str: +def convert_community_ids_to_uuid(community_id: str) -> str | uuid.UUID: # if it already is a string representation of uuid, keep it as it is try: uuid.UUID(community_id, version=4) #? @@ -86,7 +86,7 @@ def convert_community_ids_to_uuid(community_id: str) -> str: class CommunityRoleMixin: - def _get_record_communities(self, record: RecordWithDraft = None, **kwargs: Any)->list[str]: + def _get_record_communities(self, record: Record = None, **kwargs: Any)->list[str]: try: return record.parent.communities.ids except AttributeError: @@ -100,7 +100,7 @@ def _get_data_communities(self, data: dict=None, **kwargs: Any)->list[str]: class DefaultCommunityRoleMixin: - def _get_record_communities(self, record: RecordWithDraft = None, **kwargs: Any)->list[str]: + def _get_record_communities(self, record: Record = None, **kwargs: Any)->list[str]: try: return [str(record.parent.communities.default.id)] except (AttributeError, TypeError) as e: @@ -134,7 +134,7 @@ def communities(self, identity: Identity)->list[str]: return list(community_ids) @abc.abstractmethod - def _get_record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> list[str]: + def _get_record_communities(self, record: Record=None, **kwargs: Any) -> list[str]: raise NotImplementedError() @abc.abstractmethod @@ -145,7 +145,7 @@ def _get_data_communities(self, data: dict = None, **kwargs: Any) -> list[str]: def roles(self, **kwargs: Any)->list[str]: raise NotImplementedError() - def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]: + def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]: """Set of Needs granting permission.""" if record: community_ids = self._get_record_communities(record) @@ -251,14 +251,14 @@ def query_filter_field(self)->str: class RecordOwnerInDefaultRecordCommunity(DefaultCommunityRoleMixin, Generator): default_or_ids = "default" - def _record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> set[str]: + def _record_communities(self, record: Record=None, **kwargs: Any) -> set[str]: return set(self._get_record_communities(record, **kwargs)) - def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]: + def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]: record_communities = set(self._get_record_communities(record, **kwargs)) return self._needs(record_communities, record=record) - def _needs(self, record_communities: set[str], record: RecordWithDraft = None) -> list[Need]: + def _needs(self, record_communities: set[str], record: Record = None) -> list[Need]: owners = getattr(record.parent, "owners", None) ret = [] for owner in owners: @@ -298,9 +298,9 @@ class RecordOwnerInRecordCommunity( default_or_ids = "ids" # trick to use CommunityRoleMixin instead of DefaultCommunityRoleMixin - def _record_communities(self, record: RecordWithDraft=None, **kwargs: Any) -> set[str]: + def _record_communities(self, record: Record=None, **kwargs: Any) -> set[str]: return set(self._get_record_communities(record, **kwargs)) - def needs(self, record: RecordWithDraft=None, data:dict=None, **kwargs:Any) -> list[Need]: + def needs(self, record: Record=None, data:dict=None, **kwargs:Any) -> list[Need]: record_communities = set(self._get_record_communities(record, **kwargs)) return self._needs(record_communities, record=record) diff --git a/tests/test_communities/conftest.py b/tests/test_communities/conftest.py index 12996fa..31ab09a 100644 --- a/tests/test_communities/conftest.py +++ b/tests/test_communities/conftest.py @@ -47,7 +47,6 @@ from oarepo_communities.services.permissions.policy import ( CommunityDefaultWorkflowPermissions, ) -from tests.test_communities.utils import link2testclient from deepmerge import always_merger pytest_plugins = [ @@ -59,6 +58,14 @@ "pytest_oarepo.users", ] +@pytest.fixture(autouse=True) +def init_cf(init_cf): + return init_cf + +@pytest.fixture(scope="module", autouse=True) +def location(location): + return location + @pytest.fixture() def urls(): return {"BASE_URL": "/thesis/", "BASE_URL_REQUESTS": "/requests/"} diff --git a/tests/test_communities/test_community_requests.py b/tests/test_communities/test_community_requests.py index 4373bbf..b4eb91b 100644 --- a/tests/test_communities/test_community_requests.py +++ b/tests/test_communities/test_community_requests.py @@ -1,4 +1,5 @@ import pytest +from pytest_oarepo.functions import link2testclient from oarepo_communities.errors import ( CommunityAlreadyIncludedException, @@ -6,8 +7,6 @@ PrimaryCommunityException, ) -from .utils import link2testclient - REPO_NAME = "thesis" diff --git a/tests/test_communities/test_permissions.py b/tests/test_communities/test_permissions.py index a1af5ec..193dbd6 100644 --- a/tests/test_communities/test_permissions.py +++ b/tests/test_communities/test_permissions.py @@ -5,7 +5,7 @@ from invenio_communities.communities.records.api import Community from invenio_communities.proxies import current_communities from invenio_users_resources.proxies import current_users_service -from tests.test_communities.utils import link2testclient +from pytest_oarepo.functions import link2testclient def test_disabled_endpoints( diff --git a/tests/test_communities/utils.py b/tests/test_communities/utils.py deleted file mode 100644 index 4b69022..0000000 --- a/tests/test_communities/utils.py +++ /dev/null @@ -1,5 +0,0 @@ - - -def link2testclient(link, ui=False): - base_string = "https://127.0.0.1:5000/api/" if not ui else "https://127.0.0.1:5000/" - return link[len(base_string) - 1 :]