def test_scanErrors_argument_instanceId_of_invalid_type_should_raise_TypeError(self): """ Test scanErrors(self, instanceId, limit=None) """ sfdb = SpiderFootDb(self.default_options, False) limit = None invalid_types = [None, list(), dict(), int()] for invalid_type in invalid_types: with self.subTest(invalid_type=invalid_type): with self.assertRaises(TypeError): sfdb.scanErrors(invalid_type, limit)
def test_scanErrors_should_return_a_list(self): """ Test scanErrors(self, instanceId, limit=None) """ sfdb = SpiderFootDb(self.default_options, False) instance_id = "example instance id" scan_instance = sfdb.scanErrors(instance_id, None) self.assertIsInstance(scan_instance, list)
def scanerrors(self, id, limit=None): """Scan error data Args: id (str): scan ID limit: TBD """ cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8" dbh = SpiderFootDb(self.config) retdata = [] try: data = dbh.scanErrors(id, limit) except Exception: return json.dumps(retdata).encode('utf-8') for row in data: generated = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0] / 1000)) retdata.append([generated, row[1], html.escape(str(row[2]))]) return json.dumps(retdata).encode('utf-8')
def scanerrors(self, id, limit=None): """Scan error data. Args: id (str): scan ID limit: TBD Returns: str: scan errors as JSON """ dbh = SpiderFootDb(self.config) retdata = [] try: data = dbh.scanErrors(id, limit) except Exception: return retdata for row in data: generated = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0] / 1000)) retdata.append([generated, row[1], html.escape(str(row[2]))]) return retdata