def testRegisterEntities(self): mtgx = pymtgx.Pymtgx() self.assertEqual(6, len(mtgx.entities)) mtgx.register_entities("test_entities.mtz") self.assertEqual(8, len(mtgx.entities)) registered_entity = mtgx.entities["maltego.Humbug"] self.assertEqual("humbug.Id", registered_entity['name'])
def testNodesAndEdgesAreAdded(self): mtgx = pymtgx.Pymtgx() self.assertEqual(0, len(mtgx.nodes())) id1 = mtgx.add_node("maltego.Person", "Jon Doe") id2 = mtgx.add_node("maltego.EmailAddress", "*****@*****.**") self.assertEqual(2, len(mtgx.nodes())) self.assertEqual(0, len(mtgx.edges())) mtgx.add_edge(id1, id2) self.assertEqual(1, len(mtgx.edges()))
def __init__(self, input_file, format_spec_file, output_file, entity_files, delimiter, quotechar, skip_lines, map_header): self.mtgx = pymtgx.Pymtgx() # Ensure correct output file extension. if output_file.endswith(".mtgx"): output_file = output_file[:-5] self.output_file = output_file self.number_of_edges = 0 # Register entity specifications for entity_file in entity_files: self.mtgx.register_entities(entity_file) # If we are using indexed format specifications, load them right away. if not map_header: self.format_spec = self.__load_indexed_format(format_spec_file) with open(input_file, 'rb') as csvfile: lines = 0 # Read lines as CSV. for line in csv.reader(csvfile, delimiter=delimiter, quotechar=quotechar): lines += 1 if lines <= skip_lines: continue # If we are using mapped format specifications, load mapping from first # line that is not skipped. elif map_header and lines == skip_lines + 1: self.format_spec = self.__load_mapped_format( format_spec_file, line) continue # Parse the line into maltego entities and edges. self.number_of_edges += self._parse_line(line) # Calculate the number of lines we've parsed. self.number_of_lines = lines - skip_lines
def testNodeFormat(self): mtgx = pymtgx.Pymtgx() mtgx.add_node("maltego.Person", "Jon Doe") nodes = mtgx.nodes(data=True) element = nodes[0][1]['MaltegoEntity'].data entity = element.getchildren()[0] self.assertEqual("maltego.Person", entity.attrib['type']) prop = entity.getchildren()[0].getchildren()[0] self.assertEqual("person.fullname", prop.attrib['name']) self.assertEqual("string", prop.attrib['type']) value = prop.getchildren()[0].text self.assertEqual("Jon Doe", value)
def testLayout(self): mtgx = pymtgx.Pymtgx() id1 = mtgx.add_node("maltego.Person", "Jon Doe") id2 = mtgx.add_node("maltego.EmailAddress", "*****@*****.**") mtgx.add_edge(id1, id2) for node in mtgx.positions: self.assertFalse('x' in mtgx.positions[node].position.attrib) self.assertFalse('y' in mtgx.positions[node].position.attrib) mtgx.layout('spring_layout') for node in mtgx.positions: self.assertNotEqual(None, mtgx.positions[node].position.attrib['x']) self.assertNotEqual(None, mtgx.positions[node].position.attrib['y']) mtgx.create('test5')