test_wikidicts.py[9] ........F ___________________________________________________________________________________________________ ________________________ entrypoint: TestGroupDicts().testRenameGroupPage _________________________ def testRenameGroupPage(self): # tests if the dict cache for groups is refreshed after renaming a page gain_superuser_rights(self.request) pagename = u'SomeGroup' page = PageEditor(self.request, pagename, do_editor_backup=0) body = " * ExampleUser" page.saveText(body, 0) page = PageEditor(self.request, pagename, do_editor_backup=0) > page.renamePage(self.request, u'AnotherGroup') [/home/workspace/moin-1.7/MoinMoin/_tests/test_wikidicts.py:127] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def renamePage(self, newpagename, comment=None): """ Rename the current version of the page (making a backup before deletion and keeping the backups, logs and attachments). @param comment: Comment given by user @rtype: unicode @return: success flag, error message """ request = self.request _ = self._ if not (request.user.may.delete(self.page_name) and request.user.may.write(newpagename)): msg = _('You are not allowed to rename this page!') raise self.AccessDenied, msg if not newpagename: return False, _("You can't rename to an empty pagename.") newpage = PageEditor(request, newpagename) pageexists_error = _("""'''A page with the name {{{'%s'}}} already exists.''' Try a different name.""") % (wikiutil.escape(newpagename), ) # Check whether a page with the new name already exists if newpage.exists(includeDeleted=1): return False, pageexists_error # Get old page text savetext = self.get_raw_body() oldpath = self.getPagePath(check_create=0) newpath = newpage.getPagePath(check_create=0) # Rename page # NOTE: might fail if another process created newpagename just # NOW, while you read this comment. Rename is atomic for files - # but for directories, rename will fail if the directory # exists. We should have global edit-lock to avoid this. # See http://docs.python.org/lib/os-file-dir.html try: os.rename(oldpath, newpath) self.error = None # Save page text with a comment about the old name savetext = u"## page was renamed from %s\n%s" % (self.page_name, savetext) > newpage.saveText(savetext, 0, comment=comment, extra=self.page_name, action='SAVE/RENAME', notify=False) [/home/workspace/moin-1.7/MoinMoin/PageEditor.py:609] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def saveText(self, newtext, rev, **kw): """ Save new text for a page. @param newtext: text to save for this page @param rev: revision of the page @keyword trivial: trivial edit (default: 0) @keyword extra: extra info field (e.g. for SAVE/REVERT with revno) @keyword comment: comment field (when preview is true) @keyword action: action for editlog (default: SAVE) @keyword index: needs indexing, not already handled (default: 1) @keyword deleted: if True, then don't save page content (used by DeletePage, default: False) @keyword notify: if False (default: True), don't send a PageChangedEvent @rtype: unicode @return: error msg """ request = self.request _ = self._ > self._save_draft(newtext, rev, **kw) [/home/workspace/moin-1.7/MoinMoin/PageEditor.py:1024] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _save_draft(self, text, rev, **kw): """ Save an editor backup to the drafts cache arena. @param text: draft text of the page (if None, the draft gets removed from the cache) @param rev: the revision of the page this draft is based on @param kw: no keyword args used currently """ request = self.request if not request.user.valid or not self.do_editor_backup: return None arena = 'drafts' key = request.user.id cache = caching.CacheEntry(request, arena, key, scope='wiki', use_pickle=True) if cache.exists(): cache_data = cache.content() else: cache_data = {} pagename = self.page_name if text is None: try: del cache_data[pagename] except: pass else: timestamp = int(time.time()) cache_data[pagename] = (timestamp, rev, text) > cache.update(cache_data) [/home/workspace/moin-1.7/MoinMoin/PageEditor.py:836] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def update(self, content): try: fname = self._filename() if self.use_pickle: content = pickle.dumps(content, PICKLE_PROTOCOL) elif self.use_encode: content = content.encode(config.charset) if not self.locking or self.locking and self.wlock.acquire(1.0): try: # we do not write content to old inode, but to a new file # so we don't need to lock when we just want to read the file # (at least on POSIX, this works) tmp_handle, tmp_fname = tempfile.mkstemp('.tmp', self.key, self.arena_dir) os.write(tmp_handle, content) os.close(tmp_handle) # this is either atomic or happening with real locks set: filesys.rename(tmp_fname, fname) filesys.chmod(fname, 0666 & config.umask) # fix mode that mkstemp chose finally: if self.locking: self.wlock.release() else: print self.lock_dir self.request.log("Can't acquire write lock in %s" % self.lock_dir) except (pickle.PicklingError, OSError, IOError, ValueError), err: E raise CacheError(str(err)) > CacheError: Can't pickle : attribute lookup __builtin__.instancemethod failed [/home/workspace/moin-1.7/MoinMoin/caching.py:150] ___________________________________________________________________________________________________ ======================= tests finished: 8 passed, 1 failed in 0.83 seconds ========================