From 4b33712fae088e375625146624111ce6cb94b6f3 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Fri, 15 Mar 2024 13:53:47 +0100 Subject: [PATCH 1/9] fix for repositories without draft --- oarepo_requests/services/schema.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/oarepo_requests/services/schema.py b/oarepo_requests/services/schema.py index afc8a8ac..7ec3f36a 100644 --- a/oarepo_requests/services/schema.py +++ b/oarepo_requests/services/schema.py @@ -1,5 +1,4 @@ import marshmallow as ma -from invenio_drafts_resources.services.records.config import is_record from invenio_records_resources.services import ConditionalLink from invenio_records_resources.services.base.links import Link, LinksTemplate from invenio_requests.proxies import current_request_type_registry @@ -8,6 +7,11 @@ from oarepo_requests.utils import get_matching_service_for_record +def is_record(record, ctx): + """Shortcut for links to determine if record is a record.""" + if not hasattr(record, "is_draft"): + return True + return not record.is_draft def get_links_schema(): # TODO possibly specify more From ebd08f9882ef8662fed208d20a37deaa711eb308 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Mon, 18 Mar 2024 16:47:53 +0100 Subject: [PATCH 2/9] self link update --- oarepo_requests/ext.py | 2 +- oarepo_requests/resources/oarepo/resource.py | 31 ++++++++++++----- ...test_read_extended.py => test_extended.py} | 33 +++++++++++++++++++ 3 files changed, 57 insertions(+), 9 deletions(-) rename tests/test_requests/{test_read_extended.py => test_extended.py} (57%) diff --git a/oarepo_requests/ext.py b/oarepo_requests/ext.py index 58d1e38f..f0afded4 100644 --- a/oarepo_requests/ext.py +++ b/oarepo_requests/ext.py @@ -55,6 +55,6 @@ def init_services(self, app): def init_resources(self, app): """Init resources.""" self.requests_resource = OARepoRequestsResource( - service=self.requests_service, + oarepo_requests_service=self.requests_service, config=OARepoRequestsResourceConfig.build(app), ) diff --git a/oarepo_requests/resources/oarepo/resource.py b/oarepo_requests/resources/oarepo/resource.py index fcce5631..d79a1d22 100644 --- a/oarepo_requests/resources/oarepo/resource.py +++ b/oarepo_requests/resources/oarepo/resource.py @@ -7,17 +7,23 @@ request_headers, request_view_args, ) +from invenio_requests.proxies import current_requests_service from invenio_requests.resources import RequestsResource from oarepo_requests.utils import stringify_first_val class OARepoRequestsResource(RequestsResource, ErrorHandlersMixin): - """ - def __init__(self, config, service): - super().__init__(config) - self.service = service - """ + + def __init__( + self, + config, + oarepo_requests_service, + invenio_requests_service=current_requests_service, + ): + # so super methods can be used with original service + super().__init__(config, invenio_requests_service) + self.oarepo_requests_service = oarepo_requests_service def create_url_rules(self): """Create the URL rules for the record resource.""" @@ -46,7 +52,7 @@ def s(route): @response_handler() def create(self): - items = self.service.create( + items = self.oarepo_requests_service.create( identity=g.identity, data=resource_requestctx.data, request_type=resource_requestctx.data.pop("request_type", None), @@ -72,7 +78,7 @@ def stringify_first_val(dct): dct[k] = str(v) return dct - items = self.service.create( + items = self.oarepo_requests_service.create( identity=g.identity, data=resource_requestctx.data, type_id=resource_requestctx.data.pop("request_type", None), @@ -91,9 +97,18 @@ def stringify_first_val(dct): @response_handler() def read_extended(self): """Read an item.""" - item = self.service.read( + item = self.oarepo_requests_service.read( id_=resource_requestctx.view_args["id"], identity=g.identity, expand=resource_requestctx.args.get("expand", False), ) return item.to_dict(), 200 + + # from parent + @request_extra_args + @request_headers + @request_view_args + @request_data + @response_handler() + def update_extended(self): + return super().update() diff --git a/tests/test_requests/test_read_extended.py b/tests/test_requests/test_extended.py similarity index 57% rename from tests/test_requests/test_read_extended.py rename to tests/test_requests/test_extended.py index e4da43ae..80bda551 100644 --- a/tests/test_requests/test_read_extended.py +++ b/tests/test_requests/test_extended.py @@ -42,3 +42,36 @@ def test_read_extended( ), new_call2.json, ) + + +def test_update_self_link( + example_topic_draft, + client_logged_as, + users, + urls, + publish_request_data_function, + serialization_result, + ui_serialization_result, + search_clear, +): + receiver = users[1] + creator_client = client_logged_as(users[0].email) + resp_request_create = creator_client.post( + urls["BASE_URL_REQUESTS"], + json=publish_request_data_function(example_topic_draft["id"]), + ) + resp_request_submit = creator_client.post( + link_api2testclient(resp_request_create.json["links"]["actions"]["submit"]) + ) + read_before = creator_client.get( + link_api2testclient(resp_request_submit.json["links"]["self"]) + ) + update = creator_client.put( + link_api2testclient(resp_request_submit.json["links"]["self"]), + json={"title": "lalala"}, + ) + read_after = creator_client.get( + link_api2testclient(resp_request_submit.json["links"]["self"]) + ) + assert read_before.json["title"] == "" + assert read_after.json["title"] == "lalala" From a7fd802fcd2c4c83294ce14cb086050fe1ed9737 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Tue, 19 Mar 2024 11:13:06 +0100 Subject: [PATCH 3/9] missed resource fix --- oarepo_requests/resources/oarepo/resource.py | 6 +----- tests/test_requests/test_extended.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/oarepo_requests/resources/oarepo/resource.py b/oarepo_requests/resources/oarepo/resource.py index d79a1d22..ca9e9551 100644 --- a/oarepo_requests/resources/oarepo/resource.py +++ b/oarepo_requests/resources/oarepo/resource.py @@ -42,6 +42,7 @@ def s(route): route("POST", p(routes["list"]), self.create), route("POST", p(routes["list-extended"]), self.create_extended), route("GET", p(routes["item-extended"]), self.read_extended), + route("PUT", p(routes["item-extended"]), self.update_extended), ] return url_rules + base_routes @@ -105,10 +106,5 @@ def read_extended(self): return item.to_dict(), 200 # from parent - @request_extra_args - @request_headers - @request_view_args - @request_data - @response_handler() def update_extended(self): return super().update() diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index 80bda551..cd9b0bda 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -64,14 +64,24 @@ def test_update_self_link( link_api2testclient(resp_request_create.json["links"]["actions"]["submit"]) ) read_before = creator_client.get( - link_api2testclient(resp_request_submit.json["links"]["self"]) - ) - update = creator_client.put( link_api2testclient(resp_request_submit.json["links"]["self"]), + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) + read_from_record = creator_client.get( + f"{urls['BASE_URL']}{example_topic_draft['id']}/draft", + ) + link_to_extended = link_api2testclient( + read_from_record.json["requests"][0]["links"]["self"] + ) + + update_extended = creator_client.put( + link_to_extended, json={"title": "lalala"}, ) + assert update_extended.status_code == 200 read_after = creator_client.get( - link_api2testclient(resp_request_submit.json["links"]["self"]) + link_api2testclient(resp_request_submit.json["links"]["self"]), + headers={"Accept": "application/vnd.inveniordm.v1+json"}, ) assert read_before.json["title"] == "" assert read_after.json["title"] == "lalala" From 7940c903f89fa7e8a4fa87f1f8580b5deae62797 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Tue, 19 Mar 2024 11:52:40 +0100 Subject: [PATCH 4/9] fix --- tests/test_requests/test_extended.py | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index cd9b0bda..71ae0c49 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -65,7 +65,6 @@ def test_update_self_link( ) read_before = creator_client.get( link_api2testclient(resp_request_submit.json["links"]["self"]), - headers={"Accept": "application/vnd.inveniordm.v1+json"}, ) read_from_record = creator_client.get( f"{urls['BASE_URL']}{example_topic_draft['id']}/draft", @@ -74,6 +73,7 @@ def test_update_self_link( read_from_record.json["requests"][0]["links"]["self"] ) + assert link_to_extended.startswith(f"{urls['BASE_URL_REQUESTS']}extended") update_extended = creator_client.put( link_to_extended, json={"title": "lalala"}, @@ -81,7 +81,36 @@ def test_update_self_link( assert update_extended.status_code == 200 read_after = creator_client.get( link_api2testclient(resp_request_submit.json["links"]["self"]), - headers={"Accept": "application/vnd.inveniordm.v1+json"}, ) assert read_before.json["title"] == "" assert read_after.json["title"] == "lalala" + + +""" +def test_events_resource( + example_topic_draft, + client_logged_as, + users, + urls, + publish_request_data_function, + serialization_result, + ui_serialization_result, + search_clear, +): + receiver = users[1] + creator_client = client_logged_as(users[0].email) + resp_request_create = creator_client.post( + urls["BASE_URL_REQUESTS"], + json=publish_request_data_function(example_topic_draft["id"]), + ) + resp_request_submit = creator_client.post( + link_api2testclient(resp_request_create.json["links"]["actions"]["submit"]) + ) + read_before = creator_client.get( + link_api2testclient(resp_request_submit.json["links"]["self"]), + headers={"Accept": "application/vnd.inveniordm.v1+json"}, + ) + read_from_record = creator_client.get( + f"{urls['BASE_URL']}{example_topic_draft['id']}/draft", + ) +""" From 01a905c91ed01b6c7dd361b41d8ff1093c7a037b Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Wed, 20 Mar 2024 00:30:29 +0100 Subject: [PATCH 5/9] krist/be-240-comments-and-timeline-links-do-not-work-on-requests-404-not --- oarepo_requests/ext.py | 12 +++++-- oarepo_requests/resources/events/__init__.py | 0 oarepo_requests/resources/events/config.py | 25 ++++++++++++++ oarepo_requests/resources/events/resource.py | 35 ++++++++++++++++++++ oarepo_requests/services/schema.py | 7 +--- oarepo_requests/utils.py | 7 ++++ oarepo_requests/views/api.py | 6 ++++ oarepo_requests/views/app.py | 4 +++ setup.cfg | 4 +-- tests/conftest.py | 10 ++++++ tests/test_requests/test_extended.py | 31 ++++++++++++++--- 11 files changed, 125 insertions(+), 16 deletions(-) create mode 100644 oarepo_requests/resources/events/__init__.py create mode 100644 oarepo_requests/resources/events/config.py create mode 100644 oarepo_requests/resources/events/resource.py diff --git a/oarepo_requests/ext.py b/oarepo_requests/ext.py index f0afded4..cf92a30b 100644 --- a/oarepo_requests/ext.py +++ b/oarepo_requests/ext.py @@ -5,6 +5,11 @@ from oarepo_requests.services.oarepo.config import OARepoRequestsServiceConfig from oarepo_requests.services.oarepo.service import OARepoRequestsService +from oarepo_requests.resources.events.resource import OARepoRequestsCommentsResource +from oarepo_requests.resources.events.config import OARepoRequestsCommentsResourceConfig + +from invenio_requests.proxies import current_events_service + class OARepoRequests: def __init__(self, app=None): @@ -48,9 +53,6 @@ def init_services(self, app): service_configs = self.service_configs(app) """Initialize the service and resource for Requests.""" self.requests_service = OARepoRequestsService(config=service_configs.requests) - # self.request_events_service = RequestEventsService( - # config=service_configs.request_events, - # ) def init_resources(self, app): """Init resources.""" @@ -58,3 +60,7 @@ def init_resources(self, app): oarepo_requests_service=self.requests_service, config=OARepoRequestsResourceConfig.build(app), ) + self.request_events_resource = OARepoRequestsCommentsResource( + service=current_events_service, + config=OARepoRequestsCommentsResourceConfig.build(app), + ) diff --git a/oarepo_requests/resources/events/__init__.py b/oarepo_requests/resources/events/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/oarepo_requests/resources/events/config.py b/oarepo_requests/resources/events/config.py new file mode 100644 index 00000000..6f5be404 --- /dev/null +++ b/oarepo_requests/resources/events/config.py @@ -0,0 +1,25 @@ +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 OARepoRequestsUIJSONSerializer +class OARepoRequestsCommentsResourceConfig(RequestCommentsResourceConfig, ConfiguratorMixin): + """""" + + blueprint_name = "oarepo_request_events" + url_prefix = "/requests" + routes = { + **RequestCommentsResourceConfig.routes, + "list-extended": "/extended//comments", + "item-extended": "/extended//comments/", + "timeline-extended": "/extended//timeline", + } + + @property + def response_handlers(self): + return { + "application/vnd.inveniordm.v1+json": ResponseHandler( + OARepoRequestsUIJSONSerializer() + ), + **super().response_handlers, + } diff --git a/oarepo_requests/resources/events/resource.py b/oarepo_requests/resources/events/resource.py new file mode 100644 index 00000000..683a366c --- /dev/null +++ b/oarepo_requests/resources/events/resource.py @@ -0,0 +1,35 @@ +from flask_resources import route +from invenio_records_resources.resources.errors import ErrorHandlersMixin +from invenio_requests.resources.events.resource import RequestCommentsResource + +class OARepoRequestsCommentsResource(RequestCommentsResource, ErrorHandlersMixin): + + def create_url_rules(self): + """Create the URL rules for the record resource.""" + base_routes = super().create_url_rules() + routes = self.config.routes + + url_rules = [ + route("POST", routes["list-extended"], self.create_extended), + route("GET", routes["item-extended"], self.read_extended), + route("PUT", routes["item-extended"], self.update_extended), + route("DELETE", routes["item-extended"], self.delete_extended), + route("GET", routes["timeline-extended"], self.search_extended), + ] + return url_rules + base_routes + + # from parent + def create_extended(self): + return super().create() + + def read_extended(self): + return super().read() + + def update_extended(self): + return super().update() + + def delete_extended(self): + return super().delete() + + def search_extended(self): + return super().search() \ No newline at end of file diff --git a/oarepo_requests/services/schema.py b/oarepo_requests/services/schema.py index 7ec3f36a..267d527d 100644 --- a/oarepo_requests/services/schema.py +++ b/oarepo_requests/services/schema.py @@ -5,13 +5,8 @@ from invenio_requests.services.schemas import GenericRequestSchema from marshmallow import fields -from oarepo_requests.utils import get_matching_service_for_record +from oarepo_requests.utils import get_matching_service_for_record, is_record -def is_record(record, ctx): - """Shortcut for links to determine if record is a record.""" - if not hasattr(record, "is_draft"): - return True - return not record.is_draft def get_links_schema(): # TODO possibly specify more diff --git a/oarepo_requests/utils.py b/oarepo_requests/utils.py index 26f506d6..02817ce8 100644 --- a/oarepo_requests/utils.py +++ b/oarepo_requests/utils.py @@ -139,3 +139,10 @@ def stringify_first_val(dct): for k, v in dct.items(): dct[k] = str(v) return dct + + +def is_record(record, ctx): + """Shortcut for links to determine if record is a record.""" + if not hasattr(record, "is_draft"): + return True + return not record.is_draft diff --git a/oarepo_requests/views/api.py b/oarepo_requests/views/api.py index 445c8ee6..7208d4cb 100644 --- a/oarepo_requests/views/api.py +++ b/oarepo_requests/views/api.py @@ -3,3 +3,9 @@ def create_oarepo_requests(app): ext = app.extensions["oarepo-requests"] blueprint = ext.requests_resource.as_blueprint() return blueprint + +def create_oarepo_requests_events(app): + """Create requests blueprint.""" + ext = app.extensions["oarepo-requests"] + blueprint = ext.request_events_resource.as_blueprint() + return blueprint diff --git a/oarepo_requests/views/app.py b/oarepo_requests/views/app.py index 5ae753fa..4eefb278 100644 --- a/oarepo_requests/views/app.py +++ b/oarepo_requests/views/app.py @@ -4,3 +4,7 @@ def create_app_blueprint(app): blueprint = Blueprint("oarepo_requests_app", __name__, url_prefix="/requests/") return blueprint + +def create_app_events_blueprint(app): + blueprint = Blueprint("oarepo_requests_events_app", __name__, url_prefix="/requests/") + return blueprint diff --git a/setup.cfg b/setup.cfg index 107e935c..60d35d11 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,14 +31,14 @@ invenio_base.api_apps = oarepo_requests = oarepo_requests.ext:OARepoRequests invenio_base.apps = thesis = oarepo_requests.ext:OARepoRequests -#invenio_base.blueprints = -# oarepo_requests = oarepo_requests.views.api:create_oarepo_requests invenio_base.api_blueprints = oarepo_requests = oarepo_requests.views.api:create_oarepo_requests + oarepo_requests_events = oarepo_requests.views.api:create_oarepo_requests_events invenio_base.blueprints = oarepo_requests = oarepo_requests.views.app:create_app_blueprint + oarepo_requests_events = oarepo_requests.views.app:create_app_events_blueprint diff --git a/tests/conftest.py b/tests/conftest.py index bf6a6706..4a28c460 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -381,6 +381,16 @@ def request_with_receiver_user( request = Request.get_record(request_item.id) return request_item +@pytest.fixture() +def events_resource_data(): + """Input data for the Request Events Resource (REST body).""" + return { + "payload": { + "content": "This is a comment.", + "format": RequestEventFormat.HTML.value, + } + } + # ------- import os diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index 71ae0c49..af46ef7a 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -1,5 +1,5 @@ from .utils import is_valid_subdict, link_api2testclient - +from invenio_requests.records.api import RequestEvent def test_read_extended( example_topic_draft, @@ -85,8 +85,6 @@ def test_update_self_link( assert read_before.json["title"] == "" assert read_after.json["title"] == "lalala" - -""" def test_events_resource( example_topic_draft, client_logged_as, @@ -95,9 +93,9 @@ def test_events_resource( publish_request_data_function, serialization_result, ui_serialization_result, + events_resource_data, search_clear, ): - receiver = users[1] creator_client = client_logged_as(users[0].email) resp_request_create = creator_client.post( urls["BASE_URL_REQUESTS"], @@ -113,4 +111,27 @@ def test_events_resource( read_from_record = creator_client.get( f"{urls['BASE_URL']}{example_topic_draft['id']}/draft", ) -""" + + comments_link = link_api2testclient(read_from_record.json['requests'][0]["links"]["comments"]) + timeline_link = link_api2testclient(read_from_record.json['requests'][0]["links"]["timeline"]) + + comments_extended = creator_client.post( + comments_link, + json=events_resource_data, + ) + assert comments_extended.status_code == 201 + comment = creator_client.get( + f"{comments_link}/{comments_extended.json['id']}", + ) + assert comment.status_code == 200 + RequestEvent.index.refresh() + comments_extended_timeline = creator_client.get( + timeline_link, + ) + assert comments_extended_timeline.status_code == 200 + assert len(comments_extended_timeline.json["hits"]["hits"]) == 1 + + + + + From 8301c40d81ee112bed86364cef27842911a62256 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Wed, 20 Mar 2024 09:21:44 +0100 Subject: [PATCH 6/9] format --- oarepo_requests/ext.py | 8 +++----- oarepo_requests/resources/events/config.py | 6 +++++- oarepo_requests/resources/events/resource.py | 3 ++- oarepo_requests/views/api.py | 1 + oarepo_requests/views/app.py | 5 ++++- tests/conftest.py | 1 + tests/test_requests/test_extended.py | 18 ++++++++++-------- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/oarepo_requests/ext.py b/oarepo_requests/ext.py index cf92a30b..aff6da9e 100644 --- a/oarepo_requests/ext.py +++ b/oarepo_requests/ext.py @@ -1,15 +1,13 @@ from invenio_base.utils import obj_or_import_string +from invenio_requests.proxies import current_events_service +from oarepo_requests.resources.events.config import OARepoRequestsCommentsResourceConfig +from oarepo_requests.resources.events.resource import OARepoRequestsCommentsResource from oarepo_requests.resources.oarepo.config import OARepoRequestsResourceConfig from oarepo_requests.resources.oarepo.resource import OARepoRequestsResource from oarepo_requests.services.oarepo.config import OARepoRequestsServiceConfig from oarepo_requests.services.oarepo.service import OARepoRequestsService -from oarepo_requests.resources.events.resource import OARepoRequestsCommentsResource -from oarepo_requests.resources.events.config import OARepoRequestsCommentsResourceConfig - -from invenio_requests.proxies import current_events_service - class OARepoRequests: def __init__(self, app=None): diff --git a/oarepo_requests/resources/events/config.py b/oarepo_requests/resources/events/config.py index 6f5be404..f699a40a 100644 --- a/oarepo_requests/resources/events/config.py +++ b/oarepo_requests/resources/events/config.py @@ -3,7 +3,11 @@ from invenio_requests.resources.events.config import RequestCommentsResourceConfig from oarepo_requests.resources.ui import OARepoRequestsUIJSONSerializer -class OARepoRequestsCommentsResourceConfig(RequestCommentsResourceConfig, ConfiguratorMixin): + + +class OARepoRequestsCommentsResourceConfig( + RequestCommentsResourceConfig, ConfiguratorMixin +): """""" blueprint_name = "oarepo_request_events" diff --git a/oarepo_requests/resources/events/resource.py b/oarepo_requests/resources/events/resource.py index 683a366c..69a4059c 100644 --- a/oarepo_requests/resources/events/resource.py +++ b/oarepo_requests/resources/events/resource.py @@ -2,6 +2,7 @@ from invenio_records_resources.resources.errors import ErrorHandlersMixin from invenio_requests.resources.events.resource import RequestCommentsResource + class OARepoRequestsCommentsResource(RequestCommentsResource, ErrorHandlersMixin): def create_url_rules(self): @@ -32,4 +33,4 @@ def delete_extended(self): return super().delete() def search_extended(self): - return super().search() \ No newline at end of file + return super().search() diff --git a/oarepo_requests/views/api.py b/oarepo_requests/views/api.py index 7208d4cb..ea7df014 100644 --- a/oarepo_requests/views/api.py +++ b/oarepo_requests/views/api.py @@ -4,6 +4,7 @@ def create_oarepo_requests(app): blueprint = ext.requests_resource.as_blueprint() return blueprint + def create_oarepo_requests_events(app): """Create requests blueprint.""" ext = app.extensions["oarepo-requests"] diff --git a/oarepo_requests/views/app.py b/oarepo_requests/views/app.py index 4eefb278..f9ab7a68 100644 --- a/oarepo_requests/views/app.py +++ b/oarepo_requests/views/app.py @@ -5,6 +5,9 @@ def create_app_blueprint(app): blueprint = Blueprint("oarepo_requests_app", __name__, url_prefix="/requests/") return blueprint + def create_app_events_blueprint(app): - blueprint = Blueprint("oarepo_requests_events_app", __name__, url_prefix="/requests/") + blueprint = Blueprint( + "oarepo_requests_events_app", __name__, url_prefix="/requests/" + ) return blueprint diff --git a/tests/conftest.py b/tests/conftest.py index 4a28c460..6e89659e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -381,6 +381,7 @@ def request_with_receiver_user( request = Request.get_record(request_item.id) return request_item + @pytest.fixture() def events_resource_data(): """Input data for the Request Events Resource (REST body).""" diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index af46ef7a..e1c00ea1 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -1,6 +1,8 @@ -from .utils import is_valid_subdict, link_api2testclient from invenio_requests.records.api import RequestEvent +from .utils import is_valid_subdict, link_api2testclient + + def test_read_extended( example_topic_draft, client_logged_as, @@ -85,6 +87,7 @@ def test_update_self_link( assert read_before.json["title"] == "" assert read_after.json["title"] == "lalala" + def test_events_resource( example_topic_draft, client_logged_as, @@ -112,8 +115,12 @@ def test_events_resource( f"{urls['BASE_URL']}{example_topic_draft['id']}/draft", ) - comments_link = link_api2testclient(read_from_record.json['requests'][0]["links"]["comments"]) - timeline_link = link_api2testclient(read_from_record.json['requests'][0]["links"]["timeline"]) + comments_link = link_api2testclient( + read_from_record.json["requests"][0]["links"]["comments"] + ) + timeline_link = link_api2testclient( + read_from_record.json["requests"][0]["links"]["timeline"] + ) comments_extended = creator_client.post( comments_link, @@ -130,8 +137,3 @@ def test_events_resource( ) assert comments_extended_timeline.status_code == 200 assert len(comments_extended_timeline.json["hits"]["hits"]) == 1 - - - - - From 1cc090c3a5f39a0231a3bb7aea94fd2ac1a1d0f0 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Thu, 21 Mar 2024 11:12:46 +0100 Subject: [PATCH 7/9] test_fix --- tests/test_requests/test_publish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_requests/test_publish.py b/tests/test_requests/test_publish.py index ef47f921..8cf0f3a3 100644 --- a/tests/test_requests/test_publish.py +++ b/tests/test_requests/test_publish.py @@ -60,7 +60,7 @@ def test_publish( ThesisDraft.index.refresh() draft_lst = logged_client_request(creator, "get", f"/user{urls['BASE_URL']}") lst = logged_client_request(creator, "get", urls["BASE_URL"]) - assert len(draft_lst.json["hits"]["hits"]) == 2 + assert len(draft_lst.json["hits"]["hits"]) == 3 assert len(lst.json["hits"]["hits"]) == 1 resp_request_create = logged_client_request( From f91cf35d456206e75406b45ed53bdaeb37d58a97 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Thu, 21 Mar 2024 11:16:24 +0100 Subject: [PATCH 8/9] version bump --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 60d35d11..8e85ed78 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-requests -version = 1.1.4 +version = 1.1.5 description = authors = Ronald Krist readme = README.md From 52902b4e6c6b8384b1d63e03adae9cae5326e0e8 Mon Sep 17 00:00:00 2001 From: Ronald Krist Date: Thu, 21 Mar 2024 15:00:01 +0100 Subject: [PATCH 9/9] check extended link to events resourced is checked in test --- tests/test_requests/test_extended.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_requests/test_extended.py b/tests/test_requests/test_extended.py index e1c00ea1..1bcd9930 100644 --- a/tests/test_requests/test_extended.py +++ b/tests/test_requests/test_extended.py @@ -122,6 +122,9 @@ def test_events_resource( read_from_record.json["requests"][0]["links"]["timeline"] ) + assert comments_link.startswith("/requests/extended") + assert timeline_link.startswith("/requests/extended") + comments_extended = creator_client.post( comments_link, json=events_resource_data,