Skip to content

Commit e684644

Browse files
committed
ref(tests): Refactor test cases
1 parent 97dd890 commit e684644

12 files changed

Lines changed: 118 additions & 75 deletions

File tree

‎tests/integrations/django/asgi/test_asgi.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sentry_sdk.integrations.django.asgi import _asgi_middleware_mixin_factory
1717
from tests.integrations.django.myapp.asgi import channels_application
1818
from tests.integrations.django.utils import pytest_mark_django_db_decorator
19-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
19+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
2020

2121
try:
2222
from django.urls import reverse
@@ -941,7 +941,9 @@ async def test_async_middleware_process_exception_is_awaited(
941941
@pytest.mark.skipif(
942942
django.VERSION < (3, 0), reason="Django ASGI support shipped in 3.0"
943943
)
944-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
944+
@pytest.mark.parametrize(
945+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
946+
)
945947
@pytest_mark_django_db_decorator()
946948
async def test_user_identity_error_event_data_collection(
947949
sentry_init, capture_events, application, init_kwargs, expect_user

‎tests/integrations/django/test_data_scrubbing.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tests.conftest import unpack_werkzeug_response, werkzeug_set_cookie
88
from tests.integrations.django.myapp.wsgi import application
99
from tests.integrations.django.utils import pytest_mark_django_db_decorator
10-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
10+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
1111

1212
try:
1313
from django.urls import reverse
@@ -370,7 +370,9 @@ def test_empty_query_string_is_dropped_with_data_collection(
370370

371371
@pytest.mark.forked
372372
@pytest_mark_django_db_decorator()
373-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
373+
@pytest.mark.parametrize(
374+
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
375+
)
374376
def test_user_info_span_attributes_data_collection(
375377
sentry_init, client, capture_items, init_kwargs, expect_ip
376378
):
@@ -401,7 +403,9 @@ def test_user_info_span_attributes_data_collection(
401403

402404
@pytest.mark.forked
403405
@pytest_mark_django_db_decorator()
404-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
406+
@pytest.mark.parametrize(
407+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
408+
)
405409
def test_user_identity_span_attributes_data_collection(
406410
sentry_init, client, capture_items, init_kwargs, expect_user
407411
):
@@ -432,7 +436,9 @@ def test_user_identity_span_attributes_data_collection(
432436

433437
@pytest.mark.forked
434438
@pytest_mark_django_db_decorator()
435-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
439+
@pytest.mark.parametrize(
440+
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
441+
)
436442
def test_user_info_error_event_data_collection(
437443
sentry_init, client, capture_events, init_kwargs, expect_ip
438444
):
@@ -453,7 +459,9 @@ def test_user_info_error_event_data_collection(
453459

454460
@pytest.mark.forked
455461
@pytest_mark_django_db_decorator()
456-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
462+
@pytest.mark.parametrize(
463+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
464+
)
457465
def test_user_identity_error_event_data_collection(
458466
sentry_init, client, capture_events, init_kwargs, expect_user
459467
):

‎tests/integrations/flask/test_flask.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from sentry_sdk.consts import SPANDATA
3333
from sentry_sdk.integrations.logging import LoggingIntegration
3434
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
35-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
35+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
3636

3737
# Query string used across the query-param filtering tests below. ``auth`` is a
3838
# built-in sensitive term, so it is redacted by the default denylist.
@@ -1234,7 +1234,9 @@ def test_empty_query_string_is_dropped_with_data_collection(
12341234
assert "query_string" not in event["request"]
12351235

12361236

1237-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
1237+
@pytest.mark.parametrize(
1238+
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
1239+
)
12381240
def test_user_info_span_attributes_data_collection(
12391241
sentry_init, app, capture_items, monkeypatch, init_kwargs, expect_ip
12401242
):
@@ -1265,7 +1267,9 @@ def test_user_info_span_attributes_data_collection(
12651267
assert "client.address" not in segment["attributes"]
12661268

12671269

1268-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
1270+
@pytest.mark.parametrize(
1271+
"init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES_LEGACY
1272+
)
12691273
def test_user_info_error_event_data_collection(
12701274
sentry_init, app, capture_events, monkeypatch, init_kwargs, expect_ip
12711275
):
@@ -1316,7 +1320,9 @@ def crash():
13161320
assert "ip_address" not in event.get("user", {})
13171321

13181322

1319-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
1323+
@pytest.mark.parametrize(
1324+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
1325+
)
13201326
def test_flask_login_user_identity_error_event_data_collection(
13211327
sentry_init, app, capture_events, init_kwargs, expect_user
13221328
):
@@ -1364,7 +1370,9 @@ def crash():
13641370
assert "username" not in user
13651371

13661372

1367-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
1373+
@pytest.mark.parametrize(
1374+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
1375+
)
13681376
def test_flask_login_user_identity_span_attributes_data_collection(
13691377
sentry_init, app, capture_items, init_kwargs, expect_user
13701378
):

‎tests/integrations/huey/test_huey.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sentry_sdk.integrations.huey import HueyIntegration
1111
from sentry_sdk.traces import SegmentNameSource, SpanStatus
1212
from sentry_sdk.utils import parse_version
13-
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES
13+
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES_LEGACY
1414

1515
HUEY_VERSION = parse_version(HUEY_VERSION)
1616

@@ -205,7 +205,7 @@ def maybe_locked_task():
205205

206206
@pytest.mark.parametrize(
207207
"init_kwargs,expected_args,expected_kwargs",
208-
DATA_COLLECTION_QUEUES_CASES,
208+
DATA_COLLECTION_QUEUES_CASES_LEGACY,
209209
)
210210
def test_task_args_kwargs_data_collection(
211211
capture_items,

‎tests/integrations/litestar/test_litestar.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE
2020
from tests.conftest import ApproxDict
2121
from tests.integrations.conftest import parametrize_test_configurable_status_codes
22-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
22+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
2323

2424

2525
def litestar_app_factory(middleware=None, debug=True, exception_handlers=None):
@@ -448,7 +448,9 @@ def test_span_origin(
448448
assert span["attributes"]["sentry.origin"] == "auto.http.litestar"
449449

450450

451-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
451+
@pytest.mark.parametrize(
452+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
453+
)
452454
def test_litestar_scope_user_on_exception_event(
453455
sentry_init,
454456
capture_exceptions,

‎tests/integrations/pyramid/test_pyramid.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
1616
from sentry_sdk.traces import SpanStatus
1717
from tests.conftest import unpack_werkzeug_response
18-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
18+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
1919

2020

2121
def hi(request):
@@ -536,7 +536,9 @@ def test_span_origin(
536536
assert segment["attributes"]["sentry.origin"] == "auto.http.pyramid"
537537

538538

539-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
539+
@pytest.mark.parametrize(
540+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
541+
)
540542
def test_span_sets_user_id_on_segment(
541543
sentry_init,
542544
pyramid_config,
@@ -575,7 +577,9 @@ def authenticated_userid(self, request):
575577
assert "user.id" not in segment["attributes"]
576578

577579

578-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
580+
@pytest.mark.parametrize(
581+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
582+
)
579583
def test_user_id_error_event_data_collection(
580584
sentry_init,
581585
pyramid_config,

‎tests/integrations/rq/test_rq.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from sentry_sdk.consts import SPANDATA
99
from sentry_sdk.integrations.rq import RqIntegration
1010
from sentry_sdk.utils import SENSITIVE_DATA_SUBSTITUTE, parse_version
11-
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES
11+
from tests.integrations.utils import DATA_COLLECTION_QUEUES_CASES_LEGACY
1212

1313

1414
@pytest.fixture(autouse=True)
@@ -91,7 +91,7 @@ def test_basic(
9191

9292
@pytest.mark.parametrize(
9393
"init_kwargs,expected_args,expected_kwargs",
94-
DATA_COLLECTION_QUEUES_CASES,
94+
DATA_COLLECTION_QUEUES_CASES_LEGACY,
9595
)
9696
def test_job_args_kwargs_data_collection(
9797
sentry_init,

‎tests/integrations/sanic/test_sanic.py‎

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,9 @@ def test_span_origin(sentry_init, app, capture_items):
503503
assert segment["attributes"]["sentry.origin"] == "auto.http.sanic"
504504

505505

506-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
506+
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
507507
def test_user_ip_address_on_all_spans(
508-
sentry_init, app, capture_items, init_kwargs, expect_ip
508+
sentry_init, app, capture_items, data_collection, expect_ip
509509
):
510510
app.config.FORWARDED_SECRET = "test"
511511

@@ -519,7 +519,7 @@ def child_span_handler(request):
519519
integrations=[SanicIntegration()],
520520
default_integrations=False,
521521
traces_sample_rate=1.0,
522-
**init_kwargs,
522+
data_collection=data_collection,
523523
)
524524

525525
items = capture_items("span")
@@ -543,17 +543,17 @@ def child_span_handler(request):
543543
assert "user.ip_address" not in child_span["attributes"]
544544

545545

546-
@pytest.mark.parametrize("init_kwargs, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
546+
@pytest.mark.parametrize("data_collection, expect_ip", DATA_COLLECTION_USER_INFO_CASES)
547547
def test_client_address_span_attribute_data_collection(
548-
sentry_init, app, capture_items, init_kwargs, expect_ip
548+
sentry_init, app, capture_items, data_collection, expect_ip
549549
):
550550
app.config.FORWARDED_SECRET = "test"
551551

552552
sentry_init(
553553
integrations=[SanicIntegration()],
554554
default_integrations=False,
555555
traces_sample_rate=1.0,
556-
**init_kwargs,
556+
data_collection=data_collection,
557557
)
558558

559559
items = capture_items("span")
@@ -581,55 +581,43 @@ def test_client_address_span_attribute_data_collection(
581581

582582
_QUERY_PARAM_DATA_COLLECTION_CASES = [
583583
pytest.param(
584-
{"data_collection": {"url_query_params": {"mode": "off"}}},
584+
{"url_query_params": {"mode": "off"}},
585585
None,
586586
id="data_collection_off",
587587
),
588588
pytest.param(
589-
{"data_collection": {}},
589+
{},
590590
"toy=tennisball&color=red&auth=%5BFiltered%5D",
591591
id="data_collection_denylist_default",
592592
),
593593
pytest.param(
594-
{
595-
"data_collection": {
596-
"url_query_params": {"mode": "denylist", "terms": ["toy"]}
597-
}
598-
},
594+
{"url_query_params": {"mode": "denylist", "terms": ["toy"]}},
599595
"toy=%5BFiltered%5D&color=red&auth=%5BFiltered%5D",
600596
id="data_collection_denylist_custom_terms",
601597
),
602598
pytest.param(
603-
{
604-
"data_collection": {
605-
"url_query_params": {"mode": "allowlist", "terms": ["toy"]}
606-
}
607-
},
599+
{"url_query_params": {"mode": "allowlist", "terms": ["toy"]}},
608600
"toy=tennisball&color=%5BFiltered%5D&auth=%5BFiltered%5D",
609601
id="data_collection_allowlist",
610602
),
611603
pytest.param(
612-
{
613-
"data_collection": {
614-
"url_query_params": {"mode": "allowlist", "terms": ["auth"]}
615-
}
616-
},
604+
{"url_query_params": {"mode": "allowlist", "terms": ["auth"]}},
617605
"toy=%5BFiltered%5D&color=%5BFiltered%5D&auth=%5BFiltered%5D",
618606
id="data_collection_allowlist_sensitive_term",
619607
),
620608
]
621609

622610

623611
@pytest.mark.parametrize(
624-
"init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
612+
"data_collection, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
625613
)
626614
def test_url_query_data_collection(
627-
sentry_init, app, capture_items, init_kwargs, expected_query
615+
sentry_init, app, capture_items, data_collection, expected_query
628616
):
629617
sentry_init(
630618
integrations=[SanicIntegration()],
631619
traces_sample_rate=1.0,
632-
**init_kwargs,
620+
data_collection=data_collection,
633621
)
634622

635623
items = capture_items("span")
@@ -661,12 +649,12 @@ def test_url_query_data_collection(
661649

662650

663651
@pytest.mark.parametrize(
664-
"init_kwargs, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
652+
"data_collection, expected_query", _QUERY_PARAM_DATA_COLLECTION_CASES
665653
)
666654
def test_url_query_data_collection_event_processor(
667-
sentry_init, app, capture_events, init_kwargs, expected_query
655+
sentry_init, app, capture_events, data_collection, expected_query
668656
):
669-
sentry_init(integrations=[SanicIntegration()], **init_kwargs)
657+
sentry_init(integrations=[SanicIntegration()], data_collection=data_collection)
670658

671659
events = capture_events()
672660

@@ -766,12 +754,12 @@ def oversized_handler(request):
766754

767755

768756
@pytest.mark.parametrize(
769-
"init_kwargs, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES
757+
"data_collection, expect_remote_addr", DATA_COLLECTION_REMOTE_ADDR_CASES
770758
)
771759
def test_remote_addr_data_collection(
772-
sentry_init, app, capture_events, init_kwargs, expect_remote_addr
760+
sentry_init, app, capture_events, data_collection, expect_remote_addr
773761
):
774-
sentry_init(integrations=[SanicIntegration()], **init_kwargs)
762+
sentry_init(integrations=[SanicIntegration()], data_collection=data_collection)
775763
events = capture_events()
776764

777765
c = get_client(app)

‎tests/integrations/starlite/test_starlite.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from sentry_sdk import capture_message
1414
from sentry_sdk._types import SENSITIVE_DATA_SUBSTITUTE
1515
from sentry_sdk.integrations.starlite import StarliteIntegration
16-
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES
16+
from tests.integrations.utils import DATA_COLLECTION_USER_INFO_CASES_LEGACY
1717

1818

1919
def starlite_app_factory(middleware=None, debug=True, exception_handlers=None):
@@ -398,7 +398,9 @@ def test_span_origin(sentry_init, capture_items):
398398
assert item.payload["attributes"]["sentry.origin"] == "auto.http.starlite"
399399

400400

401-
@pytest.mark.parametrize("init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES)
401+
@pytest.mark.parametrize(
402+
"init_kwargs, expect_user", DATA_COLLECTION_USER_INFO_CASES_LEGACY
403+
)
402404
def test_starlite_scope_user_on_exception_event(
403405
sentry_init, capture_exceptions, capture_events, init_kwargs, expect_user
404406
):

0 commit comments

Comments
 (0)