annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
3 MoinMoin - MoinMoin.PageEditor Tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
5 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
6 2007 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
10 import py
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
11
2834
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
12 from MoinMoin import wikiutil
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
13 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14 from MoinMoin.PageEditor import PageEditor
2407
ca02fd95fe59 "Fixed" PageEditor test.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2399
diff changeset
15 from MoinMoin._tests.common import gain_superuser_rights
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
16
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
17 class TestExpandVars(object):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
18 """PageEditor: testing page editor"""
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 _tests = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 # Variable, Expanded
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
23 ("@PAGE@", pagename),
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
24 ("em@PAGE@bedded", "em%sbedded" % pagename),
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
25 ("@NOVAR@", "@NOVAR@"),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 ("case@Page@sensitive", "case@Page@sensitive"),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
27 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
29 def setup_method(self, method):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30 self.page = PageEditor(self.request, self.pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 def testExpandVariables(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33 """ PageEditor: expand general variables """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 for var, expected in self._tests:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 result = self.page._expand_variables(var)
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
36 assert result == expected
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
39 class TestExpandUserName(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40 """ Base class for user name tests
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
41
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 Set user name during tests.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 variable = u'@USERNAME@'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
46
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
47 def setup_method(self, method):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 self.page = PageEditor(self.request, self.pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 self.savedName = self.request.user.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 self.request.user.name = self.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
52 def teardown_method(self, method):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 self.request.user.name = self.savedName
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
54
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
55 def expand(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 return self.page._expand_variables(self.variable)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
59 class TestExpandCamelCaseName(TestExpandUserName):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
60
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 name = u'UserName'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
62
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 def testExpandCamelCaseUserName(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 """ PageEditor: expand @USERNAME@ CamelCase """
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
65 assert self.expand() == self.name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
68 class TestExpandExtendedName(TestExpandUserName):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
69
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 name = u'user name'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
71
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
72 def testExtendedNamesEnabled(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
73 """ PageEditor: expand @USERNAME@ extended name - enabled """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 try:
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
75 config = self.TestConfig()
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
76 assert self.expand() == u'[[%s]]' % self.name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 del config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
79
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
80
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
81 class TestExpandMailto(TestExpandUserName):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 variable = u'@MAILTO@'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84 name = u'user name'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 email = 'user@example.com'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
87 def setup_method(self, method):
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
88 super(TestExpandMailto, self).setup_method(method)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
89 self.savedValid = self.request.user.valid
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90 self.request.user.valid = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 self.savedEmail = self.request.user.email
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 self.request.user.email = self.email
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
94 def teardown_method(self, method):
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
95 super(TestExpandMailto, self).teardown_method(method)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 self.request.user.valid = self.savedValid
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 self.request.user.email = self.savedEmail
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
98
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 def testMailto(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100 """ PageEditor: expand @MAILTO@ """
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
101 assert self.expand() == u'<<MailTo(%s)>>' % self.email
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
102
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
104 class TestExpandPrivateVariables(TestExpandUserName):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 variable = u'@ME@'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 name = u'AutoCreatedMoinMoinTemporaryTestUser'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 dictPage = name + '/MyDict'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 shouldDeleteTestPage = True
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
110
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
111 def setup_method(self, method):
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
112 super(TestExpandPrivateVariables, self).setup_method(method)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 self.savedValid = self.request.user.valid
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 self.request.user.valid = 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 self.createTestPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 self.deleteCaches()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
118 def teardown_method(self, method):
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
119 super(TestExpandPrivateVariables, self).teardown_method(method)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 self.request.user.valid = self.savedValid
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 self.deleteTestPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 def testPrivateVariables(self):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
124 """ PageEditor: expand user variables """
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
125 assert self.expand() == self.name
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 def createTestPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 """ Create temporary page, bypass logs, notification and backups
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
129
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130 TODO: this code is very fragile, any change in the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 implementation will break this test. Need to factor PageEditor
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 to make it possible to create page without loging and notifying.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 import os
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
135 path = self.dictPagePath()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 if os.path.exists(path):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 self.shouldDeleteTestPage = False
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
138 py.test.skip("%s exists. Won't overwrite exiting page" % self.dictPage)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140 os.mkdir(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 revisionsDir = os.path.join(path, 'revisions')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 os.mkdir(revisionsDir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 current = '00000001'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 text = u' ME:: %s\n' % self.name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 file(os.path.join(revisionsDir, current), 'w').write(text)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 except Exception, err:
2006
1339d6fdc4ff Changed tests to use py.test. Also changed the semantics a bit - the test wiki directory is only created freshly if it does not exist.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1918
diff changeset
148 py.test.skip("Can not be create test page: %s" % err)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
150 def deleteCaches(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
151 """ Force the wiki to scan the test page into the dicts """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 from MoinMoin import caching
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
153 caching.CacheEntry(self.request, 'wikidicts', 'dicts_groups', scope='wiki').remove()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
154 if hasattr(self.request, 'dicts'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155 del self.request.dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
156 if hasattr(self.request.cfg, 'DICTS_DATA'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
157 del self.request.cfg.DICTS_DATA
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 self.request.pages = {}
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
159
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
160 def deleteTestPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 """ Delete temporary page, bypass logs and notifications """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 if self.shouldDeleteTestPage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 import shutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
164 shutil.rmtree(self.dictPagePath(), True)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
165
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 def dictPagePath(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
167 page = Page(self.request, self.dictPage)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 return page.getPagePath(use_underlay=0, check_create=0)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
169
2397
a10ae31a6133 Test if page save really fails when PreSave event handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2286
diff changeset
170
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
171 class TestSave(object):
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
172
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
173 def setup_method(self, method):
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
174 self.old_handlers = self.request.cfg.event_handlers
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
175 gain_superuser_rights(self.request)
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
176
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
177 def teardown_method(self, method):
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
178 self.request.cfg.event_handlers = self.old_handlers
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
179
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
180 def testSaveAbort(self):
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
181 """Test if saveText() is interrupted if PagePreSave event handler returns Abort"""
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
182
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
183 def handler(event):
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
184 from MoinMoin.events import Abort
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
185 return Abort("This is just a test")
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
186
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
187 pagename = u'AutoCreatedMoinMoinTemporaryTestPageFortestSave'
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
188 testtext = u'ThisIsSomeStupidTestPageText!'
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2397
diff changeset
189
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
190 self.request.cfg.event_handlers = [handler]
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
191
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
192 page = Page(self.request, pagename)
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
193 if page.exists():
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
194 deleter = PageEditor(self.request, pagename)
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
195 deleter.deletePage()
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
196
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
197 editor = PageEditor(self.request, pagename)
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
198 editor.saveText(testtext, 0)
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
199
2487
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
200 print "PageEditor can't save a page if Abort is returned from PreSave event handlers"
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
201 page = Page(self.request, pagename)
509cde9e567f Fix test of Abort in PageEditor so that it restores the event handler list.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2448
diff changeset
202 assert page.body != testtext
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2415
diff changeset
203
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2415
diff changeset
204
2835
9c4c20145a1f test_PageEditor, test_events: skip broken test
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2834
diff changeset
205 class TestDictPageDeletion(object):
2834
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
206
2835
9c4c20145a1f test_PageEditor, test_events: skip broken test
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2834
diff changeset
207 def testCreateDictAndDeleteDictPage(self):
2834
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
208 """
2835
9c4c20145a1f test_PageEditor, test_events: skip broken test
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2834
diff changeset
209 simple test if it is possible to delete a Dict page after creation
2834
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
210 """
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
211 pagename = u'SomeDict'
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
212 page = PageEditor(self.request, pagename, do_editor_backup=0)
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
213 body = u"This is an example text"
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
214 page.saveText(body, 0)
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
215
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
216 success_i, result = page.deletePage()
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
217
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
218 expected = u'Page "SomeDict" was successfully deleted!'
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
219
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
220 assert result == expected
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
221
3042
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
222 class TestCopyPage(object):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
223
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
224 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
225 copy_pagename = u'AutoCreatedMoinMoinTemporaryCopyTestPage'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
226 shouldDeleteTestPage = True
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
227 text = u'Example'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
228
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
229 def setup_method(self, method):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
230 self.savedValid = self.request.user.valid
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
231 self.request.user.valid = 1
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
232
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
233 def teardown_method(self, method):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
234 self.request.user.valid = self.savedValid
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
235 self.deleteTestPage()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
236
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
237 def createTestPage(self):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
238 """ Create temporary page, bypass logs, notification and backups
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
239
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
240 TODO: this code is very fragile, any change in the
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
241 implementation will break this test. Need to factor PageEditor
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
242 to make it possible to create page without loging and notifying.
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
243 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
244 import os
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
245 path = Page(self.request, self.pagename).getPagePath(check_create=0)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
246 copy_path = Page(self.request, self.copy_pagename).getPagePath(check_create=0)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
247
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
248 if os.path.exists(path) or os.path.exists(copy_path):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
249 self.shouldDeleteTestPage = False
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
250 py.test.skip("%s or %s exists. Won't overwrite exiting page" % (self.pagename, self.copy_pagename))
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
251 try:
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
252 os.mkdir(path)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
253 revisionsDir = os.path.join(path, 'revisions')
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
254 os.mkdir(revisionsDir)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
255 current = '00000001'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
256 file(os.path.join(path, 'current'), 'w').write('%s\n' % current)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
257
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
258 file(os.path.join(revisionsDir, current), 'w').write(self.text)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
259 except Exception, err:
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
260 py.test.skip("Can not be create test page: %s" % err)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
261
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
262 def deleteTestPage(self):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
263 """ Delete temporary page, bypass logs and notifications """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
264 if self.shouldDeleteTestPage:
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
265 import shutil
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
266 shutil.rmtree(Page(self.request, self.pagename).getPagePath(), True)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
267 shutil.rmtree(Page(self.request, self.copy_pagename).getPagePath(), True)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
268
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
269 def test_copy_page(self):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
270 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
271 Tests copying a page without restricted acls
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
272 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
273 self.createTestPage()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
274 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
275 revision = Page(self.request, self.copy_pagename).current_rev()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
276 assert result and revision is 2
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
277
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
278 def test_copy_page_acl_read(self):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
279 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
280 Tests copying a page without write rights
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
281 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
282 self.text = u'#acl SomeUser:read,write,delete All:read\n'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
283 self.createTestPage()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
284 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
285 revision = Page(self.request, self.copy_pagename).current_rev()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
286 assert result and revision is 2
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
287
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
288 def test_copy_page_acl_no_read(self):
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
289 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
290 Tests copying a page without read rights
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
291 """
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
292 self.text = u'#acl SomeUser:read,write,delete All:\n'
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
293 self.createTestPage()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
294 result, msg = PageEditor(self.request, self.pagename).copyPage(self.copy_pagename)
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
295 revision = Page(self.request, self.copy_pagename).current_rev()
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
296 assert result and revision is 2
353739af70fa PageEditor: fixed copyPage for write restricted pages, tests added (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2836
diff changeset
297
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2415
diff changeset
298 coverage_modules = ['MoinMoin.PageEditor']
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
299