File tree 2 files changed +35
-0
lines changed
sentry_sdk/integrations/django
tests/integrations/django
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ def sentry_wrapped_method(*args, **kwargs):
125
125
class SentryWrappingMiddleware (
126
126
_asgi_middleware_mixin_factory (_check_middleware_span ) # type: ignore
127
127
):
128
+ sync_capable = getattr (middleware , "sync_capable" , True )
128
129
async_capable = DJANGO_SUPPORTS_ASYNC_MIDDLEWARE and getattr (
129
130
middleware , "async_capable" , False
130
131
)
Original file line number Diff line number Diff line change
1
+ from typing import Optional
2
+
3
+ import pytest
4
+
5
+ from sentry_sdk .integrations .django .middleware import _wrap_middleware
6
+
7
+
8
+ def _sync_capable_middleware_factory (sync_capable ):
9
+ # type: (Optional[bool]) -> type
10
+ """Create a middleware class with a sync_capable attribute set to the value passed to the factory.
11
+ If the factory is called with None, the middleware class will not have a sync_capable attribute.
12
+ """
13
+ sc = sync_capable # rename so we can set sync_capable in the class
14
+
15
+ class TestMiddleware :
16
+ nonlocal sc
17
+ if sc is not None :
18
+ sync_capable = sc
19
+
20
+ return TestMiddleware
21
+
22
+
23
+ @pytest .mark .parametrize (
24
+ ("middleware" , "sync_capable" ),
25
+ (
26
+ (_sync_capable_middleware_factory (True ), True ),
27
+ (_sync_capable_middleware_factory (False ), False ),
28
+ (_sync_capable_middleware_factory (None ), True ),
29
+ ),
30
+ )
31
+ def test_wrap_middleware_sync_capable_attribute (middleware , sync_capable ):
32
+ wrapped_middleware = _wrap_middleware (middleware , "test_middleware" )
33
+
34
+ assert wrapped_middleware .sync_capable is sync_capable
You can’t perform that action at this time.
0 commit comments