def test_nb_files(self): with patch('brain.models.sqlobjects.Scan.files', new_callable=PropertyMock) as mock_files: mock_files.return_value = {} scan = Scan(self.frontend_scanid, self.user_id) self.assertEqual(scan.nb_files, 0) mock_files.assert_called_once()
def test001___init__(self): scan = Scan(self.frontend_scanid, self.user_id, self.nb_files) self.assertEqual(scan.scan_id, self.frontend_scanid) self.assertEqual(scan.user_id, self.user_id) self.assertEqual(scan.nb_files, self.nb_files) self.assertEqual(scan.status, IrmaScanStatus.empty) self.assertIsNotNone(scan.timestamp)
def new(frontend_scan_id, user, session): try: scan = Scan.get_scan(frontend_scan_id, user.id, session) except IrmaDatabaseResultNotFound: scan = Scan(frontend_scan_id, user.id) session.add(scan) session.commit() log.debug("scanid %s: user_id %s id %s", frontend_scan_id, user.id, scan.id) return scan
def setUp(self): self.session = MagicMock() self.name = "user" self.rmqvhost = "vhost" self.ftpuser = "******" self.user = User(self.name, self.rmqvhost, self.ftpuser) self.frontend_scanid = "frontend_scanid" self.nb_files = randint(50, 100) self.scan = Scan(frontend_scanid=self.frontend_scanid, user_id=self.user.id) self.scan.user = self.user
def new(frontend_scan_id, user, nb_files, session): try: scan = Scan.get_scan(frontend_scan_id, user.id, session) scan.nb_files += nb_files scan.update(['nb_files'], session) except IrmaDatabaseResultNotFound: scan = Scan(frontend_scan_id, user.id, nb_files) scan.save(session) session.commit() log.debug("scanid %s: user_id %s nb_files %s id %s", frontend_scan_id, user.id, nb_files, scan.id) return scan