-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c0687c
commit 56dfcd4
Showing
3 changed files
with
57 additions
and
24 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
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 |
---|---|---|
@@ -1,18 +1,56 @@ | ||
import pytest | ||
|
||
from sentry_sdk import Client | ||
from sentry_sdk import Hub, capture_exception | ||
|
||
|
||
def test_send_to_spotlight(make_client): | ||
client = make_client( | ||
spotlight=False, | ||
) | ||
assert client.spotlight is None | ||
@pytest.fixture | ||
def capture_spotlight_envelopes(monkeypatch): | ||
def inner(): | ||
envelopes = [] | ||
test_spotlight = Hub.current.client.spotlight | ||
old_capture_envelope = test_spotlight.capture_envelope | ||
|
||
def append_envelope(envelope): | ||
envelopes.append(envelope) | ||
return old_capture_envelope(envelope) | ||
|
||
@pytest.fixture | ||
def make_client(request): | ||
def inner(**kwargs): | ||
return Client("http://foobar@test.com/132", **kwargs) | ||
monkeypatch.setattr(test_spotlight, "capture_envelope", append_envelope) | ||
return envelopes | ||
|
||
return inner | ||
|
||
|
||
def test_spotlight_off_by_default(sentry_init): | ||
sentry_init() | ||
assert Hub.current.client.spotlight is None | ||
|
||
|
||
def test_spotlight_default_url(sentry_init): | ||
sentry_init(spotlight=True) | ||
|
||
spotlight = Hub.current.client.spotlight | ||
assert spotlight is not None | ||
assert spotlight.url == "http://localhost:8969/stream" | ||
|
||
|
||
def test_spotlight_custom_url(sentry_init): | ||
sentry_init(spotlight="http://foobar@test.com/132") | ||
|
||
spotlight = Hub.current.client.spotlight | ||
assert spotlight is not None | ||
assert spotlight.url == "http://foobar@test.com/132" | ||
|
||
|
||
def test_spotlight_envelope(sentry_init, capture_spotlight_envelopes): | ||
sentry_init(spotlight=True) | ||
envelopes = capture_spotlight_envelopes() | ||
|
||
try: | ||
raise ValueError("aha!") | ||
except Exception: | ||
capture_exception() | ||
|
||
(envelope,) = envelopes | ||
payload = envelope.items[0].payload.json | ||
|
||
assert payload["exception"]["values"][0]["value"] == "aha!" |