From 36456e454b90338a8b209884e1876aefa03ea9f4 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Tue, 26 Nov 2024 16:03:49 +0100 Subject: [PATCH] workflows: fixed set_schema and create_ticket_on_author_update * ref: cern-sis/issues-inspire/issues/611 --- .../author_create/author_create_init.py | 2 +- .../author/author_update/author_update.py | 2 +- .../TestAuthorCreateInit.test_set_schema.yaml | 51 +++++++++++ ...e.test_create_ticket_on_author_update.yaml | 91 +++++++++++++++++++ ...r_create_tasks.py => test_author_tasks.py} | 16 ++++ 5 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 workflows/tests/cassettes/TestAuthorCreateInit.test_set_schema.yaml create mode 100644 workflows/tests/cassettes/TestAuthorUpdate.test_create_ticket_on_author_update.yaml rename workflows/tests/{test_author_create_tasks.py => test_author_tasks.py} (85%) diff --git a/workflows/dags/author/author_create/author_create_init.py b/workflows/dags/author/author_create/author_create_init.py index 50eb846ea..84c87baf5 100644 --- a/workflows/dags/author/author_create/author_create_init.py +++ b/workflows/dags/author/author_create/author_create_init.py @@ -57,7 +57,7 @@ def set_schema(**context): workflow_management_hook.partial_update_workflow( workflow_id=context["params"]["workflow_id"], workflow_partial_update_data={ - "data": {**context["params"]["data"], "$schema": schema} + "data": {**context["params"]["workflow"]["data"], "$schema": schema} }, ) diff --git a/workflows/dags/author/author_update/author_update.py b/workflows/dags/author/author_update/author_update.py index 826b8c679..533db494f 100644 --- a/workflows/dags/author/author_update/author_update.py +++ b/workflows/dags/author/author_update/author_update.py @@ -82,7 +82,7 @@ def create_ticket_on_author_update(**context): workflow_ticket_management_hook.create_ticket_entry( workflow_id=context["params"]["workflow_id"], - ticket_type="author_update_user", + ticket_type="author_update_curation", ticket_id=ticket_id, ) diff --git a/workflows/tests/cassettes/TestAuthorCreateInit.test_set_schema.yaml b/workflows/tests/cassettes/TestAuthorCreateInit.test_set_schema.yaml new file mode 100644 index 000000000..9789ddebc --- /dev/null +++ b/workflows/tests/cassettes/TestAuthorCreateInit.test_set_schema.yaml @@ -0,0 +1,51 @@ +interactions: +- request: + body: '{"data": {"$schema": "https://inspirehep.net/schemas/records/authors.json", + "_collections": ["Authors"], "acquisition_source": {"datetime": "2024-11-18T11:34:19.809575", + "email": "micha.moshe.moskovic@cern.ch", "internal_uid": 50872, "method": "submitter", + "orcid": "0000-0002-7638-5686", "source": "submitter"}, "name": {"preferred_name": + "Third B", "value": "B, Third"}, "status": "active"}}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '393' + Content-Type: + - application/json + method: PATCH + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521/ + response: + body: + string: '{"id":"00000000-0000-0000-0000-000000001521","tickets":[],"decisions":[],"data":{"$schema":"https://inspirehep.net/schemas/records/authors.json","_collections":["Authors"],"acquisition_source":{"datetime":"2024-11-18T11:34:19.809575","email":"micha.moshe.moskovic@cern.ch","internal_uid":50872,"method":"submitter","orcid":"0000-0002-7638-5686","source":"submitter"},"name":{"preferred_name":"Third + B","value":"B, Third"},"status":"active"},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-11-26T14:13:56.571976Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '580' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Tue, 26 Nov 2024 14:13:56 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 200 + message: OK +version: 1 diff --git a/workflows/tests/cassettes/TestAuthorUpdate.test_create_ticket_on_author_update.yaml b/workflows/tests/cassettes/TestAuthorUpdate.test_create_ticket_on_author_update.yaml new file mode 100644 index 000000000..671989d7a --- /dev/null +++ b/workflows/tests/cassettes/TestAuthorUpdate.test_create_ticket_on_author_update.yaml @@ -0,0 +1,91 @@ +interactions: +- request: + body: '{"functional_category": "Author updates", "template": "curator_update_author", + "subject": "Update to author Third B on INSPIRE", "template_context": {"url": + "https://inspirebeta.net/authors/12345", "bibedit_url": "https://inspirebeta.net/record/12345", + "url_author_form": "https://inspirebeta.net/submissions/authors/12345"}, "caller_email": + "micha.moshe.moskovic@cern.ch"}' + headers: + Accept: + - application/vnd+inspire.record.raw+json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '373' + Content-Type: + - application/json + method: POST + uri: https://inspirebeta.net/api/tickets/create + response: + body: + string: '{"ticket_id":"9e67066e8746d250225886640cbb3565","ticket_url":"https://cerntraining.service-now.com/nav_to.do?uri=/u_request_fulfillment.do?sys_id=9e67066e8746d250225886640cbb3565"} + + ' + headers: + access-control-allow-origin: + - '*' + access-control-expose-headers: + - Content-Type, ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset + alt-svc: + - h3=":443";ma=60; + content-length: + - '181' + content-type: + - application/json + date: + - Tue, 26 Nov 2024 15:00:51 GMT + server: + - gunicorn/19.10.0 + x-proxy-backend: + - inspire-qa_hep-web_http + status: + code: 200 + message: OK +- request: + body: '{"ticket_type": "author_update_curation", "ticket_id": "9e67066e8746d250225886640cbb3565", + "workflow": "00000000-0000-0000-0000-000000001521"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '142' + Content-Type: + - application/json + method: POST + uri: http://host.docker.internal:8001/api/workflows/authors/tickets/ + response: + body: + string: '{"id":3,"ticket_url":"https://cerntraining.service-now.com/nav_to.do?uri=/u_request_fulfillment.do?sys_id=9e67066e8746d250225886640cbb3565","workflow":"00000000-0000-0000-0000-000000001521","ticket_id":"9e67066e8746d250225886640cbb3565","ticket_type":"author_update_curation","_created_at":"2024-11-26T15:00:51.801217Z","_updated_at":"2024-11-26T15:00:51.801236Z"}' + headers: + Allow: + - GET, POST, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '364' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Tue, 26 Nov 2024 15:00:51 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + status: + code: 201 + message: Created +version: 1 diff --git a/workflows/tests/test_author_create_tasks.py b/workflows/tests/test_author_tasks.py similarity index 85% rename from workflows/tests/test_author_create_tasks.py rename to workflows/tests/test_author_tasks.py index f1b749e04..9b7ccb12d 100644 --- a/workflows/tests/test_author_create_tasks.py +++ b/workflows/tests/test_author_tasks.py @@ -58,6 +58,11 @@ class TestAuthorCreateInit: dag = dagbag.get_dag("author_create_initialization_dag") context = base_context + @pytest.mark.vcr + def test_set_schema(self): + task = self.dag.get_task("set_schema") + task.execute(context=self.context) + @pytest.mark.vcr def test_create_author_create_user_ticket(self): task = self.dag.get_task("create_author_create_user_ticket") @@ -79,3 +84,14 @@ def test_close_author_create_user_ticket(self): def test_create_author_create_curation_ticket(self): task = self.dag.get_task("create_author_create_curation_ticket") task.execute(context=self.context) + + +class TestAuthorUpdate: + dag = dagbag.get_dag("author_update_dag") + context = base_context + context["params"]["workflow"]["data"]["control_number"] = "12345" + + @pytest.mark.vcr + def test_create_ticket_on_author_update(self): + task = self.dag.get_task("create_ticket_on_author_update") + task.execute(context=self.context)