betodealmeida commented on a change in pull request #17464:
URL: https://github.com/apache/superset/pull/17464#discussion_r751468466



##########
File path: tests/integration_tests/core_tests.py
##########
@@ -1548,6 +1548,30 @@ 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")
+    def test_stop_query_no_cancel_query(self, 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.sql = "SELECT *"
+        query_mock.database = 1
+        query_mock.schema = "superset"
+        query_mock.client_id = "foo"
+        query_mock.status = QueryStatus.RUNNING
+        self.login(username="admin")
+
+        with mock.patch("superset.views.core.db") as mock_superset_db:
+            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)},
+            )
+
+        self.assertEqual(rv.status_code, 422)

Review comment:
       Since me started using pylint naked asserts are preferred:
   
   ```suggestion
           assert rv.status_code == 422
   ```

##########
File path: tests/integration_tests/core_tests.py
##########
@@ -1548,6 +1548,30 @@ 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")
+    def test_stop_query_no_cancel_query(self, 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.sql = "SELECT *"
+        query_mock.database = 1
+        query_mock.schema = "superset"
+        query_mock.client_id = "foo"
+        query_mock.status = QueryStatus.RUNNING
+        self.login(username="admin")
+
+        with mock.patch("superset.views.core.db") as mock_superset_db:
+            mock_superset_db.session.query().filter_by().one().return_value = 
query_mock

Review comment:
       Oh, I didn't know you could use `()` instead of `return_value`. Nice!

##########
File path: tests/integration_tests/core_tests.py
##########
@@ -1548,6 +1548,30 @@ 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")
+    def test_stop_query_no_cancel_query(self, 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.sql = "SELECT *"
+        query_mock.database = 1
+        query_mock.schema = "superset"
+        query_mock.client_id = "foo"

Review comment:
       Do we need to mock these attributes?

##########
File path: tests/integration_tests/core_tests.py
##########
@@ -1548,6 +1548,30 @@ 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")
+    def test_stop_query_no_cancel_query(self, 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.sql = "SELECT *"
+        query_mock.database = 1
+        query_mock.schema = "superset"
+        query_mock.client_id = "foo"
+        query_mock.status = QueryStatus.RUNNING
+        self.login(username="admin")
+
+        with mock.patch("superset.views.core.db") as mock_superset_db:

Review comment:
       Why not also patch the method with a decorator, like you did for 
`cancel_query`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to