def test_collect_from_localhost(self, path_mock): """ Should initialize collectors for the example file "collect-from-localhost.xml" """ from instructionparsers.xmlparser import XmlParser instructions = '../examples/collect-from-localhost.xml' try: xml_parser = XmlParser(instructionspath=instructions, protocol=None) xml_parser._instructionspath = instructions xml_parser._init_instructions() except Exception: self.fail(f"Failed to initialize parser for '{instructions}'.")
def test_collect_all(self, path_mock): """ Should initialize collectors for the example file "collect-all.xml" """ from instructionparsers.xmlparser import XmlParser instructions = '../examples/collect-all.xml' if platform.system() == 'Windows': instructions = '..\examples\collect-all-windows.xml' try: xml_parser = XmlParser(instructionspath=instructions, protocol=None) xml_parser._instructionspath = instructions xml_parser._init_instructions() except Exception: self.fail(f"Failed to initialize parser for '{instructions}'.")
def test_collect_from_image(self, path_mock): """ Should initialize collectors for the example file "collect-from-image.xml" """ from instructionparsers.xmlparser import XmlParser instructions = '../examples/collect-from-image.xml' try: xml_parser = XmlParser(instructionspath=instructions, protocol=None) xml_parser._instructionspath = instructions xml_parser._init_instructions() except FileNotFoundError: # Assume the file not found is from the missing ewf file in the example instructions. pass except Exception: self.fail(f"Failed to initialize parser for '{instructions}'.")
def test__init_instructions_valid_instructions(self, path_mock): """ Should initialize collectors for all XML elements which have the attribute "module". """ from instructionparsers.xmlparser import XmlParser from instructionparsers.wrapper import InstructionWrapper instructions = './instructions/valid_instructions.xml' xml_parser = XmlParser(instructionspath=instructions, protocol=None) xml_parser._instructionspath = instructions instructionstree = xml_parser._init_instructions() self.assertIsInstance(instructionstree, InstructionWrapper)
def test__init_instructions_valid_instructions(self, path_mock): """ Should return the instruction tree starting with "Root" node. """ from instructionparsers.xmlparser import XmlParser instructions = './instructions/valid_instructions.xml' xml_parser = XmlParser(instructionspath=instructions, protocol=None) xml_parser._instructionspath = instructions instructionstree = xml_parser._init_instructions() self.assertEqual(instructionstree.instructionname, 'Root') self.assertEqual( instructionstree.instructionchildren[0].instructionname, 'LocalHost') self.assertEqual( instructionstree.instructionchildren[0].instructionchildren[0]. instructionname, 'MachineName') self.assertEqual( instructionstree.instructionchildren[1].instructionname, 'LocalHost') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[0]. instructionname, 'OSName') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[1]. instructionname, 'OSVersion') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[2]. instructionname, 'OSTimezone') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[3]. instructionname, 'AllUsernames') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[4]. instructionname, 'CurrentUser') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[5]. instructionname, 'SudoVersion') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[6]. instructionname, 'FileExistence') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[7]. instructionname, 'FileExistence') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[8]. instructionname, 'FileExistence') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[9]. instructionname, 'FileExistence') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[10]. instructionname, 'FileExistence') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[11]. instructionname, 'ShellHistoryOfAllUsers') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[12]. instructionname, 'NVRAMCollector') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[13]. instructionname, 'TimeFromNTPServer') self.assertEqual( instructionstree.instructionchildren[1].instructionchildren[14]. instructionname, 'LocalTime')