comparison MoinMoin/_tests/test_PageEditor.py @ 3042:353739af70fa

PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Tue, 19 Feb 2008 22:06:50 +0100
parents f5049c4cbf6e
children 02b73ceab324
comparison
equal deleted inserted replaced
3041:7400c1f2e20a 3042:353739af70fa
217 217
218 expected = u'Page "SomeDict" was successfully deleted!' 218 expected = u'Page "SomeDict" was successfully deleted!'
219 219
220 assert result == expected 220 assert result == expected
221 221
222 class TestCopyPage(object):
223
224 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
225 copy_pagename = u'AutoCreatedMoinMoinTemporaryCopyTestPage'
226 shouldDeleteTestPage = True
227 text = u'Example'
228
229 def setup_method(self, method):
230 self.savedValid = self.request.user.valid
231 self.request.user.valid = 1
232
233 def teardown_method(self, method):
234 self.request.user.valid = self.savedValid
235 self.deleteTestPage()
236
237 def createTestPage(self):
238 """ Create temporary page, bypass logs, notification and backups
239
240 TODO: this code is very fragile, any change in the
241 implementation will break this test. Need to factor PageEditor
242 to make it possible to create page without loging and notifying.
243 """
244 import os
245 path = Page(self.request, self.pagename).getPagePath(check_create=0)
246 copy_path = Page(self.request, self.copy_pagename).getPagePath(check_create=0)
247
248 if os.path.exists(path) or os.path.exists(copy_path):
249 self.shouldDeleteTestPage = False
250 py.test.skip("%s or %s exists. Won't overwrite exiting page" % (self.pagename, self.copy_pagename))
251 try:
252 os.mkdir(path)
253 revisionsDir = os.path.join(path, 'revisions')
254 os.mkdir(revisionsDir)
255 current = '00000001'
256 file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
257
258 file(os.path.join(revisionsDir, current), 'w').write(self.text)
259 except Exception, err:
260 py.test.skip("Can not be create test page: %s" % err)
261
262 def deleteTestPage(self):
263 """ Delete temporary page, bypass logs and notifications """
264 if self.shouldDeleteTestPage:
265 import shutil
266 shutil.rmtree(Page(self.request, self.pagename).getPagePath(), True)
267 shutil.rmtree(Page(self.request, self.copy_pagename).getPagePath(), True)
268
269 def test_copy_page(self):
270 """
271 Tests copying a page without restricted acls
272 """
273 self.createTestPage()
274 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
275 revision = Page(self.request, self.copy_pagename).current_rev()
276 assert result and revision is 2
277
278 def test_copy_page_acl_read(self):
279 """
280 Tests copying a page without write rights
281 """
282 self.text = u'#acl SomeUser:read,write,delete All:read\n'
283 self.createTestPage()
284 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
285 revision = Page(self.request, self.copy_pagename).current_rev()
286 assert result and revision is 2
287
288 def test_copy_page_acl_no_read(self):
289 """
290 Tests copying a page without read rights
291 """
292 self.text = u'#acl SomeUser:read,write,delete All:\n'
293 self.createTestPage()
294 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
295 revision = Page(self.request, self.copy_pagename).current_rev()
296 assert result and revision is 2
297
222 coverage_modules = ['MoinMoin.PageEditor'] 298 coverage_modules = ['MoinMoin.PageEditor']
223 299