test sftp: use force_text() instead of decode() (#38781)
This commit is contained in:
parent
74ead60c38
commit
6a85a58114
|
@ -20,6 +20,7 @@ import pytest
|
|||
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import models
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from passerelle.utils.sftp import SFTP, SFTPFormField, SFTPField
|
||||
|
||||
|
@ -97,7 +98,7 @@ def test_form_field(sftpserver, ssh_key, ssh_key_with_password):
|
|||
with form.cleaned_data['sftp'].client() as sftp:
|
||||
assert sftp.listdir() == ['a.zip']
|
||||
|
||||
form = Form(data={'sftp_0': url, 'sftp_2': ssh_key.decode('ascii')})
|
||||
form = Form(data={'sftp_0': url, 'sftp_2': force_text(ssh_key, 'ascii')})
|
||||
assert form.is_valid()
|
||||
sftp = form.cleaned_data['sftp']
|
||||
assert isinstance(sftp, SFTP)
|
||||
|
@ -127,13 +128,13 @@ def test_form_field(sftpserver, ssh_key, ssh_key_with_password):
|
|||
with form.cleaned_data['sftp'].client() as sftp:
|
||||
assert sftp.listdir() == ['a.zip']
|
||||
|
||||
form = Form(data={'sftp_0': url, 'sftp_2': ssh_key_with_password.decode('ascii')})
|
||||
form = Form(data={'sftp_0': url, 'sftp_2': force_text(ssh_key_with_password, 'ascii')})
|
||||
assert not form.is_valid()
|
||||
assert 'key invalid' in str(form.errors)
|
||||
|
||||
form = Form(data={
|
||||
'sftp_0': url,
|
||||
'sftp_2': ssh_key_with_password.decode('ascii'),
|
||||
'sftp_2': force_text(ssh_key_with_password, 'ascii'),
|
||||
'sftp_3': 'coucou',
|
||||
})
|
||||
assert form.is_valid()
|
||||
|
|
Loading…
Reference in New Issue