|
18 | 18 | capture_exception, |
19 | 19 | capture_event, |
20 | 20 | set_tag, |
| 21 | + get_client, |
21 | 22 | ) |
| 23 | +from sentry_sdk.client import NonRecordingClient |
22 | 24 | from sentry_sdk.integrations.executing import ExecutingIntegration |
23 | 25 | from sentry_sdk.transport import Transport |
24 | 26 | from sentry_sdk.serializer import MAX_DATABAG_BREADTH |
@@ -1205,3 +1207,66 @@ def test_uwsgi_warnings(sentry_init, recwarn, opt, missing_flags): |
1205 | 1207 | assert flag in str(record.message) |
1206 | 1208 | else: |
1207 | 1209 | assert not recwarn |
| 1210 | + |
| 1211 | + |
| 1212 | +def test_last_event_id_non_recording(): |
| 1213 | + client = NonRecordingClient() |
| 1214 | + |
| 1215 | + assert client.last_event_id() is None |
| 1216 | + |
| 1217 | + |
| 1218 | +def test_last_event_id_nothing_sent(sentry_init): |
| 1219 | + sentry_init() |
| 1220 | + client = get_client() |
| 1221 | + |
| 1222 | + assert client.last_event_id() is None |
| 1223 | + |
| 1224 | + |
| 1225 | +def test_last_event_id_manually_set(sentry_init): |
| 1226 | + sentry_init() |
| 1227 | + client = get_client() |
| 1228 | + |
| 1229 | + client.capture_event({"event_id": "42"}) |
| 1230 | + |
| 1231 | + assert client.last_event_id() == "42" |
| 1232 | + |
| 1233 | + |
| 1234 | +def test_last_event_id_auto_generated(sentry_init): |
| 1235 | + sentry_init() |
| 1236 | + client = get_client() |
| 1237 | + |
| 1238 | + client.capture_event({}) |
| 1239 | + |
| 1240 | + # We can't predict the event ID, but it should be set |
| 1241 | + assert client.last_event_id() is not None |
| 1242 | + |
| 1243 | + |
| 1244 | +def test_last_event_id_no_transport(sentry_init): |
| 1245 | + sentry_init() |
| 1246 | + client = get_client() |
| 1247 | + client.transport = None |
| 1248 | + |
| 1249 | + client.capture_event({"event_id": "42"}) |
| 1250 | + |
| 1251 | + assert client.last_event_id() is None |
| 1252 | + |
| 1253 | + |
| 1254 | +@pytest.mark.parametrize("type", ("check_in", "transaction")) |
| 1255 | +def test_last_event_id_not_error(type, sentry_init): |
| 1256 | + sentry_init() |
| 1257 | + client = get_client() |
| 1258 | + |
| 1259 | + client.capture_event({"type": type, "event_id": "42"}) |
| 1260 | + |
| 1261 | + assert client.last_event_id() is None |
| 1262 | + |
| 1263 | + |
| 1264 | +@pytest.mark.parametrize("type", ("check_in", "transaction")) |
| 1265 | +def test_last_event_id_not_error_after_error(type, sentry_init): |
| 1266 | + sentry_init() |
| 1267 | + client = get_client() |
| 1268 | + |
| 1269 | + client.capture_event({"event_id": "error_id"}) |
| 1270 | + client.capture_event({"type": type, "event_id": "not_error_id"}) |
| 1271 | + |
| 1272 | + assert client.last_event_id() == "error_id" |
0 commit comments