FreedomBox/plinth/tests/test_views.py
Sunil Mohan Adapa 6f30e12cd7
views: Drop use of private Django utility
We are currently using django.utils.http.is_safe_url which is a private method
and may break API anytime. Replace it with similar but limited implementation.

Tests:

- Unit tests.

- Dismiss a notification and the redirect to the same page happens properly.

- Logout, goto to home page or login page. Change the language and it will
redirect back to home page or login page appropriately.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-06-27 16:03:15 -04:00

32 lines
615 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
Tests for common FreedomBox views.
"""
import pytest
from plinth.views import is_safe_url
@pytest.mark.parametrize('url', [
'/plinth/login/',
'/',
'safe',
])
def test_is_safe_url_valid_url(url):
"""Test valid URLs for safe URL checks."""
assert is_safe_url(url)
@pytest.mark.parametrize('url', [
'',
None,
'\\plinth',
'///plinth',
'https://example.com/plinth/login/',
'https:///plinth/login',
])
def test_is_safe_url_invalid_url(url):
"""Test invalid URLs for safe URL checks."""
assert not is_safe_url(url)