-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(django): Add `sync_capable` to `SentryWrappingMiddleware` Fixes #3506 * test(django): Test that `sync_capable` set on wrapped middleware
- Loading branch information
1 parent
53897ff
commit a581542
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
|
||
from sentry_sdk.integrations.django.middleware import _wrap_middleware | ||
|
||
|
||
def _sync_capable_middleware_factory(sync_capable): | ||
# type: (Optional[bool]) -> type | ||
"""Create a middleware class with a sync_capable attribute set to the value passed to the factory. | ||
If the factory is called with None, the middleware class will not have a sync_capable attribute. | ||
""" | ||
sc = sync_capable # rename so we can set sync_capable in the class | ||
|
||
class TestMiddleware: | ||
nonlocal sc | ||
if sc is not None: | ||
sync_capable = sc | ||
|
||
return TestMiddleware | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("middleware", "sync_capable"), | ||
( | ||
(_sync_capable_middleware_factory(True), True), | ||
(_sync_capable_middleware_factory(False), False), | ||
(_sync_capable_middleware_factory(None), True), | ||
), | ||
) | ||
def test_wrap_middleware_sync_capable_attribute(middleware, sync_capable): | ||
wrapped_middleware = _wrap_middleware(middleware, "test_middleware") | ||
|
||
assert wrapped_middleware.sync_capable is sync_capable |