|
1 | 1 | import pytest
|
| 2 | +import json |
2 | 3 |
|
3 | 4 | from werkzeug.test import Client
|
4 | 5 | from django.contrib.auth.models import User
|
@@ -389,3 +390,68 @@ def test_template_exception(sentry_init, client, capture_events):
|
389 | 390 | (None, None),
|
390 | 391 | (u"invalid_block_tag", u"django.template.base"),
|
391 | 392 | ]
|
| 393 | + |
| 394 | + |
| 395 | +@pytest.mark.parametrize( |
| 396 | + "type,event_request", |
| 397 | + [ |
| 398 | + [ |
| 399 | + "json", |
| 400 | + { |
| 401 | + "cookies": {}, |
| 402 | + "data": {"foo": "bar"}, |
| 403 | + "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"}, |
| 404 | + "headers": { |
| 405 | + "Content-Length": "14", |
| 406 | + "Content-Type": "application/json", |
| 407 | + "Host": "localhost", |
| 408 | + }, |
| 409 | + "method": "POST", |
| 410 | + "query_string": "", |
| 411 | + "url": "http://localhost/rest-framework-exc", |
| 412 | + }, |
| 413 | + ], |
| 414 | + [ |
| 415 | + "formdata", |
| 416 | + { |
| 417 | + "cookies": {}, |
| 418 | + "data": {"foo": "bar"}, |
| 419 | + "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"}, |
| 420 | + "headers": { |
| 421 | + "Content-Length": "7", |
| 422 | + "Content-Type": "application/x-www-form-urlencoded", |
| 423 | + "Host": "localhost", |
| 424 | + }, |
| 425 | + "method": "POST", |
| 426 | + "query_string": "", |
| 427 | + "url": "http://localhost/rest-framework-exc", |
| 428 | + }, |
| 429 | + ], |
| 430 | + ], |
| 431 | +) |
| 432 | +def test_rest_framework_basic( |
| 433 | + sentry_init, client, capture_events, capture_exceptions, type, event_request |
| 434 | +): |
| 435 | + pytest.importorskip("rest_framework") |
| 436 | + sentry_init(integrations=[DjangoIntegration()], send_default_pii=True) |
| 437 | + exceptions = capture_exceptions() |
| 438 | + events = capture_events() |
| 439 | + |
| 440 | + if type == "json": |
| 441 | + client.post( |
| 442 | + reverse("rest_framework_exc"), |
| 443 | + data=json.dumps({"foo": "bar"}), |
| 444 | + content_type="application/json", |
| 445 | + ) |
| 446 | + elif type == "formdata": |
| 447 | + client.post(reverse("rest_framework_exc"), data={"foo": "bar"}) |
| 448 | + else: |
| 449 | + assert False |
| 450 | + |
| 451 | + error, = exceptions |
| 452 | + assert isinstance(error, ZeroDivisionError) |
| 453 | + |
| 454 | + event, = events |
| 455 | + assert event["exception"]["values"][0]["mechanism"]["type"] == "django" |
| 456 | + |
| 457 | + assert event["request"] == event_request |
0 commit comments