def test002_upload_scan_not_a_file(self, m_IrmaSFTP, m_ospath): scanid = "scanid2" filename = "file2" m_ospath.isfile.return_value = False with self.assertRaises(IrmaFtpError) as context: module.upload_scan(scanid, [filename]) self.assertEqual(str(context.exception), "Ftp upload Error")
def launch_asynchronous(scanid): log.debug("scanid: %s", scanid) with session_transaction() as session: scan = Scan.load_from_ext_id(scanid, session=session) IrmaScanStatus.filter_status(scan.status, IrmaScanStatus.ready, IrmaScanStatus.ready) scan_request = _create_scan_request(scan.files_web, scan.get_probelist(), scan.mimetype_filtering) scan_request = _add_empty_results(scan.files_web, scan_request, scan, session) # Nothing to do if scan_request.nb_files == 0: scan.set_status(IrmaScanStatus.finished) session.commit() log.warning("scanid: %s finished nothing to do", scanid) return try: upload_list = list() for file in scan.files: upload_list.append(file.path) ftp_ctrl.upload_scan(scanid, upload_list) except IrmaFtpError as e: log.error("scanid: %s ftp upload error %s", scanid, str(e)) scan.set_status(IrmaScanStatus.error_ftp_upload) session.commit() return # launch new celery scan task on brain celery_brain.scan_launch(scanid, scan_request.to_dict()) scan.set_status(IrmaScanStatus.uploaded) session.commit() log.info("scanid: %s uploaded", scanid) return
def test003_upload_scan_wrong_hash(self, m_IrmaSFTP, m_ospath): scanid = "scanid3" filename = "file3" m_ftp = MagicMock() m_ftp.upload_file.return_value = "whatever" m_IrmaSFTP().__enter__.return_value = m_ftp m_ospath.basename.return_value = filename m_ospath.isfile.return_value = True with self.assertRaises(IrmaFtpError) as context: module.upload_scan(scanid, [filename]) self.assertEqual(str(context.exception), "Ftp upload Error")
def test001_upload_scan(self, m_IrmaSFTP, m_ospath): scanid = "scanid1" filename = "file1" m_ftp = MagicMock() m_ftp.upload_file.return_value = filename m_IrmaSFTP().__enter__.return_value = m_ftp m_ospath.isfile.return_value = True m_ospath.basename.return_value = filename module.upload_scan(scanid, [filename]) m_ospath.isfile.assert_called_once_with(filename) m_ftp.upload_file.assert_called_once_with(scanid, filename)