Beispiel #1
0
 def test_upload_file_not_a_file(self, m_IrmaSFTP, m_ospath):
     upload_path = "path2"
     filename = "file2"
     m_ospath.isfile.return_value = False
     with self.assertRaises(IrmaFtpError) as context:
         module.upload_file(upload_path, filename)
     self.assertEqual(str(context.exception), "Ftp upload Error")
Beispiel #2
0
 def test_upload_file(self, m_IrmaSFTP, m_ospath):
     upload_path = "path1"
     filename = "file1"
     m_ftp = MagicMock()
     m_IrmaSFTP().__enter__.return_value = m_ftp
     m_ospath.isfile.return_value = True
     m_ospath.basename.return_value = filename
     module.upload_file(upload_path, filename)
     m_ospath.isfile.assert_called_once_with(filename)
     m_ftp.upload_file.assert_called_once_with(upload_path, filename)
Beispiel #3
0
def scan_launch_file_ext(file_ext_id):
    file_ext = None
    with session_transaction() as session:
        try:
            file_ext = FileExt.load_from_ext_id(file_ext_id, session)
            scan_id = file_ext.scan.external_id
            log.debug("scan %s: launch scan for file_ext: %s",
                      scan_id, file_ext_id)
            ftp_ctrl.upload_file(file_ext_id, file_ext.file.path)
            # launch new celery scan task on brain
            celery_brain.scan_launch(file_ext_id, file_ext.probes, scan_id)
        except IrmaFtpError as e:
            log.error("file_ext %s: ftp upload error %s", file_ext_id, str(e))
            if file_ext is not None:
                file_ext.scan.set_status(IrmaScanStatus.error_ftp_upload)
        except Exception as e:
            log.exception(e)