Skip to content

Commit cee64e0

Browse files
test(gql): Remove problematic tests (getsentry#2835)
These two tests are failing in getsentry#2454, blocking that PR from being merged. The tests appear to be broken, and since they appear to be unnecessary (we don't have similar tests for other integrations), we should delete them. See getsentry#2454 for a more detailed explanation.
1 parent a1181a6 commit cee64e0

1 file changed

Lines changed: 0 additions & 103 deletions

File tree

tests/integrations/gql/test_gql.py

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,7 @@
55
from gql import Client
66
from gql.transport.exceptions import TransportQueryError
77
from gql.transport.requests import RequestsHTTPTransport
8-
from graphql import DocumentNode
98
from sentry_sdk.integrations.gql import GQLIntegration
10-
from unittest.mock import MagicMock, patch
11-
12-
13-
class _MockClientBase(MagicMock):
14-
"""
15-
Mocked version of GQL Client class, following same spec as GQL Client.
16-
"""
17-
18-
def __init__(self, *args, **kwargs):
19-
kwargs["spec"] = Client
20-
super().__init__(*args, **kwargs)
21-
22-
transport = MagicMock()
239

2410

2511
@responses.activate
@@ -81,95 +67,6 @@ def test_gql_init(sentry_init):
8167
sentry_init(integrations=[GQLIntegration()])
8268

8369

84-
@patch("sentry_sdk.integrations.gql.Hub")
85-
def test_setup_once_patches_execute_and_patched_function_calls_original(_):
86-
"""
87-
Unit test which ensures the following:
88-
1. The GQLIntegration setup_once function patches the gql.Client.execute method
89-
2. The patched gql.Client.execute method still calls the original method, and it
90-
forwards its arguments to the original method.
91-
3. The patched gql.Client.execute method returns the same value that the original
92-
method returns.
93-
"""
94-
original_method_return_value = MagicMock()
95-
96-
class OriginalMockClient(_MockClientBase):
97-
"""
98-
This mock client always returns the mock original_method_return_value when a query
99-
is executed. This can be used to simulate successful GraphQL queries.
100-
"""
101-
102-
execute = MagicMock(
103-
spec=Client.execute, return_value=original_method_return_value
104-
)
105-
106-
original_execute_method = OriginalMockClient.execute
107-
108-
with patch(
109-
"sentry_sdk.integrations.gql.gql.Client", new=OriginalMockClient
110-
) as PatchedMockClient: # noqa: N806
111-
# Below line should patch the PatchedMockClient with Sentry SDK magic
112-
GQLIntegration.setup_once()
113-
114-
# We expect GQLIntegration.setup_once to patch the execute method.
115-
assert (
116-
PatchedMockClient.execute is not original_execute_method
117-
), "execute method not patched"
118-
119-
# Now, let's instantiate a client and send it a query. Original execute still should get called.
120-
mock_query = MagicMock(spec=DocumentNode)
121-
client_instance = PatchedMockClient()
122-
patched_method_return_value = client_instance.execute(mock_query)
123-
124-
# Here, we check that the original execute was called
125-
original_execute_method.assert_called_once_with(client_instance, mock_query)
126-
127-
# Also, let's verify that the patched execute returns the expected value.
128-
assert (
129-
patched_method_return_value is original_method_return_value
130-
), "pathced execute method returns a different value than the original execute method"
131-
132-
133-
@patch("sentry_sdk.integrations.gql.event_from_exception")
134-
@patch("sentry_sdk.integrations.gql.Hub")
135-
def test_patched_gql_execute_captures_and_reraises_graphql_exception(
136-
mock_hub, mock_event_from_exception
137-
):
138-
"""
139-
Unit test which ensures that in the case that calling the execute method results in a
140-
TransportQueryError (which gql raises when a GraphQL error occurs), the patched method
141-
captures the event on the current Hub and it reraises the error.
142-
"""
143-
mock_event_from_exception.return_value = (dict(), MagicMock())
144-
145-
class OriginalMockClient(_MockClientBase):
146-
"""
147-
This mock client always raises a TransportQueryError when a GraphQL query is attempted.
148-
This simulates a GraphQL query which results in errors.
149-
"""
150-
151-
execute = MagicMock(
152-
spec=Client.execute, side_effect=TransportQueryError("query failed")
153-
)
154-
155-
with patch(
156-
"sentry_sdk.integrations.gql.gql.Client", new=OriginalMockClient
157-
) as PatchedMockClient: # noqa: N806
158-
# Below line should patch the PatchedMockClient with Sentry SDK magic
159-
GQLIntegration.setup_once()
160-
161-
mock_query = MagicMock(spec=DocumentNode)
162-
client_instance = PatchedMockClient()
163-
164-
# The error should still get raised even though we have instrumented the execute method.
165-
with pytest.raises(TransportQueryError):
166-
client_instance.execute(mock_query)
167-
168-
# However, we should have also captured the error on the hub.
169-
mock_capture_event = mock_hub.current.capture_event
170-
mock_capture_event.assert_called_once()
171-
172-
17370
def test_real_gql_request_no_error(sentry_init, capture_events):
17471
"""
17572
Integration test verifying that the GQLIntegration works as expected with successful query.

0 commit comments

Comments
 (0)