def read_file_as_root(file_path): """Secure helper to read file as root.""" try: out, _err = execute('cat', file_path, run_as_root=True) return out except exception.ProcessExecutionError: raise exception.FileNotFound(file_path=file_path)
def test_file_not_found(self): # Verify response code for exception.FileNotFound file_path = "fake_file_path" e = exception.FileNotFound(file_path=file_path) self.assertEqual(404, e.code) self.assertIn(file_path, e.msg)