I have created this functionality where System regularly connects to remote location, checks specified directory and if it finds specific files in there, it imports data to system.
Transfer functionality is implemented using paramiko
and ftplib
. So I wonder if it is possible to somehow create some "fake" SSH connection into one of my module's directories, so it would act like a remote location where there would be test file to import (at least with paramiko
behavior)?
So unittest could be run without actual real connection to some remote location? Any ideas for that?
Update to have better question, here is a sample of method that might have unittest (unittest would be to test if I could get sftp
object):
import socket
from paramiko import AuthenticationException, Transport, SFTPClient
def get_sftp_connection(self, log_error=True):
self.ensure_one()
login = self.login_id
LogCustom = self.env['log.custom'] # Custom thing, no need for unittest here
ref = self._get_rec_description()
try:
transport = Transport((login.host, login.port))
transport.connect(username=login.user, password=login.passwd)
sftp = SFTPClient.from_transport(transport)
except socket.gaierror:
msg = _("Name or service '%s' not known") % (login.host)
if log_error:
LogCustom.log_error_event(operation='read', ref=ref, name=msg)
return None
else:
raise ValidationError(msg)
except AuthenticationException:
msg = _("Bad username or password")
if log_error: # No need for unittest
LogCustom.log_error_event(operation='read', ref=ref, name=msg)
return None
else:
raise ValidationError(msg)
return sftp