Skip to content

Commit

Permalink
Regex support added for IGNORE_URLS with test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Saurav Sharma authored and Saurav Sharma committed Feb 15, 2024
1 parent 7e51dac commit 28fdfb5
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions tests/functional/test_sync_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_improperly_configured_if_not_in_installed_apps(client, monkeypatch):
client.get('/')


def test_url_ignored(client, caplog):
def test_url_ignored_without_regex(client, caplog):
"""
Test that a URL specified in IGNORE_URLS is ignored.
:param client: Django client
Expand All @@ -309,28 +309,6 @@ def test_url_ignored(client, caplog):
assert [(x.message, x.correlation_id) for x in caplog.records] == expected


def test_url_ignored_without_regex(client, caplog):
"""
Test that a URL without regex pattern specified in IGNORE_URLS is ignored.
:param client: Django client
:param caplog: Caplog fixture
"""
from django.conf import settings as django_settings

mocked_settings = deepcopy(django_settings.DJANGO_GUID)
mocked_settings['IGNORE_URLS'] = ['no-guid']
with override_settings(DJANGO_GUID=mocked_settings):
client.get('/no-guid', **{'HTTP_Correlation-ID': 'bad-guid'})
# No log message should have a GUID, aka `None` on index 1.
expected = [
('sync middleware called', None),
('This log message should NOT have a GUID - the URL is in IGNORE_URLS', None),
('Some warning in a function', None),
('Received signal `request_finished`, clearing guid', None),
]
assert [(x.message, x.correlation_id) for x in caplog.records] == expected


def test_url_ignored_with_regex(client, caplog):
"""
Test that a URL with regex pattern specified in IGNORE_URLS is ignored.
Expand Down

0 comments on commit 28fdfb5

Please sign in to comment.