From 714129401a8ddf3f8f2c0c8f3f2e8bfef67a79e9 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Mon, 18 Mar 2024 10:05:19 +0100 Subject: [PATCH] test(gql): Remove problematic tests --- tests/integrations/gql/test_gql.py | 103 ----------------------------- 1 file changed, 103 deletions(-) diff --git a/tests/integrations/gql/test_gql.py b/tests/integrations/gql/test_gql.py index 7ae3cfe77d..f87fb974d0 100644 --- a/tests/integrations/gql/test_gql.py +++ b/tests/integrations/gql/test_gql.py @@ -5,21 +5,7 @@ from gql import Client from gql.transport.exceptions import TransportQueryError from gql.transport.requests import RequestsHTTPTransport -from graphql import DocumentNode from sentry_sdk.integrations.gql import GQLIntegration -from unittest.mock import MagicMock, patch - - -class _MockClientBase(MagicMock): - """ - Mocked version of GQL Client class, following same spec as GQL Client. - """ - - def __init__(self, *args, **kwargs): - kwargs["spec"] = Client - super().__init__(*args, **kwargs) - - transport = MagicMock() @responses.activate @@ -81,95 +67,6 @@ def test_gql_init(sentry_init): sentry_init(integrations=[GQLIntegration()]) -@patch("sentry_sdk.integrations.gql.Hub") -def test_setup_once_patches_execute_and_patched_function_calls_original(_): - """ - Unit test which ensures the following: - 1. The GQLIntegration setup_once function patches the gql.Client.execute method - 2. The patched gql.Client.execute method still calls the original method, and it - forwards its arguments to the original method. - 3. The patched gql.Client.execute method returns the same value that the original - method returns. - """ - original_method_return_value = MagicMock() - - class OriginalMockClient(_MockClientBase): - """ - This mock client always returns the mock original_method_return_value when a query - is executed. This can be used to simulate successful GraphQL queries. - """ - - execute = MagicMock( - spec=Client.execute, return_value=original_method_return_value - ) - - original_execute_method = OriginalMockClient.execute - - with patch( - "sentry_sdk.integrations.gql.gql.Client", new=OriginalMockClient - ) as PatchedMockClient: # noqa: N806 - # Below line should patch the PatchedMockClient with Sentry SDK magic - GQLIntegration.setup_once() - - # We expect GQLIntegration.setup_once to patch the execute method. - assert ( - PatchedMockClient.execute is not original_execute_method - ), "execute method not patched" - - # Now, let's instantiate a client and send it a query. Original execute still should get called. - mock_query = MagicMock(spec=DocumentNode) - client_instance = PatchedMockClient() - patched_method_return_value = client_instance.execute(mock_query) - - # Here, we check that the original execute was called - original_execute_method.assert_called_once_with(client_instance, mock_query) - - # Also, let's verify that the patched execute returns the expected value. - assert ( - patched_method_return_value is original_method_return_value - ), "pathced execute method returns a different value than the original execute method" - - -@patch("sentry_sdk.integrations.gql.event_from_exception") -@patch("sentry_sdk.integrations.gql.Hub") -def test_patched_gql_execute_captures_and_reraises_graphql_exception( - mock_hub, mock_event_from_exception -): - """ - Unit test which ensures that in the case that calling the execute method results in a - TransportQueryError (which gql raises when a GraphQL error occurs), the patched method - captures the event on the current Hub and it reraises the error. - """ - mock_event_from_exception.return_value = (dict(), MagicMock()) - - class OriginalMockClient(_MockClientBase): - """ - This mock client always raises a TransportQueryError when a GraphQL query is attempted. - This simulates a GraphQL query which results in errors. - """ - - execute = MagicMock( - spec=Client.execute, side_effect=TransportQueryError("query failed") - ) - - with patch( - "sentry_sdk.integrations.gql.gql.Client", new=OriginalMockClient - ) as PatchedMockClient: # noqa: N806 - # Below line should patch the PatchedMockClient with Sentry SDK magic - GQLIntegration.setup_once() - - mock_query = MagicMock(spec=DocumentNode) - client_instance = PatchedMockClient() - - # The error should still get raised even though we have instrumented the execute method. - with pytest.raises(TransportQueryError): - client_instance.execute(mock_query) - - # However, we should have also captured the error on the hub. - mock_capture_event = mock_hub.current.capture_event - mock_capture_event.assert_called_once() - - def test_real_gql_request_no_error(sentry_init, capture_events): """ Integration test verifying that the GQLIntegration works as expected with successful query.