def test_extract_metadata__correct_method_is_called(self): with mock_patch(self.analysis_plugin, '_extract_metadata_from_tar', self._extract_metadata_from_archive_mock): self.result = None fo = FoMock(None, 'application/x-tar') self.analysis_plugin._extract_metadata(fo) assert self.result == 'archive' with mock_patch(self.analysis_plugin, '_extract_metadata_from_file_system', self._extract_metadata_from_file_system_mock): self.result = None fo = FoMock(None, 'filesystem/ext4') self.analysis_plugin._extract_metadata(fo) assert self.result == 'fs'
def test_process_qemu_job(): test_results = { '--option': { 'stdout': 'test', 'stderr': '', 'return_code': '0' } } uid = 'test_uid' results = {} with mock_patch(qemu_exec, 'check_qemu_executability', lambda *_: test_results): qemu_exec.process_qemu_job('test_path', 'test_arch', Path('test_root'), results, uid) assert results == { uid: { 'path': 'test_path', 'results': { 'test_arch': test_results } } } qemu_exec.process_qemu_job('test_path', 'test_arch_2', Path('test_root'), results, uid) assert results == { uid: { 'path': 'test_path', 'results': { 'test_arch': test_results, 'test_arch_2': test_results } } }
def test_get_blacklist_file_type_from_database(self): def add_file_type_mock(_, fo): fo.processed_analysis['file_type'] = {'mime': 'foo_type'} file_object = MockFileObject() file_object.processed_analysis.pop('file_type') with mock_patch(self.sched, '_add_completed_analysis_results_to_file_object', add_file_type_mock): result = self.sched._get_file_type_from_object_or_db(file_object) assert result == 'foo_type'
def test_ajax_get_system_stats_error(self): with mock_patch(self.mocked_interface, 'get_statistic', lambda _: {}): result = self.test_client.get('/ajax/stats/system').json assert result['backend_cpu_percentage'] == 'n/a' assert result['number_of_running_analyses'] == 'n/a'