def testTskPathType(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): with mock.patch.object(magics_impl._state, 'cur_dir', '/quux'): magics_impl.grr_ls_impl('foo/bar', path_type=magics_impl.TSK) mock_client.tsk.ls.assert_called_once_with('/quux/foo/bar')
def testCurrentPath(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): with mock.patch.object(magics_impl._state, 'cur_dir', '/quux'): magics_impl.grr_ls_impl() mock_client.os.ls.assert_called_once_with('/quux') self.assertFalse(mock_client.os.cached.ls.called)
def testCached(self): mock_client = mock.MagicMock() with mock.patch.object(magics_impl._state, 'client', mock_client): with mock.patch.object(magics_impl._state, 'cur_dir', '/quux'): magics_impl.grr_ls_impl('foo/bar', cached=True) mock_client.cached.ls.assert_called_once_with('/quux/foo/bar') self.assertFalse(mock_client.ls.called)
def grr_ls(line): """Lists files in the specified directory or the current directory. Args: line: A string representing arguments passed to the magic command. Returns: A sequence of stat entries. Raises: NoClientSelectedError: Client is not selected to perform this operation. """ args = grr_ls.parser.parse_args(shlex.split(line)) return magics_impl.grr_ls_impl(args.path, args.cached)
def testNoClientSelected(self): with self.assertRaises(magics_impl.NoClientSelectedError): magics_impl.grr_ls_impl('/foo')