1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# This file is part of the django-environ.
#
# Copyright (c) 2021-2024, Serghei Iakovlev <oss@serghei.pl>
# Copyright (c) 2013-2021, Daniele Faraglia <daniele.faraglia@gmail.com>
#
# For the full copyright and license information, please view
# the LICENSE.txt file that was distributed with this source code.
import pytest
from environ.environ import _cast, _cast_urlstr
@pytest.mark.parametrize(
'literal',
['anything-', 'anything*', '*anything', 'anything.',
'anything.1', '(anything', 'anything-v1.2', 'anything-1.2', 'anything=']
)
def test_cast(literal):
"""Safely evaluate a string containing an invalid Python literal.
See https://github.com/joke2k/django-environ/issues/200 for details."""
assert _cast(literal) == literal
@pytest.mark.parametrize(
"quoted_url_str,expected_unquoted_str",
[
("Le-%7BFsIaYnaQw%7Da2B%2F%5BV8bS+", "Le-{FsIaYnaQw}a2B/[V8bS+"),
("my_test-string+", "my_test-string+"),
("my%20test%20string+", "my test string+")
]
)
def test_cast_urlstr(quoted_url_str, expected_unquoted_str):
"""Make sure that a url str that contains plus sign literals does not get unquoted incorrectly
Plus signs should not be converted to spaces, since spaces are encoded with %20 in URIs
see https://github.com/joke2k/django-environ/issues/357 for details.
related to https://github.com/joke2k/django-environ/pull/69"""
assert _cast_urlstr(quoted_url_str) == expected_unquoted_str
|