annotate MoinMoin/_tests/test_PageEditor.py @ 3946:54fffaea4e22

Reapplied the changes done in 28442c70f757 to the page editor tests.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Fri, 15 Aug 2008 23:21:10 +0200
parents a86a245db9cb
children 0d6724b87856
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
3504
7ee94ad36708 tests: test page creation/deletion now done by helpers in MoinMoin._tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3503
diff changeset
15
7ee94ad36708 tests: test page creation/deletion now done by helpers in MoinMoin._tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3503
diff changeset
16 # TODO: check if and where we can use the helpers:
7ee94ad36708 tests: test page creation/deletion now done by helpers in MoinMoin._tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3503
diff changeset
17 from MoinMoin._tests import become_trusted, create_page, nuke_page
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
19 class TestExpandVars(object):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
20 """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
21 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 _tests = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 # Variable, Expanded
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
25 ("@PAGE@", pagename),
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
26 ("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
27 ("@NOVAR@", "@NOVAR@"),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
28 ("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
29 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
31 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
32 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
33
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 def testExpandVariables(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 """ 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
36 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
37 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
38 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
39
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
40
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
41 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
42 """ 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
43
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
44 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
45 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 pagename = u'AutoCreatedMoinMoinTemporaryTestPage'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 variable = u'@USERNAME@'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
48
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
49 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
50 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
51 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
52 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
53
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
54 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
55 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
56
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 def expand(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 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
59
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60
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
61 class TestExpandCamelCaseName(TestExpandUserName):
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 name = u'UserName'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
64
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65 def testExpandCamelCaseUserName(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 """ 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
67 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
68
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69
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
70 class TestExpandExtendedName(TestExpandUserName):
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 name = u'user name'
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
73
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74 def testExtendedNamesEnabled(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
75 """ 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
76 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
77 config = self.TestConfig()
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
78 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
79 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 del config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
82
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
83 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
84
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 variable = u'@MAILTO@'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
86 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
87 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
88
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
89 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
90 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
91 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
92 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
93 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
94 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
95
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
96 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
97 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
98 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
99 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
100
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 def testMailto(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 """ PageEditor: expand @MAILTO@ """
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
103 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
104
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105
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
106 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
107
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 variable = u'@ME@'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 name = u'AutoCreatedMoinMoinTemporaryTestUser'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110 dictPage = name + '/MyDict'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 shouldDeleteTestPage = True
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
112
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
113 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
114 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
115 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
116 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
117 self.createTestPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 self.deleteCaches()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
120 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
121 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
122 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
123 self.deleteTestPage()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125 def testPrivateVariables(self):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
126 """ 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
127 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
128
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 def createTestPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130 """ 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
131
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
132 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
133 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
134 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
135 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 import os
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
137 path = self.dictPagePath()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
138 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
139 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
140 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
141 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 os.mkdir(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 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
144 os.mkdir(revisionsDir)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 current = '00000001'
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(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
147 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
148 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
149 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
150 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
151
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 def deleteCaches(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 """ 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
154 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
155 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
156 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
157 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
158 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
159 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
160 self.request.pages = {}
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
161
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 def deleteTestPage(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 """ 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
164 if self.shouldDeleteTestPage:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
165 import shutil
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 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
167
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 def dictPagePath(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 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
170 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
171
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
172
2817
53adbd066e90 tests: convert PageEditor tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2726
diff changeset
173 class TestSave(object):
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
174
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
175 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
176 self.old_handlers = self.request.cfg.event_handlers
3503
383fda7ebfd1 tests: add some clarifications to become_trusted/become_valid, use become_trusted instead of become_superuser when it does not need superuser permissions
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3502
diff changeset
177 become_trusted(self.request)
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
178
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
179 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
180 self.request.cfg.event_handlers = self.old_handlers
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
181
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
182 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
183 """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
184
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
185 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
186 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
187 return Abort("This is just a test")
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
188
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
189 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
190 testtext = u'ThisIsSomeStupidTestPageText!'
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
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 self.request.cfg.event_handlers = [handler]
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
193
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
194 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
195 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
196 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
197 deleter.deletePage()
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
198
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
199 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
200 editor.saveText(testtext, 0)
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2487
diff changeset
201
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
202 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
203 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
204 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
205
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2415
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 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
208
2835
9c4c20145a1f test_PageEditor, test_events: skip broken test
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2834
diff changeset
209 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
210 """
2835
9c4c20145a1f test_PageEditor, test_events: skip broken test
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2834
diff changeset
211 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
212 """
3946
54fffaea4e22 Reapplied the changes done in 28442c70f757 to the page editor tests.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 3944
diff changeset
213 become_trusted(self.request)
2834
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
214 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
215 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
216 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
217 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
218
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
219 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
220
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
221 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
222
7d4a6e369a5a test_GetVal fixed, Creation Delete test for test_PageEditor
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2817
diff changeset
223 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
224
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
225 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
226
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 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
228 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
229 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
230 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
231
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 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
233 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
234 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
235
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 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
237 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
238 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
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 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
241 """ 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
242
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 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
244 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
245 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
246 """
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 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
248 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
249 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
250
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 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
252 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
253 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
254 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
255 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
256 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
257 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
258 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
259 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
260
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 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
262 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
263 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
264
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 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
266 """ 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
267 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
268 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
269 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
270 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
271
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 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
273 """
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 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
275 """
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 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
277 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
278 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
279 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
280
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 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
282 """
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 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
284 """
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 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
286 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
287 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
288 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
289 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
290
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 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
292 """
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 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
294 """
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 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
296 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
297 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
298 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
299 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
300
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2415
diff changeset
301 coverage_modules = ['MoinMoin.PageEditor']