diff --git a/backoffice/backoffice/workflows/api/views.py b/backoffice/backoffice/workflows/api/views.py index 1f6f5dc3..140225f9 100644 --- a/backoffice/backoffice/workflows/api/views.py +++ b/backoffice/backoffice/workflows/api/views.py @@ -53,11 +53,7 @@ def get_queryset(self): return self.queryset def perform_destroy(self, instance): - print("stuff should happen now") - airflow_utils.delete_workflow_dag_runs( - instance.workflow_id, instance.workflow_type - ) - print("stuff has happened") + airflow_utils.delete_workflow_dag_runs(instance.id, instance.workflow_type) super().perform_destroy(instance) diff --git a/backoffice/backoffice/workflows/tests/cassettes/TestAirflowUtils.test_delete_workflow_dag_runs.yaml b/backoffice/backoffice/workflows/tests/cassettes/TestAirflowUtils.test_delete_workflow_dag_runs.yaml new file mode 100644 index 00000000..f997984a --- /dev/null +++ b/backoffice/backoffice/workflows/tests/cassettes/TestAirflowUtils.test_delete_workflow_dag_runs.yaml @@ -0,0 +1,209 @@ +interactions: +- request: + body: '{"dag_run_id": "00000000-0000-0000-0000-000000000001", "conf": {"workflow_id": + "00000000-0000-0000-0000-000000000001"}}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '119' + Content-Type: + - application/json + method: POST + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns + response: + body: + string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000001\"\n + \ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\": + \"00000000-0000-0000-0000-000000000001\",\n \"data_interval_end\": \"2024-08-19T11:39:24.438383+00:00\",\n + \ \"data_interval_start\": \"2024-08-19T11:39:24.438383+00:00\",\n \"end_date\": + null,\n \"execution_date\": \"2024-08-19T11:39:24.438383+00:00\",\n \"external_trigger\": + true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T11:39:24.438383+00:00\",\n + \ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n + \ \"state\": \"queued\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '579' + Content-Type: + - application/json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000001 + response: + body: + string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000001\"\n + \ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\": + \"00000000-0000-0000-0000-000000000001\",\n \"data_interval_end\": \"2024-08-19T11:39:24.438383+00:00\",\n + \ \"data_interval_start\": \"2024-08-19T11:39:24.438383+00:00\",\n \"end_date\": + null,\n \"execution_date\": \"2024-08-19T11:39:24.438383+00:00\",\n \"external_trigger\": + true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T11:39:24.438383+00:00\",\n + \ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n + \ \"state\": \"queued\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '579' + Content-Type: + - application/json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/00000000-0000-0000-0000-000000000001 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_approved_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000001' not found\",\n \"status\": + 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '294' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/00000000-0000-0000-0000-000000000001 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_rejected_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000001' not found\",\n \"status\": + 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '294' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + method: DELETE + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000001 + response: + body: + string: '' + headers: + Connection: + - close + Content-Type: + - application/json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 204 + message: NO CONTENT +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + method: DELETE + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000001 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_initialization_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000001' not found\",\n \"status\": + 404,\n \"title\": \"Not Found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '293' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 11:39:24 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +version: 1 diff --git a/backoffice/backoffice/workflows/tests/cassettes/TestWorkflowViewSet.test_destroy.yaml b/backoffice/backoffice/workflows/tests/cassettes/TestWorkflowViewSet.test_destroy.yaml index ddcb915f..73499d6f 100644 --- a/backoffice/backoffice/workflows/tests/cassettes/TestWorkflowViewSet.test_destroy.yaml +++ b/backoffice/backoffice/workflows/tests/cassettes/TestWorkflowViewSet.test_destroy.yaml @@ -1,7 +1,7 @@ interactions: - request: - body: '{"dag_run_id": "cef38eb0-f950-43dd-a771-525fda714491", "conf": {"workflow_id": - "cef38eb0-f950-43dd-a771-525fda714491", "data": {}}}' + body: '{"dag_run_id": "00000000-0000-0000-0000-000000000002", "conf": {"workflow_id": + "00000000-0000-0000-0000-000000000002"}}' headers: Accept: - '*/*' @@ -10,30 +10,30 @@ interactions: Connection: - keep-alive Content-Length: - - '131' + - '119' Content-Type: - application/json method: POST uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns response: body: - string: "{\n \"conf\": {\n \"data\": {},\n \"workflow_id\": \"cef38eb0-f950-43dd-a771-525fda714491\"\n + string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000002\"\n \ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\": - \"cef38eb0-f950-43dd-a771-525fda714491\",\n \"data_interval_end\": \"2024-08-19T08:55:53.292606+00:00\",\n - \ \"data_interval_start\": \"2024-08-19T08:55:53.292606+00:00\",\n \"end_date\": - null,\n \"execution_date\": \"2024-08-19T08:55:53.292606+00:00\",\n \"external_trigger\": - true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T08:55:53.292606+00:00\",\n + \"00000000-0000-0000-0000-000000000002\",\n \"data_interval_end\": \"2024-08-19T13:16:38.257736+00:00\",\n + \ \"data_interval_start\": \"2024-08-19T13:16:38.257736+00:00\",\n \"end_date\": + null,\n \"execution_date\": \"2024-08-19T13:16:38.257736+00:00\",\n \"external_trigger\": + true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T13:16:38.257736+00:00\",\n \ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n \ \"state\": \"queued\"\n}\n" headers: Connection: - close Content-Length: - - '595' + - '579' Content-Type: - application/json Date: - - Mon, 19 Aug 2024 08:55:53 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -51,27 +51,26 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: - string: "{\n \"conf\": {\n \"data\": {},\n \"workflow_id\": \"cef38eb0-f950-43dd-a771-525fda714491\"\n + string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000002\"\n \ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\": - \"cef38eb0-f950-43dd-a771-525fda714491\",\n \"data_interval_end\": \"2024-08-19T08:55:53.292606+00:00\",\n - \ \"data_interval_start\": \"2024-08-19T08:55:53.292606+00:00\",\n \"end_date\": - null,\n \"execution_date\": \"2024-08-19T08:55:53.292606+00:00\",\n \"external_trigger\": - true,\n \"last_scheduling_decision\": \"2024-08-19T08:56:02.944297+00:00\",\n - \ \"logical_date\": \"2024-08-19T08:55:53.292606+00:00\",\n \"note\": null,\n - \ \"run_type\": \"manual\",\n \"start_date\": \"2024-08-19T08:55:53.863497+00:00\",\n - \ \"state\": \"running\"\n}\n" + \"00000000-0000-0000-0000-000000000002\",\n \"data_interval_end\": \"2024-08-19T13:16:38.257736+00:00\",\n + \ \"data_interval_start\": \"2024-08-19T13:16:38.257736+00:00\",\n \"end_date\": + null,\n \"execution_date\": \"2024-08-19T13:16:38.257736+00:00\",\n \"external_trigger\": + true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T13:16:38.257736+00:00\",\n + \ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n + \ \"state\": \"queued\"\n}\n" headers: Connection: - close Content-Length: - - '656' + - '579' Content-Type: - application/json Date: - - Mon, 19 Aug 2024 08:56:03 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -89,11 +88,11 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_approved_dag' - and DagRun ID: 'cef38eb0-f950-43dd-a771-525fda714491' not found\",\n \"status\": + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" headers: Connection: @@ -103,7 +102,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 19 Aug 2024 08:56:03 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -121,11 +120,11 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_rejected_dag' - and DagRun ID: 'cef38eb0-f950-43dd-a771-525fda714491' not found\",\n \"status\": + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" headers: Connection: @@ -135,7 +134,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 19 Aug 2024 08:56:03 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -153,27 +152,26 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: - string: "{\n \"conf\": {\n \"data\": {},\n \"workflow_id\": \"cef38eb0-f950-43dd-a771-525fda714491\"\n + string: "{\n \"conf\": {\n \"workflow_id\": \"00000000-0000-0000-0000-000000000002\"\n \ },\n \"dag_id\": \"author_create_initialization_dag\",\n \"dag_run_id\": - \"cef38eb0-f950-43dd-a771-525fda714491\",\n \"data_interval_end\": \"2024-08-19T08:55:53.292606+00:00\",\n - \ \"data_interval_start\": \"2024-08-19T08:55:53.292606+00:00\",\n \"end_date\": - \"2024-08-19T08:56:11.955315+00:00\",\n \"execution_date\": \"2024-08-19T08:55:53.292606+00:00\",\n - \ \"external_trigger\": true,\n \"last_scheduling_decision\": \"2024-08-19T08:56:11.953434+00:00\",\n - \ \"logical_date\": \"2024-08-19T08:55:53.292606+00:00\",\n \"note\": null,\n - \ \"run_type\": \"manual\",\n \"start_date\": \"2024-08-19T08:55:53.863497+00:00\",\n - \ \"state\": \"failed\"\n}\n" + \"00000000-0000-0000-0000-000000000002\",\n \"data_interval_end\": \"2024-08-19T13:16:38.257736+00:00\",\n + \ \"data_interval_start\": \"2024-08-19T13:16:38.257736+00:00\",\n \"end_date\": + null,\n \"execution_date\": \"2024-08-19T13:16:38.257736+00:00\",\n \"external_trigger\": + true,\n \"last_scheduling_decision\": null,\n \"logical_date\": \"2024-08-19T13:16:38.257736+00:00\",\n + \ \"note\": null,\n \"run_type\": \"manual\",\n \"start_date\": null,\n + \ \"state\": \"queued\"\n}\n" headers: Connection: - close Content-Length: - - '685' + - '579' Content-Type: - application/json Date: - - Mon, 19 Aug 2024 08:56:23 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -191,11 +189,137 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/00000000-0000-0000-0000-000000000002 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_approved_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": + 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '294' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 13:16:38 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/00000000-0000-0000-0000-000000000002 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_rejected_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": + 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '294' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 13:16:38 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + Content-Length: + - '0' + method: DELETE + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000002 + response: + body: + string: '' + headers: + Connection: + - close + Content-Type: + - application/json + Date: + - Mon, 19 Aug 2024 13:16:38 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 204 + message: NO CONTENT +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_initialization_dag/dagRuns/00000000-0000-0000-0000-000000000002 + response: + body: + string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_initialization_dag' + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": + 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" + headers: + Connection: + - close + Content-Length: + - '300' + Content-Type: + - application/problem+json + Date: + - Mon, 19 Aug 2024 13:16:38 GMT + Server: + - gunicorn + X-Robots-Tag: + - noindex, nofollow + status: + code: 404 + message: NOT FOUND +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + method: GET + uri: http://airflow-webserver:8080/api/v1/dags/author_create_approved_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_approved_dag' - and DagRun ID: 'cef38eb0-f950-43dd-a771-525fda714491' not found\",\n \"status\": + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" headers: Connection: @@ -205,7 +329,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 19 Aug 2024 08:56:23 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: @@ -223,11 +347,11 @@ interactions: Connection: - keep-alive method: GET - uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/cef38eb0-f950-43dd-a771-525fda714491 + uri: http://airflow-webserver:8080/api/v1/dags/author_create_rejected_dag/dagRuns/00000000-0000-0000-0000-000000000002 response: body: string: "{\n \"detail\": \"DAGRun with DAG ID: 'author_create_rejected_dag' - and DagRun ID: 'cef38eb0-f950-43dd-a771-525fda714491' not found\",\n \"status\": + and DagRun ID: '00000000-0000-0000-0000-000000000002' not found\",\n \"status\": 404,\n \"title\": \"DAGRun not found\",\n \"type\": \"https://airflow.apache.org/docs/apache-airflow/2.8.3/stable-rest-api-ref.html#section/Errors/NotFound\"\n}\n" headers: Connection: @@ -237,7 +361,7 @@ interactions: Content-Type: - application/problem+json Date: - - Mon, 19 Aug 2024 08:56:23 GMT + - Mon, 19 Aug 2024 13:16:38 GMT Server: - gunicorn X-Robots-Tag: diff --git a/backoffice/backoffice/workflows/tests/test_airflow_utils.py b/backoffice/backoffice/workflows/tests/test_airflow_utils.py index 2d508c0b..eb64b541 100644 --- a/backoffice/backoffice/workflows/tests/test_airflow_utils.py +++ b/backoffice/backoffice/workflows/tests/test_airflow_utils.py @@ -64,3 +64,10 @@ def test_restart_workflow_dags(self): self.workflow_id, self.workflow_type ) self.assertEqual(response.status_code, 200) + + @pytest.mark.vcr() + def test_delete_workflow_dag_runs(self): + response = airflow_utils.delete_workflow_dag_runs( + self.workflow_id, self.workflow_type + ) + self.assertEqual(response.status_code, 200) diff --git a/backoffice/backoffice/workflows/tests/test_views.py b/backoffice/backoffice/workflows/tests/test_views.py index c879a91c..214ee07b 100644 --- a/backoffice/backoffice/workflows/tests/test_views.py +++ b/backoffice/backoffice/workflows/tests/test_views.py @@ -15,7 +15,12 @@ from backoffice.workflows import airflow_utils from backoffice.workflows.api.serializers import WorkflowTicketSerializer -from backoffice.workflows.constants import WORKFLOW_DAGS, StatusChoices, WorkflowType +from backoffice.workflows.constants import ( + WORKFLOW_DAGS, + AuthorCreateDags, + StatusChoices, + WorkflowType, +) from backoffice.workflows.models import WorkflowTicket User = get_user_model() @@ -52,7 +57,12 @@ class TestWorkflowViewSet(BaseTransactionTestCase): def setUp(self): super().setUp() self.workflow = Workflow.objects.create( - data={}, status=StatusChoices.APPROVAL, core=True, is_update=False + data={}, + status=StatusChoices.APPROVAL, + core=True, + is_update=False, + workflow_type=WorkflowType.AUTHOR_CREATE, + id=uuid.UUID(int=2), ) def test_list_curator(self): @@ -75,45 +85,25 @@ def test_list_anonymous(self): self.assertEqual(response.status_code, 403) - # @pytest.mark.vcr() + @pytest.mark.vcr() def test_destroy(self): self.api_client.force_authenticate(user=self.curator) - workflow_type = WorkflowType.AUTHOR_CREATE - url = reverse("api:workflows-authors-list") - response = self.api_client.post( - url, - format="json", - data={ - "workflow_type": workflow_type, - "status": "running", - "data": {}, - }, + airflow_utils.trigger_airflow_dag( + AuthorCreateDags.initialize, str(self.workflow.id) ) - json_response = response.json()["conf"] - import time - - time.sleep(10) - - # import ipdb; ipdb.set_trace() - assert ( - airflow_utils.find_executed_dags( - json_response["workflow_id"], workflow_type - ) - is not None + assert airflow_utils.find_executed_dags( + self.workflow.id, self.workflow.workflow_type ) - import time - time.sleep(10) - self.workflow.delete() - import time + url = reverse("api:workflows-detail", kwargs={"pk": self.workflow.id}) + response = self.api_client.delete(url) - time.sleep(10) - # import ipdb; ipdb.set_trace() + self.assertEqual(response.status_code, 204) assert ( airflow_utils.find_executed_dags( - json_response["workflow_id"], workflow_type + self.workflow.id, self.workflow.workflow_type ) - is None + == {} )