Example #1
0
 def test_list_custom_request(self):
     offset, limit = randint(1, 100), randint(1, 100)
     result = api_scans.list(offset=offset, limit=limit)
     self.assertEqual(result["offset"], offset)
     self.assertEqual(result["limit"], limit)
     self.assertIsScanList(result["data"])
     self.session.query().options().count.assert_called()
Example #2
0
 def test_list_custom_request_no_status(self):
     offset, limit = randint(1, 100), randint(1, 100)
     status = choice(list(IrmaScanStatus.label.values()))
     result = api_scans.list(offset=offset, limit=limit)
     self.assertEqual(result["offset"], offset)
     self.assertEqual(result["limit"], limit)
     self.assertIsScanList(result["data"])
     self.session.query().count.assert_called()
Example #3
0
 def test_list_default(self):
     default_offset, default_limit = 0, 5
     result = api_scans.list()
     self.assertEqual(result["offset"], default_offset)
     self.assertEqual(result["limit"], default_limit)
     self.session.query.assert_called_with(Scan)
     self.session.query().limit.assert_called_with(default_limit)
     m_offset = self.session.query().limit().offset
     m_offset.assert_called_with(default_offset)
     self.session.query().count.assert_not_called()
Example #4
0
 def test_list_custom_request_status(self):
     offset, limit = randint(1, 100), randint(1, 100)
     status = choice(list(IrmaScanStatus.label.values()))
     for (k, v) in IrmaScanStatus.label.items():
         if v == status:
             status_code = k
             break
     result = api_scans.list(status=status, offset=offset, limit=limit)
     self.assertEqual(result["offset"], offset)
     self.assertEqual(result["limit"], limit)
     self.assertIsScanList(result["data"])
     self.session.query().filter().count.assert_called()
Example #5
0
 def test_list_custom_request_status_not_existing(self):
     offset, limit = randint(1, 100), randint(1, 100)
     with self.assertRaises(api_scans.HTTPInvalidParam):
         api_scans.list(status="whatever", offset=offset, limit=limit)
Example #6
0
 def test_list_error(self):
     exception = Exception("test")
     self.session.query.side_effect = exception
     with self.assertRaises(Exception):
         api_scans.list()
     self.session.query.assert_called_once_with(Scan)