-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test additional variant payload types and split up to 1 file per method
- Loading branch information
Showing
2 changed files
with
59 additions
and
37 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
43 changes: 43 additions & 0 deletions
43
tests/integrations/unleash/test_unleash_is_enabled_method.py
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,43 @@ | ||
import pytest | ||
from unittest.mock import Mock | ||
|
||
import sentry_sdk | ||
from sentry_sdk.integrations.unleash import UnleashIntegration | ||
|
||
|
||
@pytest.fixture | ||
def mock_unleash_client(): | ||
features = { | ||
"hello": True, | ||
"world": False, | ||
} | ||
|
||
def is_enabled(feature: str, *a, **kw) -> bool: | ||
return features.get(feature, False) | ||
|
||
client = Mock() | ||
client.is_enabled = is_enabled | ||
return client | ||
|
||
|
||
def test_is_enabled( | ||
sentry_init, capture_events, uninstall_integration, mock_unleash_client | ||
): | ||
uninstall_integration(UnleashIntegration.identifier) | ||
sentry_init(integrations=[UnleashIntegration(mock_unleash_client)]) | ||
|
||
mock_unleash_client.is_enabled("hello") | ||
mock_unleash_client.is_enabled("world") | ||
mock_unleash_client.is_enabled("other") | ||
|
||
events = capture_events() | ||
sentry_sdk.capture_exception(Exception("something wrong!")) | ||
|
||
assert len(events) == 1 | ||
assert events[0]["contexts"]["flags"] == { | ||
"values": [ | ||
{"flag": "hello", "result": True}, | ||
{"flag": "world", "result": False}, | ||
{"flag": "other", "result": False}, | ||
] | ||
} |