From b13a5c8e794cd7542db0d1c2e008aaaea0e84404 Mon Sep 17 00:00:00 2001 From: DonHaul Date: Wed, 18 Dec 2024 16:01:45 +0100 Subject: [PATCH] workflows: author submissions not erroring also some small config fixes for easy testing with docker * ref: https://github.com/cern-sis/issues-inspire/issues/643 --- Makefile | 1 + backend/inspirehep/config.py | 6 +- .../author_create/author_create_init.py | 3 +- .../backoffice/workflow_management_hook.py | 4 +- .../include/utils/set_workflow_status.py | 10 +- ...nagementHook.test_set_workflow_status.yaml | 458 +++++++++++++ ...owManagementHook.test_update_workflow.yaml | 646 ++++++++++++++++++ workflows/tests/test_set_workflow_status.py | 26 + .../tests/test_workflow_management_hook.py | 47 ++ 9 files changed, 1190 insertions(+), 11 deletions(-) create mode 100644 workflows/tests/cassettes/TestWorkflowManagementHook.test_set_workflow_status.yaml create mode 100644 workflows/tests/cassettes/TestWorkflowManagementHook.test_update_workflow.yaml create mode 100644 workflows/tests/test_set_workflow_status.py diff --git a/Makefile b/Makefile index 3e3eeb185..b976f6cd8 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,7 @@ run: services start-inspirehep sleep setup-inspirehep start-backoffice sleep set run-inspirehep: services start-inspirehep sleep setup-inspirehep run-backoffice: services start-backoffice sleep setup-backoffice +start: services start-inspirehep start-backoffice start-inspirehep: echo -e "\033[0;32m Starting HEP. \033[0m" diff --git a/backend/inspirehep/config.py b/backend/inspirehep/config.py index bd2b11d3c..05ab0f117 100644 --- a/backend/inspirehep/config.py +++ b/backend/inspirehep/config.py @@ -31,7 +31,7 @@ FEATURE_FLAG_ENABLE_ORCID_PUSH = False FEATURE_FLAG_ENABLE_REDIRECTION_OF_PIDS = False FEATURE_FLAG_ENABLE_ASSIGN_AUTHOR_PAPERS = False -FEATURE_FLAG_ENABLE_SEND_TO_BACKOFFICE = False +FEATURE_FLAG_ENABLE_SEND_TO_BACKOFFICE = True # Only push to ORCIDs that match this regex. # Examples: # any ORCID -> ".*" @@ -51,8 +51,8 @@ INSPIRE_NEXT_URL = "http://localhost:5000" LEGACY_BASE_URL = "https://old.inspirehep.net" LEGACY_RECORD_URL_PATTERN = "http://inspirehep.net/record/{recid}" -INSPIRE_BACKOFFICE_URL = "https://backoffice.dev.inspirebeta.net" -AUTHENTICATION_TOKEN_BACKOFFICE = "CHANGE_ME" +INSPIRE_BACKOFFICE_URL = "http://host.docker.internal:8001" +AUTHENTICATION_TOKEN_BACKOFFICE = "2e04111a61e8f5ba6ecec52af21bbb9e81732085" MAX_API_RESULTS = 10000 REST_MIMETYPE_QUERY_ARG_NAME = "format" diff --git a/workflows/dags/author/author_create/author_create_init.py b/workflows/dags/author/author_create/author_create_init.py index 84c87baf5..31f88e0d3 100644 --- a/workflows/dags/author/author_create/author_create_init.py +++ b/workflows/dags/author/author_create/author_create_init.py @@ -21,13 +21,14 @@ params={ "workflow_id": Param(type="string", default=""), "data": Param(type="object", default={}), + "collection": Param(type="string", default=AUTHORS), }, start_date=datetime.datetime(2024, 5, 5), schedule=None, catchup=False, # TODO: what if callback fails? Data in backoffice not up to date! on_failure_callback=set_workflow_status_to_error, - tags=["authors"], + tags=[AUTHORS], ) def author_create_initialization_dag(): """ diff --git a/workflows/plugins/hooks/backoffice/workflow_management_hook.py b/workflows/plugins/hooks/backoffice/workflow_management_hook.py index 91e2395a5..95fbc3375 100644 --- a/workflows/plugins/hooks/backoffice/workflow_management_hook.py +++ b/workflows/plugins/hooks/backoffice/workflow_management_hook.py @@ -50,7 +50,7 @@ def update_workflow(self, workflow_id: str, workflow_data: dict) -> Response: return self.run_with_advanced_retry( _retry_args=self.tenacity_retry_kwargs, method="PUT", - data=workflow_data, + json=workflow_data, endpoint=endpoint, ) @@ -61,6 +61,6 @@ def partial_update_workflow( return self.run_with_advanced_retry( _retry_args=self.tenacity_retry_kwargs, method="PATCH", - data=workflow_partial_update_data, + json=workflow_partial_update_data, endpoint=endpoint, ) diff --git a/workflows/plugins/include/utils/set_workflow_status.py b/workflows/plugins/include/utils/set_workflow_status.py index 31a7c73b7..b4bd82bb0 100644 --- a/workflows/plugins/include/utils/set_workflow_status.py +++ b/workflows/plugins/include/utils/set_workflow_status.py @@ -1,6 +1,6 @@ import logging -from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook +from hooks.backoffice.workflow_management_hook import WorkflowManagementHook from requests import Response logger = logging.getLogger(__name__) @@ -36,10 +36,10 @@ def set_workflow_status_to_error(context: dict) -> None: workflow_id (str): The identifier for the workflow. """ logger.info("Setting workflow status to error") - response = WorkflowManagementHook().set_workflow_status( - status_name="error", - workflow_id=context["params"]["workflow_id"], - collection=AUTHORS, + response = WorkflowManagementHook( + collection=context["params"]["collection"] + ).set_workflow_status( + status_name="error", workflow_id=context["params"]["workflow_id"] ) try: response.raise_for_status() diff --git a/workflows/tests/cassettes/TestWorkflowManagementHook.test_set_workflow_status.yaml b/workflows/tests/cassettes/TestWorkflowManagementHook.test_set_workflow_status.yaml new file mode 100644 index 000000000..7b725192b --- /dev/null +++ b/workflows/tests/cassettes/TestWorkflowManagementHook.test_set_workflow_status.yaml @@ -0,0 +1,458 @@ +interactions: +- request: + body: '{"status": "error"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '19' + 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":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.116687Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '498' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=126.33300000000247;desc="User CPU time", TimerPanel_stime;dur=0.34299999999376496;desc="System + CPU time", TimerPanel_total;dur=126.67599999999624;desc="Total CPU time", + TimerPanel_total_time;dur=176.78212499595247;desc="Elapsed time", SQLPanel_sql_time;dur=4.881624015979469;desc="SQL + 10 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 73351a28ff304b8f8e03b433e7460547 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.116687Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '521' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=25.58299999999747;desc="User CPU time", TimerPanel_stime;dur=0.11500000000097543;desc="System + CPU time", TimerPanel_total;dur=25.697999999998444;desc="Total CPU time", + TimerPanel_total_time;dur=30.352375004440546;desc="Elapsed time", SQLPanel_sql_time;dur=4.758288065204397;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - fccf6b01b2954230a81eb806d13e17a6 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"error","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.116687Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '521' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=23.446999999990226;desc="User CPU time", TimerPanel_stime;dur=1.6430000000013933;desc="System + CPU time", TimerPanel_total;dur=25.08999999999162;desc="Total CPU time", TimerPanel_total_time;dur=30.97674998571165;desc="Elapsed + time", SQLPanel_sql_time;dur=5.160792003152892;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache + 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - fbf63c4d899d436c9809f0ef55f7301f + status: + code: 200 + message: OK +- request: + body: '{"status": "running"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '21' + 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":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.434907Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '500' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=25.272999999998547;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=25.272999999998547;desc="Total CPU time", + TimerPanel_total_time;dur=37.83641700283624;desc="Elapsed time", SQLPanel_sql_time;dur=3.2638350094202906;desc="SQL + 10 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 0ed0c78965d7428c8c4def29c782c7ae + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.434907Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '523' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=22.463999999999373;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=22.463999999999373;desc="Total CPU time", + TimerPanel_total_time;dur=26.37154099647887;desc="Elapsed time", SQLPanel_sql_time;dur=3.205620974767953;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 119cce0dff2b4a2a8eb787b4a027650e + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"active","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:01:11.434907Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '523' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:01:11 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=64.68800000000385;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=64.68800000000385;desc="Total CPU time", TimerPanel_total_time;dur=68.7610000022687;desc="Elapsed + time", SQLPanel_sql_time;dur=3.3001650008372962;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache + 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 933f7258152742449e932aec53af03e7 + status: + code: 200 + message: OK +version: 1 diff --git a/workflows/tests/cassettes/TestWorkflowManagementHook.test_update_workflow.yaml b/workflows/tests/cassettes/TestWorkflowManagementHook.test_update_workflow.yaml new file mode 100644 index 000000000..b47ec7b22 --- /dev/null +++ b/workflows/tests/cassettes/TestWorkflowManagementHook.test_update_workflow.yaml @@ -0,0 +1,646 @@ +interactions: +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:21 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:12.803624Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=63.23100000000181;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=63.23100000000181;desc="Total CPU time", TimerPanel_total_time;dur=67.15829099994153;desc="Elapsed + time", SQLPanel_sql_time;dur=3.3035429660230875;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache + 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 9cc444e32c244f1fab02329916902928 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:12.803624Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=23.00800000000436;desc="User CPU time", TimerPanel_stime;dur=1.0680000000036216;desc="System + CPU time", TimerPanel_total;dur=24.07600000000798;desc="Total CPU time", TimerPanel_total_time;dur=28.826082998421043;desc="Elapsed + time", SQLPanel_sql_time;dur=4.843874019570649;desc="SQL 12 queries", CachePanel_total_time;dur=0;desc="Cache + 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 33f00b1a686e41cf9069a5b79111964d + status: + code: 200 + message: OK +- request: + body: '{"id": "00000000-0000-0000-0000-000000001521", "tickets": [], "decisions": + [], "validation_errors": [], "data": {"name": {"value": "B, Third", "preferred_name": + "Third B"}, "status": "deceased", "_collections": ["Authors"], "acquisition_source": + {"email": "user@cern.ch", "orcid": "0000-0000-0000-0000", "method": "submitter", + "source": "submitter", "datetime": "2024-11-18T11:34:19.809575", "internal_uid": + 50872}}, "workflow_type": "AUTHOR_CREATE", "status": "running", "_created_at": + "2024-11-25T13:49:53.009000Z", "_updated_at": "2024-12-18T16:16:12.803624Z"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '563' + Content-Type: + - application/json + method: PUT + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"deceased","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.146702Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=29.34600000000387;desc="User CPU time", TimerPanel_stime;dur=0.9359999999958291;desc="System + CPU time", TimerPanel_total;dur=30.281999999999698;desc="Total CPU time", + TimerPanel_total_time;dur=40.6737909943331;desc="Elapsed time", SQLPanel_sql_time;dur=4.049498063977808;desc="SQL + 14 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 05517897c30040fd9b7910a807b66301 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"deceased","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.146702Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=21.867000000000303;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=21.867000000000303;desc="Total CPU time", + TimerPanel_total_time;dur=25.82608300144784;desc="Elapsed time", SQLPanel_sql_time;dur=3.34125105291605;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - dc080953000f427385aec507a2b0f123 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"deceased","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.146702Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=21.517000000002895;desc="User CPU time", TimerPanel_stime;dur=0.0;desc="System + CPU time", TimerPanel_total;dur=21.517000000002895;desc="Total CPU time", + TimerPanel_total_time;dur=25.537208013702184;desc="Elapsed time", SQLPanel_sql_time;dur=3.3327479904983193;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 10fed3aaa38145b787c39f1f6c8f5614 + status: + code: 200 + message: OK +- request: + body: '{"id": "00000000-0000-0000-0000-000000001521", "tickets": [], "decisions": + [], "validation_errors": [], "data": {"name": {"value": "B, Third", "preferred_name": + "Third B"}, "status": "departed", "_collections": ["Authors"], "acquisition_source": + {"email": "user@cern.ch", "orcid": "0000-0000-0000-0000", "method": "submitter", + "source": "submitter", "datetime": "2024-11-18T11:34:19.809575", "internal_uid": + 50872}}, "workflow_type": "AUTHOR_CREATE", "status": "running", "_created_at": + "2024-11-25T13:49:53.009000Z", "_updated_at": "2024-12-18T16:16:12.803624Z"}' + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '563' + Content-Type: + - application/json + method: PUT + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.312782Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=75.23299999999722;desc="User CPU time", TimerPanel_stime;dur=0.5610000000046966;desc="System + CPU time", TimerPanel_total;dur=75.79400000000192;desc="Total CPU time", TimerPanel_total_time;dur=84.90729201002978;desc="Elapsed + time", SQLPanel_sql_time;dur=3.826252039289102;desc="SQL 14 queries", CachePanel_total_time;dur=0;desc="Cache + 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - 17a1d92e132146b7b81705bcef6cd5ee + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.312782Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=19.52700000001073;desc="User CPU time", TimerPanel_stime;dur=2.074999999990723;desc="System + CPU time", TimerPanel_total;dur=21.602000000001453;desc="Total CPU time", + TimerPanel_total_time;dur=25.451500026974827;desc="Elapsed time", SQLPanel_sql_time;dur=3.2643319573253393;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - a978efb412c0473c81ae65e1fe87a7f4 + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Type: + - application/json + method: GET + uri: http://host.docker.internal:8001/api/workflows/authors/00000000-0000-0000-0000-000000001521 + response: + body: + string: '' + headers: + Connection: + - close + Content-Language: + - en + Content-Type: + - text/html; charset=utf-8 + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Location: + - /api/workflows/authors/00000000-0000-0000-0000-000000001521/ + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Vary: + - Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + status: + code: 301 + message: Moved Permanently +- request: + body: null + headers: + Accept: + - application/json + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + 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":[],"validation_errors":[],"data":{"name":{"value":"B, + Third","preferred_name":"Third B"},"status":"departed","_collections":["Authors"],"acquisition_source":{"email":"user@cern.ch","orcid":"0000-0000-0000-0000","method":"submitter","source":"submitter","datetime":"2024-11-18T11:34:19.809575","internal_uid":50872}},"workflow_type":"AUTHOR_CREATE","status":"running","_created_at":"2024-11-25T13:49:53.009000Z","_updated_at":"2024-12-18T16:16:22.312782Z"}' + headers: + Allow: + - GET, PUT, PATCH, DELETE, HEAD, OPTIONS + Content-Language: + - en + Content-Length: + - '525' + Content-Type: + - application/json + Cross-Origin-Opener-Policy: + - same-origin + Date: + - Wed, 18 Dec 2024 16:16:22 GMT + Referrer-Policy: + - same-origin + Server: + - WSGIServer/0.2 CPython/3.11.6 + Server-Timing: + - TimerPanel_utime;dur=28.604000000001406;desc="User CPU time", TimerPanel_stime;dur=0.927000000004341;desc="System + CPU time", TimerPanel_total;dur=29.531000000005747;desc="Total CPU time", + TimerPanel_total_time;dur=30.71041702060029;desc="Elapsed time", SQLPanel_sql_time;dur=4.260957968654111;desc="SQL + 12 queries", CachePanel_total_time;dur=0;desc="Cache 0 Calls" + Vary: + - Accept, Accept-Language, Cookie, origin + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + djdt-store-id: + - c0a9033bed624d899af350ae5f29a8b5 + status: + code: 200 + message: OK +version: 1 diff --git a/workflows/tests/test_set_workflow_status.py b/workflows/tests/test_set_workflow_status.py new file mode 100644 index 000000000..52d42e4fa --- /dev/null +++ b/workflows/tests/test_set_workflow_status.py @@ -0,0 +1,26 @@ +import pytest +from hooks.backoffice.workflow_management_hook import AUTHORS, WorkflowManagementHook +from include.utils.set_workflow_status import set_workflow_status_to_error + + +class TestSetWorkflowStatus: + workflow_management_hook = WorkflowManagementHook(AUTHORS) + context = { + "params": { + "collection": "authors", + "workflow_id": "00000000-0000-0000-0000-000000001521", + } + } + + @pytest.mark.vcr + def test_set_workflow_status_to_error(self): + self.workflow_management_hook.set_workflow_status( + status_name="running", workflow_id=self.context["params"]["workflow_id"] + ) + set_workflow_status_to_error(context=self.context) + assert ( + self.workflow_management_hook.get_workflow( + self.context["params"]["workflow_id"] + )["status"] + == "error" + ) diff --git a/workflows/tests/test_workflow_management_hook.py b/workflows/tests/test_workflow_management_hook.py index f972f0108..8805839a0 100644 --- a/workflows/tests/test_workflow_management_hook.py +++ b/workflows/tests/test_workflow_management_hook.py @@ -5,6 +5,7 @@ class TestWorkflowManagementHook: workflow_management_hook = WorkflowManagementHook(AUTHORS) + test_workflow_id = "00000000-0000-0000-0000-000000001521" def test_collection(self): assert self.workflow_management_hook.endpoint == f"api/workflows/{AUTHORS}" @@ -14,3 +15,49 @@ def test_get_workflow_url(self): with pytest.raises(RetryError) as excinfo: self.workflow_management_hook.get_workflow("invalid_workflow_id") assert str(excinfo.value.__cause__) == "404:Not Found" + + @pytest.mark.vcr + def test_set_workflow_status(self): + self.workflow_management_hook.set_workflow_status( + status_name="error", workflow_id=self.test_workflow_id + ) + assert ( + self.workflow_management_hook.get_workflow(self.test_workflow_id)["status"] + == "error" + ) + + self.workflow_management_hook.set_workflow_status( + status_name="running", workflow_id=self.test_workflow_id + ) + assert ( + self.workflow_management_hook.get_workflow(self.test_workflow_id)["status"] + == "running" + ) + + @pytest.mark.vcr + def test_update_workflow(self): + workflow_data = self.workflow_management_hook.get_workflow( + self.test_workflow_id + ) + + workflow_data["data"]["status"] = "deceased" + self.workflow_management_hook.update_workflow( + self.test_workflow_id, workflow_data + ) + assert ( + self.workflow_management_hook.get_workflow(self.test_workflow_id)["data"][ + "status" + ] + == "deceased" + ) + + workflow_data["data"]["status"] = "departed" + self.workflow_management_hook.update_workflow( + self.test_workflow_id, workflow_data + ) + assert ( + self.workflow_management_hook.get_workflow(self.test_workflow_id)["data"][ + "status" + ] + == "departed" + )