@@ -26,7 +26,7 @@ def test_base64_binary_field_to_internal_value_happy(input, url_safe, expected_o
2626
2727@pytest .mark .parametrize (
2828 "input" ,
29- ["#(*@)" , "aGVsbG8" , "asd/sd/ " , "123098 " ],
29+ ["#(*@)" , "hello" , " aGVsbG8== " , "aGVsbG8== " , "aGVsbG8===" , "aGVsbG8====" , "aGVsbG8===== " ],
3030)
3131@pytest .mark .parametrize ("url_safe" , [True , False ])
3232def test_base64_binary_field_to_internal_value_invalid (input , url_safe ):
@@ -64,6 +64,20 @@ def test_base64_binary_field_to_representation_invalid():
6464 assert exc_info .value .detail [0 ].code == "invalid_type"
6565
6666
67+ @pytest .mark .parametrize (
68+ "input,corrected_input" ,
69+ [
70+ ("WcUTqPwauLDnGdb9uCZ0VQ" , "WcUTqPwauLDnGdb9uCZ0VQ==" ),
71+ ("JWmxDeJ8VCtmukFItR683RM" , "JWmxDeJ8VCtmukFItR683RM=" ),
72+ ("402aaUKt/TlX41z5tcQLdv3WMvw" , "402aaUKt/TlX41z5tcQLdv3WMvw=" ),
73+ ],
74+ )
75+ def test_base64_binary_field_corrects_truncated_padding (input , corrected_input ):
76+ """Check that the field corrects truncated padding to form valid base64."""
77+ field = Base64BinaryField ()
78+ assert field ._correct_padding (input ) == corrected_input
79+
80+
6781@pytest .mark .parametrize (
6882 "url_safe" ,
6983 [True , False ],
0 commit comments