From 8df67cff329a4551e8b1acd5e9ceafbaadc727c5 Mon Sep 17 00:00:00 2001 From: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Date: Fri, 19 Nov 2021 12:58:12 -0500 Subject: [PATCH] chore(sql_lab): Added Unit Test for stop query exception (#17464) * added unit test * feedback implemented --- tests/integration_tests/core_tests.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py index 3b9a3976fc14f..dd84f976c6df8 100644 --- a/tests/integration_tests/core_tests.py +++ b/tests/integration_tests/core_tests.py @@ -1547,6 +1547,28 @@ def test_dashboard_injected_exceptions(self, mock_db_connection_mutator): data = self.get_resp(url) self.assertIn("Error message", data) + @mock.patch("superset.sql_lab.cancel_query") + @mock.patch("superset.views.core.db.session") + def test_stop_query_not_implemented( + self, mock_superset_db_session, mock_sql_lab_cancel_query + ): + """ + Handles stop query when the DB engine spec does not + have a cancel query method. + """ + form_data = {"client_id": "foo"} + query_mock = mock.Mock() + query_mock.client_id = "foo" + query_mock.status = QueryStatus.RUNNING + self.login(username="admin") + mock_superset_db_session.query().filter_by().one().return_value = query_mock + mock_sql_lab_cancel_query.return_value = False + rv = self.client.post( + "/superset/stop_query/", data={"form_data": json.dumps(form_data)}, + ) + + assert rv.status_code == 422 + if __name__ == "__main__": unittest.main()