OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 """Tests for the extraction tool object.""" | 3 """Tests for the extraction tool object.""" |
4 | 4 |
5 import argparse | 5 import argparse |
6 import unittest | 6 import unittest |
7 | 7 |
8 from plaso.cli import extract_analyze_tool | 8 from plaso.cli import extract_analyze_tool |
9 from plaso.lib import errors | 9 from plaso.lib import errors |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() | 38 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() |
39 test_tool.AddStorageFileOptions(argument_parser) | 39 test_tool.AddStorageFileOptions(argument_parser) |
40 | 40 |
41 output = self._RunArgparseFormatHelp(argument_parser) | 41 output = self._RunArgparseFormatHelp(argument_parser) |
42 self.assertEqual(output, self._EXPECTED_OUTPUT_STORAGE_FILE_OPTIONS) | 42 self.assertEqual(output, self._EXPECTED_OUTPUT_STORAGE_FILE_OPTIONS) |
43 | 43 |
44 def testGenerateStorageFileName(self): | 44 def testGenerateStorageFileName(self): |
45 """Tests the _GenerateStorageFileName function.""" | 45 """Tests the _GenerateStorageFileName function.""" |
46 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() | 46 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() |
47 | 47 |
48 source_path = u'/test/storage/path' | 48 test_tool._source_path = u'/test/storage/path' |
49 test_tool.SetSourcePath(source_path) | |
50 storage_filename = test_tool._GenerateStorageFileName() | 49 storage_filename = test_tool._GenerateStorageFileName() |
51 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( | 50 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( |
52 filename=u'path') | 51 filename=u'path') |
53 self.assertRegexpMatches(storage_filename, expected_storage_filename) | 52 self.assertRegexpMatches(storage_filename, expected_storage_filename) |
54 | 53 |
55 source_path = u'/test/storage/path/' | 54 test_tool._source_path = u'/test/storage/path/' |
56 test_tool.SetSourcePath(source_path) | |
57 storage_filename = test_tool._GenerateStorageFileName() | 55 storage_filename = test_tool._GenerateStorageFileName() |
58 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( | 56 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( |
59 filename=u'path') | 57 filename=u'path') |
60 self.assertRegexpMatches(storage_filename, expected_storage_filename) | 58 self.assertRegexpMatches(storage_filename, expected_storage_filename) |
61 | 59 |
62 source_path = u'/' | 60 test_tool._source_path = u'/' |
63 test_tool.SetSourcePath(source_path) | |
64 storage_filename = test_tool._GenerateStorageFileName() | 61 storage_filename = test_tool._GenerateStorageFileName() |
65 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( | 62 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( |
66 filename=u'ROOT') | 63 filename=u'ROOT') |
67 self.assertRegexpMatches(storage_filename, expected_storage_filename) | 64 self.assertRegexpMatches(storage_filename, expected_storage_filename) |
68 | 65 |
69 source_path = u'/foo/..' | 66 test_tool._source_path = u'/foo/..' |
70 test_tool.SetSourcePath(source_path) | |
71 storage_filename = test_tool._GenerateStorageFileName() | 67 storage_filename = test_tool._GenerateStorageFileName() |
72 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( | 68 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( |
73 filename=u'ROOT') | 69 filename=u'ROOT') |
74 self.assertRegexpMatches(storage_filename, expected_storage_filename) | 70 self.assertRegexpMatches(storage_filename, expected_storage_filename) |
75 | 71 |
76 source_path = u'foo/../bar' | 72 test_tool._source_path = u'foo/../bar' |
77 test_tool.SetSourcePath(source_path) | |
78 storage_filename = test_tool._GenerateStorageFileName() | 73 storage_filename = test_tool._GenerateStorageFileName() |
79 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( | 74 expected_storage_filename = self._STORAGE_FILENAME_TEMPLATE.format( |
80 filename=u'bar') | 75 filename=u'bar') |
81 self.assertRegexpMatches(storage_filename, expected_storage_filename) | 76 self.assertRegexpMatches(storage_filename, expected_storage_filename) |
82 | 77 |
83 def testParseOptions(self): | 78 def testParseOptions(self): |
84 """Tests the ParseOptions function.""" | 79 """Tests the ParseOptions function.""" |
85 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() | 80 test_tool = extract_analyze_tool.ExtractionAndAnalysisTool() |
86 | 81 |
87 options = test_lib.TestOptions() | 82 options = test_lib.TestOptions() |
88 | 83 |
89 # ParseOptions will raise if source is not set. | 84 # ParseOptions will raise if source is not set. |
90 with self.assertRaises(errors.BadConfigOption): | 85 with self.assertRaises(errors.BadConfigOption): |
91 test_tool.ParseOptions(options) | 86 test_tool.ParseOptions(options) |
92 | 87 |
93 options.source = self._GetTestFilePath([u'ímynd.dd']) | 88 options.source = self._GetTestFilePath([u'ímynd.dd']) |
94 | 89 |
95 test_tool.ParseOptions(options) | 90 test_tool.ParseOptions(options) |
96 storage_path_regex = self._STORAGE_FILENAME_TEMPLATE.format( | 91 storage_path_regex = self._STORAGE_FILENAME_TEMPLATE.format( |
97 filename=u'ímynd.dd') | 92 filename=u'ímynd.dd') |
98 self.assertRegexpMatches(test_tool._storage_file_path, storage_path_regex) | 93 self.assertRegexpMatches(test_tool._storage_file_path, storage_path_regex) |
99 | 94 |
100 | 95 |
101 if __name__ == '__main__': | 96 if __name__ == '__main__': |
102 unittest.main() | 97 unittest.main() |
OLD | NEW |