diff --git a/oarepo_requests/actions/generic.py b/oarepo_requests/actions/generic.py index 30645b1..24f7ea7 100644 --- a/oarepo_requests/actions/generic.py +++ b/oarepo_requests/actions/generic.py @@ -12,11 +12,12 @@ from functools import cached_property from typing import TYPE_CHECKING, Any +from invenio_pidstore.errors import PersistentIdentifierError from invenio_requests.customizations import actions from oarepo_runtime.i18n import lazy_gettext as _ from oarepo_requests.proxies import current_oarepo_requests -from invenio_pidstore.errors import PersistentIdentifierError + if TYPE_CHECKING: from flask_babel.speaklater import LazyString from flask_principal import Identity diff --git a/oarepo_requests/resolvers/interface.py b/oarepo_requests/resolvers/interface.py index 980f302..ef66298 100644 --- a/oarepo_requests/resolvers/interface.py +++ b/oarepo_requests/resolvers/interface.py @@ -1,15 +1,17 @@ from __future__ import annotations -from typing import Any, TYPE_CHECKING +import logging +from typing import TYPE_CHECKING, Any from invenio_pidstore.errors import PersistentIdentifierError from oarepo_requests.resolvers.ui import resolve -import logging + if TYPE_CHECKING: from invenio_requests.records import Request log = logging.getLogger(__name__) + # todo consider - we are not using this strictly in the ui context - so how should we separate these things in the future def resolve_entity(entity: str, obj: Request, ctx: dict[str, Any]) -> dict: """Resolve the entity and put it into the context cache. diff --git a/oarepo_requests/resources/events/config.py b/oarepo_requests/resources/events/config.py index 076c34e..9eacc5f 100644 --- a/oarepo_requests/resources/events/config.py +++ b/oarepo_requests/resources/events/config.py @@ -9,12 +9,12 @@ from __future__ import annotations +import marshmallow as ma from flask_resources import ResponseHandler from invenio_records_resources.services.base.config import ConfiguratorMixin from invenio_requests.resources.events.config import RequestCommentsResourceConfig from oarepo_requests.resources.ui import OARepoRequestEventsUIJSONSerializer -import marshmallow as ma class OARepoRequestsCommentsResourceConfig( @@ -36,9 +36,9 @@ class OARepoRequestsCommentsResourceConfig( @property def request_item_view_args(self): return { - **super().request_item_view_args, - "event_type": ma.fields.Str(), - } + **super().request_item_view_args, + "event_type": ma.fields.Str(), + } @property def response_handlers(self) -> dict[str, ResponseHandler]: diff --git a/oarepo_requests/resources/events/resource.py b/oarepo_requests/resources/events/resource.py index f2bc08e..87421e6 100644 --- a/oarepo_requests/resources/events/resource.py +++ b/oarepo_requests/resources/events/resource.py @@ -9,9 +9,6 @@ from __future__ import annotations -from flask_resources import route -from copy import deepcopy - from flask import g from flask_resources import ( from_conf, @@ -81,7 +78,6 @@ def search_extended(self) -> tuple[dict, int]: """Search for comments.""" return super().search() - # list args parser in invenio parses request_id input through UUID instead of Str; does this have any relevance for us? @item_view_args_parser @request_extra_args @@ -89,7 +85,9 @@ def search_extended(self) -> tuple[dict, int]: @response_handler() def create_event(self): """Create a comment.""" - type_ = current_event_type_registry.lookup(resource_requestctx.view_args["event_type"], quiet=True) + type_ = current_event_type_registry.lookup( + resource_requestctx.view_args["event_type"], quiet=True + ) item = self.service.create( identity=g.identity, request_id=resource_requestctx.view_args["request_id"], diff --git a/oarepo_requests/services/permissions/generators/conditional.py b/oarepo_requests/services/permissions/generators/conditional.py index 999f0ca..c0a0d55 100644 --- a/oarepo_requests/services/permissions/generators/conditional.py +++ b/oarepo_requests/services/permissions/generators/conditional.py @@ -17,15 +17,9 @@ from invenio_requests.resolvers.registry import ResolverRegistry from oarepo_runtime.datastreams.utils import get_record_service_for_record from oarepo_workflows.requests import RecipientGeneratorMixin -from oarepo_workflows.requests.generators import ( - IfEventType as WorkflowIfEventType, -) -from oarepo_workflows.requests.generators import ( - IfRequestType as WorkflowIfRequestType, -) -from oarepo_workflows.requests.generators import ( - IfRequestTypeBase, -) +from oarepo_workflows.requests.generators import IfEventType as WorkflowIfEventType +from oarepo_workflows.requests.generators import IfRequestType as WorkflowIfRequestType +from oarepo_workflows.requests.generators import IfRequestTypeBase from sqlalchemy.exc import NoResultFound from typing_extensions import deprecated diff --git a/oarepo_requests/services/record/types/service.py b/oarepo_requests/services/record/types/service.py index a04a4d8..944fa37 100644 --- a/oarepo_requests/services/record/types/service.py +++ b/oarepo_requests/services/record/types/service.py @@ -15,9 +15,7 @@ from invenio_records_resources.services import LinksTemplate from invenio_records_resources.services.base.links import Link -from oarepo_requests.services.results import ( - RequestTypesList, -) +from oarepo_requests.services.results import RequestTypesList from oarepo_requests.services.schema import RequestTypeSchema from oarepo_requests.utils import allowed_request_types_for_record diff --git a/tests/conftest.py b/tests/conftest.py index 5a7c601..2fc0a46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -321,6 +321,7 @@ class WithApprovalPermissions(RequestBasedWorkflowPermissions): ), } + @pytest.fixture(scope="module") def create_app(instance_path, entry_points): """Application factory fixture.""" @@ -334,10 +335,12 @@ def vocab_cf(app, db, cache): prepare_cf_indices() ThesisDraft.index.refresh() + @pytest.fixture() def urls(): return {"BASE_URL": "/thesis/", "BASE_URL_REQUESTS": "/requests/"} + @pytest.fixture() def serialization_result(): def _result(topic_id, request_id): @@ -472,6 +475,7 @@ def request_events_service(app): service = current_requests.request_events_service return service + @pytest.fixture(scope="module") def record_service(): return current_service @@ -547,12 +551,14 @@ def _logged_client(user): return _logged_client + @pytest.fixture() def example_topic_draft(record_service, users, default_workflow_json): # needed for ui identity = users[0].identity draft = record_service.create(identity, default_workflow_json) return draft._obj + @pytest.fixture() def merge_record_data(default_workflow_json): def _merge_data(custom_workflow=None, additional_data=None): @@ -572,6 +578,7 @@ def _merge_data(custom_workflow=None, additional_data=None): if additional_data: always_merger.merge(json, additional_data) return json + return _merge_data @@ -584,21 +591,25 @@ def record(identity, custom_workflow=None, additional_data=None): return record + @pytest.fixture() def record_factory(record_service, draft_factory, urls): # bypassing request pattern with system identity def record(client, custom_workflow=None, additional_data=None): - draft = draft_factory(client.user_fixture.identity, custom_workflow, additional_data) - record = record_service.publish(system_identity, draft['id']) - ret = client.get(f"{urls['BASE_URL']}{record['id']}") # unified return value + draft = draft_factory( + client.user_fixture.identity, custom_workflow, additional_data + ) + record = record_service.publish(system_identity, draft["id"]) + ret = client.get(f"{urls['BASE_URL']}{record['id']}") # unified return value return ret return record - @pytest.fixture() -def record_with_files_factory(record_service, draft_factory, default_workflow_json, urls): +def record_with_files_factory( + record_service, draft_factory, default_workflow_json, urls +): def record(client, custom_workflow=None, additional_data=None): identity = client.user_fixture.identity if ( @@ -607,7 +618,7 @@ def record(client, custom_workflow=None, additional_data=None): ): if not additional_data: additional_data = {} - additional_data.setdefault("files",{}).setdefault("enabled", True) + additional_data.setdefault("files", {}).setdefault("enabled", True) draft = draft_factory(identity, custom_workflow, additional_data) # upload file @@ -625,15 +636,14 @@ def record(client, custom_workflow=None, additional_data=None): ) commit = files_service.commit_file(identity, draft["id"], "test.pdf") - #publish record + # publish record record = record_service.publish(system_identity, draft["id"]) - ret = client.get(f"{urls['BASE_URL']}{record['id']}") # unified return value + ret = client.get(f"{urls['BASE_URL']}{record['id']}") # unified return value return ret return record - @pytest.fixture() def create_draft_via_resource(merge_record_data, urls): def _create_draft( @@ -645,6 +655,7 @@ def _create_draft( return _create_draft + @pytest.fixture() def events_resource_data(): """Input data for the Request Events Resource (REST body).""" @@ -655,6 +666,7 @@ def events_resource_data(): } } + def _create_role(id, name, description, is_managed, database): """Creates a Role/Group.""" r = current_datastore.create_role( @@ -726,13 +738,17 @@ def _create_request_from_link(request_types_json, request_type): return _create_request_from_link + @pytest.fixture() def request_type_additional_data(): - return {"publish_draft":{"payload": {"version": "1.0"}}} + return {"publish_draft": {"payload": {"version": "1.0"}}} + @pytest.fixture def create_request_by_link(get_request_link, request_type_additional_data): - def _create_request(client, record, request_type, additional_data=None, **request_kwargs): + def _create_request( + client, record, request_type, additional_data=None, **request_kwargs + ): if additional_data is None: additional_data = {} applicable_requests = client.get( @@ -742,11 +758,15 @@ def _create_request(client, record, request_type, additional_data=None, **reques get_request_link(applicable_requests, request_type) ) if request_type in request_type_additional_data: - additional_data = always_merger.merge(additional_data, request_type_additional_data[request_type]) + additional_data = always_merger.merge( + additional_data, request_type_additional_data[request_type] + ) if not additional_data: create_response = client.post(create_link, **request_kwargs) else: - create_response = client.post(create_link, json=additional_data, **request_kwargs) + create_response = client.post( + create_link, json=additional_data, **request_kwargs + ) return create_response return _create_request @@ -754,10 +774,19 @@ def _create_request(client, record, request_type, additional_data=None, **reques @pytest.fixture def submit_request_by_link(create_request_by_link): - def _submit_request(client, record, request_type, create_additional_data=None, submit_additional_data=None): - create_response = create_request_by_link(client, record, request_type, additional_data=create_additional_data) + def _submit_request( + client, + record, + request_type, + create_additional_data=None, + submit_additional_data=None, + ): + create_response = create_request_by_link( + client, record, request_type, additional_data=create_additional_data + ) submit_response = client.post( - link2testclient(create_response.json["links"]["actions"]["submit"]), json=submit_additional_data + link2testclient(create_response.json["links"]["actions"]["submit"]), + json=submit_additional_data, ) return submit_response diff --git a/tests/test_requests/test_allowed_request_types_link_and_service.py b/tests/test_requests/test_allowed_request_types_link_and_service.py index 1e7f17d..ee33ffb 100644 --- a/tests/test_requests/test_allowed_request_types_link_and_service.py +++ b/tests/test_requests/test_allowed_request_types_link_and_service.py @@ -7,7 +7,6 @@ # from flask import current_app from thesis.ext import ThesisExt -from thesis.records.api import ThesisDraft, ThesisRecord from tests.test_requests.utils import link2testclient @@ -104,9 +103,7 @@ def publish_record( ): id_ = draft1.json["id"] submit_request_by_link(creator_client, draft1, "publish_draft") - record = receiver_client.get( - f"{urls['BASE_URL']}{id_}/draft?expand=true" - ) + record = receiver_client.get(f"{urls['BASE_URL']}{id_}/draft?expand=true") assert record.json["expanded"]["requests"][0]["links"]["actions"].keys() == { "accept", "decline", @@ -125,7 +122,7 @@ def test_allowed_request_types_on_published_resource( urls, create_draft_via_resource, submit_request_by_link, - search_clear + search_clear, ): creator = users[0] receiver = users[1] diff --git a/tests/test_requests/test_cascade_events.py b/tests/test_requests/test_cascade_events.py index f74b4e9..4c39361 100644 --- a/tests/test_requests/test_cascade_events.py +++ b/tests/test_requests/test_cascade_events.py @@ -31,9 +31,15 @@ def test_cascade_update( draft1 = create_draft_via_resource(creator_client, custom_workflow="cascade_update") draft2 = create_draft_via_resource(creator_client, custom_workflow="cascade_update") - publish_request_create = submit_request_by_link(creator_client, draft1, "publish_draft") - another_request_create = create_request_by_link(creator_client, draft1, "another_topic_updating") - publish_request_on_second_draft = create_request_by_link(creator_client, draft2, "publish_draft") + publish_request_create = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) + another_request_create = create_request_by_link( + creator_client, draft1, "another_topic_updating" + ) + publish_request_on_second_draft = create_request_by_link( + creator_client, draft2, "publish_draft" + ) record = receiver_client.get( f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true" diff --git a/tests/test_requests/test_conditional_recipient.py b/tests/test_requests/test_conditional_recipient.py index f1f2293..5727d89 100644 --- a/tests/test_requests/test_conditional_recipient.py +++ b/tests/test_requests/test_conditional_recipient.py @@ -23,7 +23,9 @@ def test_conditional_receiver_creator_matches( draft1 = create_draft_via_resource(creator_client, custom_workflow="with_ct") - resp_request_create = create_request_by_link(creator_client, draft1, "conditional_recipient_rt") + resp_request_create = create_request_by_link( + creator_client, draft1, "conditional_recipient_rt" + ) assert resp_request_create.status_code == 201 assert resp_request_create.json["receiver"] == {"user": "2"} @@ -47,7 +49,9 @@ def test_conditional_receiver_creator_does_not_match( draft1 = create_draft_via_resource(creator_client, custom_workflow="with_ct") - resp_request_create = create_request_by_link(creator_client, draft1, "conditional_recipient_rt") + resp_request_create = create_request_by_link( + creator_client, draft1, "conditional_recipient_rt" + ) assert resp_request_create.status_code == 201 assert resp_request_create.json["receiver"] == {"user": "3"} diff --git a/tests/test_requests/test_create_conditions.py b/tests/test_requests/test_create_conditions.py index 74062e2..20dc857 100644 --- a/tests/test_requests/test_create_conditions.py +++ b/tests/test_requests/test_create_conditions.py @@ -54,9 +54,7 @@ def test_can_create( # try declining the request for draft2, we should be able to create again then resp_request_submit = creator_client.post( - link2testclient( - create_for_request_draft2.json["links"]["actions"]["submit"] - ), + link2testclient(create_for_request_draft2.json["links"]["actions"]["submit"]), ) with pytest.raises(OpenRequestAlreadyExists): diff --git a/tests/test_requests/test_create_inmodel.py b/tests/test_requests/test_create_inmodel.py index a662767..2fb2441 100644 --- a/tests/test_requests/test_create_inmodel.py +++ b/tests/test_requests/test_create_inmodel.py @@ -8,7 +8,9 @@ from thesis.records.api import ThesisRecord from tests.test_requests.utils import link2testclient -#todo since inline is now the default way to create records, these might be redundant + + +# todo since inline is now the default way to create records, these might be redundant def test_record( logged_client, record_factory, @@ -23,7 +25,9 @@ def test_record( receiver_client = logged_client(receiver) record1 = record_factory(creator_client) - resp_request_create = create_request_by_link(creator_client, record1, "delete_published_record") + resp_request_create = create_request_by_link( + creator_client, record1, "delete_published_record" + ) assert resp_request_create.status_code == 201 resp_request_submit = creator_client.post( link2testclient(resp_request_create.json["links"]["actions"]["submit"]), @@ -55,7 +59,9 @@ def test_draft( draft1 = create_draft_via_resource(creator_client) - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft") + resp_request_create = create_request_by_link( + creator_client, draft1, "publish_draft" + ) assert resp_request_create.status_code == 201 resp_request_submit = creator_client.post( link2testclient(resp_request_create.json["links"]["actions"]["submit"]), diff --git a/tests/test_requests/test_delete.py b/tests/test_requests/test_delete.py index 4573433..16c7756 100644 --- a/tests/test_requests/test_delete.py +++ b/tests/test_requests/test_delete.py @@ -31,7 +31,9 @@ def test_delete( lst = creator_client.get(urls["BASE_URL"]) assert len(lst.json["hits"]["hits"]) == 3 - resp_request_submit = submit_request_by_link(creator_client, record1, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "delete_published_record" + ) record = receiver_client.get(f"{urls['BASE_URL']}{record1.json['id']}?expand=true") assert record.json["expanded"]["requests"][0]["links"]["actions"].keys() == { @@ -52,7 +54,9 @@ def test_delete( lst = creator_client.get(urls["BASE_URL"]) assert len(lst.json["hits"]["hits"]) == 2 - resp_request_submit = submit_request_by_link(creator_client, record2, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record2, "delete_published_record" + ) record = receiver_client.get(f"{urls['BASE_URL']}{record2.json['id']}?expand=true") decline = receiver_client.post( link2testclient( @@ -64,7 +68,9 @@ def test_delete( ) assert declined_request.json["status"] == "declined" - resp_request_submit = submit_request_by_link(creator_client, record3, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record3, "delete_published_record" + ) record = creator_client.get(f"{urls['BASE_URL']}{record3.json['id']}?expand=true") assert record.json["expanded"]["requests"][0]["links"]["actions"].keys() == { "cancel" diff --git a/tests/test_requests/test_edit.py b/tests/test_requests/test_edit.py index 65e7c62..fe297ff 100644 --- a/tests/test_requests/test_edit.py +++ b/tests/test_requests/test_edit.py @@ -30,7 +30,9 @@ def test_edit_autoaccept( ) assert direct_edit.status_code == 403 - resp_request_submit = submit_request_by_link(creator_client, record1, "edit_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "edit_published_record" + ) # is request accepted and closed? request = creator_client.get( f'{urls["BASE_URL_REQUESTS"]}{resp_request_submit.json["id"]}', @@ -72,7 +74,9 @@ def test_redirect_url( record1 = record_factory(creator_client, custom_workflow="different_recipients") record_id = record1.json["id"] - resp_request_submit = submit_request_by_link(creator_client, record1, "edit_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "edit_published_record" + ) edit_request_id = resp_request_submit.json["id"] receiver_get = receiver_client.get(f"{urls['BASE_URL_REQUESTS']}{edit_request_id}") diff --git a/tests/test_requests/test_expand.py b/tests/test_requests/test_expand.py index 74e9c49..10e0f24 100644 --- a/tests/test_requests/test_expand.py +++ b/tests/test_requests/test_expand.py @@ -23,7 +23,9 @@ def test_requests_field( draft1 = create_draft_via_resource(creator_client) - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft") + resp_request_create = create_request_by_link( + creator_client, draft1, "publish_draft" + ) assert resp_request_create.status_code == 201 resp_request_submit = creator_client.post( link2testclient(resp_request_create.json["links"]["actions"]["submit"]), @@ -49,7 +51,9 @@ def test_autoaccept_receiver( creator_client = logged_client(creator) record1 = record_factory(creator_client) - resp_request_submit = submit_request_by_link(creator_client, record1, "edit_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "edit_published_record" + ) request = creator_client.get( f'{urls["BASE_URL_REQUESTS"]}{resp_request_submit.json["id"]}?expand=true' ).json diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index afb1c26..5b0552d 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -51,7 +51,9 @@ def test_read_extended( draft1 = create_draft_via_resource(creator_client) draft_id = draft1.json["id"] - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) old_call = creator_client.get( f"{urls['BASE_URL_REQUESTS']}{resp_request_submit.json['id']}" @@ -89,7 +91,9 @@ def test_update_self_link( draft1 = create_draft_via_resource(creator_client) - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) read_before = creator_client.get( link2testclient(resp_request_submit.json["links"]["self"]), @@ -129,7 +133,9 @@ def test_events_resource( creator_client = logged_client(creator) draft1 = create_draft_via_resource(creator_client) - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) read_before = creator_client.get( link2testclient(resp_request_submit.json["links"]["self"]), diff --git a/tests/test_requests/test_index_refresh.py b/tests/test_requests/test_index_refresh.py index b18362c..0333410 100644 --- a/tests/test_requests/test_index_refresh.py +++ b/tests/test_requests/test_index_refresh.py @@ -21,7 +21,9 @@ def test_search( draft1 = create_draft_via_resource(creator_client) - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft") + resp_request_create = create_request_by_link( + creator_client, draft1, "publish_draft" + ) # should work without refreshing requests index requests_search = creator_client.get(urls["BASE_URL_REQUESTS"]).json diff --git a/tests/test_requests/test_new_version.py b/tests/test_requests/test_new_version.py index bb87b28..9bac3f8 100644 --- a/tests/test_requests/test_new_version.py +++ b/tests/test_requests/test_new_version.py @@ -69,8 +69,12 @@ def test_new_version_files( record1 = record_with_files_factory(creator_client) record2 = record_with_files_factory(creator_client) - submit1 = submit_request_by_link(creator_client, record1, "new_version", - create_additional_data={"payload": {"keep_files": "yes"}}) + submit1 = submit_request_by_link( + creator_client, + record1, + "new_version", + create_additional_data={"payload": {"keep_files": "yes"}}, + ) submit2 = submit_request_by_link(creator_client, record2, "new_version") ThesisDraft.index.refresh() diff --git a/tests/test_requests/test_no_recipient.py b/tests/test_requests/test_no_recipient.py index 76526e9..18de732 100644 --- a/tests/test_requests/test_no_recipient.py +++ b/tests/test_requests/test_no_recipient.py @@ -13,7 +13,7 @@ def test_no_recipient( search_clear, ): creator = users[0] - assert creator.id == '1' + assert creator.id == "1" creator_client = logged_client(creator) @@ -24,8 +24,8 @@ def test_no_recipient( json={ "request_type": "approve_draft", "topic": {"thesis_draft": draft1.json["id"]}, - } + }, ) assert resp_request_create.status_code == 201 - assert resp_request_create.json['receiver'] is None - assert resp_request_create.json['links']['receiver'] == {} + assert resp_request_create.json["receiver"] is None + assert resp_request_create.json["links"]["receiver"] == {} diff --git a/tests/test_requests/test_param_interpreters.py b/tests/test_requests/test_param_interpreters.py index 976dffa..7573b63 100644 --- a/tests/test_requests/test_param_interpreters.py +++ b/tests/test_requests/test_param_interpreters.py @@ -6,6 +6,7 @@ # details. # import json + from tests.test_requests.utils import link2testclient @@ -82,7 +83,8 @@ def test_owner_param_interpreter( search_user1_only = user1_client.get(f'{urls["BASE_URL_REQUESTS"]}?all=true') print(json.dumps(search_user1_only.json)) for hit in search_user1_only.json["hits"]["hits"]: - assert hit['created_by'] == {"user": "1"} or hit['receiver'] == {"user": "1"} + assert hit["created_by"] == {"user": "1"} or hit["receiver"] == {"user": "1"} + def test_open_param_interpreter( logged_client, diff --git a/tests/test_requests/test_publish.py b/tests/test_requests/test_publish.py index b9bdd8d..2e2db85 100644 --- a/tests/test_requests/test_publish.py +++ b/tests/test_requests/test_publish.py @@ -74,7 +74,9 @@ def test_publish( assert len(draft_lst.json["hits"]["hits"]) == 3 assert len(lst.json["hits"]["hits"]) == 0 - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) ThesisRecord.index.refresh() ThesisDraft.index.refresh() @@ -107,7 +109,9 @@ def test_publish( assert len(draft_lst.json["hits"]["hits"]) == 3 assert len(lst.json["hits"]["hits"]) == 1 - resp_request_submit = submit_request_by_link(creator_client, draft2, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft2, "publish_draft" + ) record = receiver_client.get( f"{urls['BASE_URL']}{draft2.json['id']}/draft?expand=true" ) @@ -121,7 +125,9 @@ def test_publish( ) assert declined_request.json["status"] == "declined" - resp_request_submit = submit_request_by_link(creator_client, draft3, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft3, "publish_draft" + ) record = creator_client.get( f"{urls['BASE_URL']}{draft3.json['id']}/draft?expand=true" ) diff --git a/tests/test_requests/test_record_requests.py b/tests/test_requests/test_record_requests.py index 2baa582..66d5719 100644 --- a/tests/test_requests/test_record_requests.py +++ b/tests/test_requests/test_record_requests.py @@ -8,7 +8,6 @@ from thesis.records.api import ThesisDraft, ThesisRecord from .utils import link2testclient -from ..conftest import create_request_by_link def test_read_requests_on_draft( @@ -31,8 +30,9 @@ def test_read_requests_on_draft( ThesisRecord.index.refresh() ThesisDraft.index.refresh() - - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) record = receiver_client.get( f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true" ) @@ -79,7 +79,9 @@ def test_read_requests_on_record( record3 = record_factory(creator_client) ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_submit = submit_request_by_link(creator_client, record1, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "delete_published_record" + ) record = receiver_client.get(f"{urls['BASE_URL']}{record1.json['id']}?expand=true") decline = receiver_client.post( link2testclient( diff --git a/tests/test_requests/test_timeline.py b/tests/test_requests/test_timeline.py index 8cbc8c2..7b80c6e 100644 --- a/tests/test_requests/test_timeline.py +++ b/tests/test_requests/test_timeline.py @@ -6,6 +6,7 @@ # details. # from invenio_requests.records.api import RequestEvent + from tests.test_requests.utils import link2testclient @@ -23,7 +24,9 @@ def test_timeline( draft1 = create_draft_via_resource(creator_client) - publish_request_submit_resp = submit_request_by_link(creator_client, draft1, "publish_draft") + publish_request_submit_resp = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) comment_resp = creator_client.post( link2testclient(publish_request_submit_resp.json["links"]["comments"]), diff --git a/tests/test_requests/test_topic_resolve.py b/tests/test_requests/test_topic_resolve.py index 822a655..016b10e 100644 --- a/tests/test_requests/test_topic_resolve.py +++ b/tests/test_requests/test_topic_resolve.py @@ -32,7 +32,9 @@ def test_resolve_topic( ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_submit = submit_request_by_link(creator_client, record1, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "delete_published_record" + ) assert resp_request_submit.json["status"] == "submitted" resp = creator_client.get( @@ -90,7 +92,9 @@ def test_ui_resolve_topic( ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_submit = submit_request_by_link(creator_client, record1, "delete_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record1, "delete_published_record" + ) assert resp_request_submit.json["status"] == "submitted" resp = creator_client.get( diff --git a/tests/test_requests/test_topic_update.py b/tests/test_requests/test_topic_update.py index 6d11297..40e9014 100644 --- a/tests/test_requests/test_topic_update.py +++ b/tests/test_requests/test_topic_update.py @@ -7,7 +7,6 @@ # from .utils import link2testclient -from ..conftest import submit_request_by_link def test_publish( @@ -26,7 +25,9 @@ def test_publish( receiver_client = logged_client(receiver) draft1 = create_draft_via_resource(creator_client) - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) record = receiver_client.get( f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true" ) diff --git a/tests/test_requests/test_ui_serialialization.py b/tests/test_requests/test_ui_serialialization.py index 8835583..fadc041 100644 --- a/tests/test_requests/test_ui_serialialization.py +++ b/tests/test_requests/test_ui_serialialization.py @@ -38,12 +38,24 @@ def test_user_serialization( ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_create = create_request_by_link(client_fallback_label, draft1, "publish_draft", - headers={"Accept": "application/vnd.inveniordm.v1+json"}) - resp_request_create_username = create_request_by_link(client_username_label, draft2, "publish_draft", - headers={"Accept": "application/vnd.inveniordm.v1+json"}) - resp_request_create_fullname = create_request_by_link(client_fullname_label, draft3, "publish_draft", - headers={"Accept": "application/vnd.inveniordm.v1+json"}) + resp_request_create = create_request_by_link( + client_fallback_label, + draft1, + "publish_draft", + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) + resp_request_create_username = create_request_by_link( + client_username_label, + draft2, + "publish_draft", + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) + resp_request_create_fullname = create_request_by_link( + client_fullname_label, + draft3, + "publish_draft", + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) pprint(resp_request_create.json) assert resp_request_create.json["stateful_name"] == "Submit for review" @@ -139,7 +151,12 @@ def test_resolver_fallback( ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft", headers={"Accept": "application/vnd.inveniordm.v1+json"}) + resp_request_create = create_request_by_link( + creator_client, + draft1, + "publish_draft", + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) assert resp_request_create.json["stateful_name"] == "Submit for review" assert ( resp_request_create.json["stateful_description"] @@ -222,8 +239,12 @@ def current_receiver(record=None, request_type=None, **kwargs): ThesisRecord.index.refresh() ThesisDraft.index.refresh() - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft", - headers={"Accept": "application/vnd.inveniordm.v1+json"}) + resp_request_create = create_request_by_link( + creator_client, + draft1, + "publish_draft", + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) assert resp_request_create.json["stateful_name"] == "Submit for review" assert ( resp_request_create.json["stateful_description"] diff --git a/tests/test_requests/test_workflows.py b/tests/test_requests/test_workflows.py index e0b1a49..6bb5ee3 100644 --- a/tests/test_requests/test_workflows.py +++ b/tests/test_requests/test_workflows.py @@ -62,6 +62,7 @@ def events_service(): return current_events_service + def test_publish_with_workflows( logged_client, users, @@ -86,7 +87,9 @@ def test_publish_with_workflows( create_non_owner = receiver_client.post( f"{urls['BASE_URL']}{draft1.json['id']}/draft/requests/publish_draft", ) - resp_request_create = create_request_by_link(creator_client, draft1, "publish_draft") + resp_request_create = create_request_by_link( + creator_client, draft1, "publish_draft" + ) assert create_non_owner.status_code == 403 assert resp_request_create.status_code == 201 @@ -206,7 +209,9 @@ def test_if_no_new_version_draft( assert "new_version" not in { r["type_id"] for r in requests } # new version created, requests should not be available again - resp_request_submit = submit_request_by_link(creator_client, record2, "edit_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record2, "edit_published_record" + ) request = creator_client.get( f'{urls["BASE_URL_REQUESTS"]}{resp_request_submit.json["id"]}', ).json # request is autoaccepted @@ -242,7 +247,9 @@ def test_if_no_edit_draft( ) requests = record.json["expanded"]["request_types"] assert "edit_published_record" in {r["type_id"] for r in requests} - resp_request_submit = submit_request_by_link(creator_client, record, "edit_published_record") + resp_request_submit = submit_request_by_link( + creator_client, record, "edit_published_record" + ) request = creator_client.get( f'{urls["BASE_URL_REQUESTS"]}{resp_request_submit.json["id"]}', ).json # request is autoaccepted @@ -503,7 +510,9 @@ def test_cancel_transition( creator_client = logged_client(creator) draft1 = create_draft_via_resource(creator_client) - resp_request_submit = submit_request_by_link(creator_client, draft1, "publish_draft") + resp_request_submit = submit_request_by_link( + creator_client, draft1, "publish_draft" + ) record = creator_client.get( f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true" ) diff --git a/tests/test_requests/utils.py b/tests/test_requests/utils.py index f7cff1b..500c191 100644 --- a/tests/test_requests/utils.py +++ b/tests/test_requests/utils.py @@ -12,6 +12,7 @@ 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 :] + # from chatgpt def dict_diff(dict1, dict2, path=""): ret = defaultdict(list)