Skip to content

Commit 68c3a64

Browse files
committed
test: Add test for getsentry#524
1 parent 9ccc7e0 commit 68c3a64

File tree

1 file changed

+12
-41
lines changed

1 file changed

+12
-41
lines changed

tests/integrations/django/test_basic.py

+12-41
Original file line numberDiff line numberDiff line change
@@ -433,58 +433,28 @@ def test_template_exception(sentry_init, client, capture_events):
433433
"route", ["rest_framework_exc", "rest_framework_read_body_and_exc"]
434434
)
435435
@pytest.mark.parametrize(
436-
"type,event_request",
436+
"ct,body",
437437
[
438-
[
439-
"json",
440-
lambda route: {
441-
"cookies": {},
442-
"data": {"foo": "bar"},
443-
"env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
444-
"headers": {
445-
"Content-Length": "14",
446-
"Content-Type": "application/json",
447-
"Host": "localhost",
448-
},
449-
"method": "POST",
450-
"query_string": "",
451-
"url": "http://localhost/{}".format(route.replace("_", "-")),
452-
},
453-
],
454-
[
455-
"formdata",
456-
lambda route: {
457-
"cookies": {},
458-
"data": {"foo": "bar"},
459-
"env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
460-
"headers": {
461-
"Content-Length": "7",
462-
"Content-Type": "application/x-www-form-urlencoded",
463-
"Host": "localhost",
464-
},
465-
"method": "POST",
466-
"query_string": "",
467-
"url": "http://localhost/{}".format(route.replace("_", "-")),
468-
},
469-
],
438+
["application/json", {"foo": "bar"}],
439+
["application/json", 1],
440+
["application/json", "foo"],
441+
["application/x-www-form-urlencoded", {"foo": "bar"}],
470442
],
471443
)
472444
def test_rest_framework_basic(
473-
sentry_init, client, capture_events, capture_exceptions, type, event_request, route
445+
sentry_init, client, capture_events, capture_exceptions, ct, body, route
474446
):
475447
pytest.importorskip("rest_framework")
476448
sentry_init(integrations=[DjangoIntegration()], send_default_pii=True)
477449
exceptions = capture_exceptions()
478450
events = capture_events()
479451

480-
if type == "json":
452+
if ct == "application/json":
481453
client.post(
482-
reverse(route),
483-
data=json.dumps({"foo": "bar"}),
484-
content_type="application/json",
454+
reverse(route), data=json.dumps(body), content_type="application/json"
485455
)
486-
elif type == "formdata":
487-
client.post(reverse(route), data={"foo": "bar"})
456+
elif ct == "application/x-www-form-urlencoded":
457+
client.post(reverse(route), data=body)
488458
else:
489459
assert False
490460

@@ -494,7 +464,8 @@ def test_rest_framework_basic(
494464
event, = events
495465
assert event["exception"]["values"][0]["mechanism"]["type"] == "django"
496466

497-
assert event["request"] == event_request(route)
467+
assert event["request"]["data"] == body
468+
assert event["request"]["headers"]["Content-Type"] == ct
498469

499470

500471
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)