annotate MoinMoin/_tests/test_user.py @ 3103:4ede355c6089

bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 23 Feb 2008 19:43:26 +0100
parents c61cd68592c2
children a7c1680aeaa0
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: utf-8 -*-
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.user Tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
5 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6 @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
7 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
9 import os
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
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 from MoinMoin import user, caching
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
13 from MoinMoin.util import filesys
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
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
15
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
16 class TestEncodePassword(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
17 """user: encode passwords tests"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
18
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 def testAscii(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 """user: encode ascii password"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21 # u'MoinMoin' and 'MoinMoin' should be encoded to same result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 expected = "{SHA}X+lk6KR7JuJEH43YnmettCwICdU="
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
23
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
24 result = user.encodePassword("MoinMoin")
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
25 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
26 result = user.encodePassword(u"MoinMoin")
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
27 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
28
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
29 def testUnicode(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30 """ user: encode unicode password """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
31 result = user.encodePassword(u'סיסמה סודית בהחלט') # Hebrew
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 expected = "{SHA}GvvkgYzv5MoF9Ljivv2oc81FmkE="
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
33 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
34
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
36 class TestLoginWithPassword(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 """user: login tests"""
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
39 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
40 # Save original user and cookie
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
41 self.saved_cookie = self.request.saved_cookie
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 self.saved_user = self.request.user
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
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 # Create anon user for the tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 self.request.saved_cookie = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 self.request.user = user.User(self.request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
48 # Prevent user list caching - we create and delete users too fast for that.
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
49 filesys.dcdisable()
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
50 self.user = None
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
51
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
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 """ Run after each test
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
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 Remove user and reset user listing cache.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
56 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 # Remove user file and user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 if self.user is not None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 path = self.user._User__filename()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 os.remove(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 except OSError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
64 del self.user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
65
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
66 # Restore original user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
67 self.request.saved_cookie = self.saved_cookie
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
68 self.request.user = self.saved_user
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 # Remove user name to id cache, or next test will fail
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
71 caching.CacheEntry(self.request, 'user', 'name2id', scope='wiki').remove()
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
72 try:
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
73 del self.request.cfg.cache.name2id
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
74 except:
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
75 pass
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
76
1801
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
77 # Prevent user list caching - we create and delete users too fast for that.
3369445b4aa8 move the dircache stuff to MoinMoin.util.filesys and disable it on win32
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
78 filesys.dcdisable()
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
79
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
80 def testAsciiPassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
81 """ user: login with ascii password """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
82 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 name = u'__Non Existent User Name__'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 self.createUser(name, password)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
86
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
87 # Try to "login"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
88 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
89 assert theUser.valid
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
90
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
91 def testUnicodePassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
92 """ user: login with non-ascii password """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
93 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94 name = u'__שם משתמש לא קיים__' # Hebrew
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 self.createUser(name, password)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
97
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 # Try to "login"
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
99 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
100 assert theUser.valid
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 def testOldNonAsciiPassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103 """ user: login with non-ascii password in pre 1.3 user file
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
104
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
105 When trying to login with an old non-ascii password in the user
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
106 file, utf-8 encoded password will not match. In this case, try
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107 all other encoding available on pre 1.3 before failing.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110 # Use iso charset to create user with old enc_password, as if
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 # the user file was migrated from pre 1.3 wiki.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 name = u'__Jürgen Herman__'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 self.createUser(name, password, charset='iso-8859-1')
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
115
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
116 # Try to "login"
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
118 assert theUser.valid
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 def testReplaceOldNonAsciiPassword(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 """ user: login replace old non-ascii password in pre 1.3 user file
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
122
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
123 When trying to login with an old non-ascii password in the user
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 file, the password hash should be replaced with new utf-8 hash.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 # Create test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127 # Use iso charset to create user with old enc_password, as if
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 # the user file was migrated from pre 1.3 wiki.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 name = u'__Jürgen Herman__'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130 password = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 self.createUser(name, password, charset='iso-8859-1')
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
132 # Login - this should replace the old password in the user file
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 theUser = user.User(self.request, name=name, password=password)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
134 # Login again - the password should be new unicode password
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
135 expected = user.encodePassword(password)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
136 theUser = user.User(self.request, name=name, password=password)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
137 assert theUser.enc_password == expected
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
138
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
139 def testSubscriptionSubscribedPage(self):
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
140 """ user: tests isSubscribedTo """
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
141 pagename = u'HelpMiscellaneous'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
142 name = u'__Jürgen Herman__'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
143 password = name
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
144 self.createUser(name, password, charset='iso-8859-1')
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
145 # Login - this should replace the old password in the user file
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
146 theUser = user.User(self.request, name=name, password=password)
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
147 theUser.subscribe(pagename)
2827
c61cd68592c2 test_user: fixed indenting
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2818
diff changeset
148 assert theUser.isSubscribedTo([pagename]) # list(!) of pages to check
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
149
2038
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
150 def testSubscriptionSubPage(self):
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
151 """ user: tests isSubscribedTo on a subpage """
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
152 pagename = u'HelpMiscellaneous'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
153 testPagename = u'HelpMiscellaneous/FrequentlyAskedQuestions'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
154 name = u'__Jürgen Herman__'
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
155 password = name
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
156 self.createUser(name, password, charset='iso-8859-1')
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
157 # Login - this should replace the old password in the user file
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
158 theUser = user.User(self.request, name=name, password=password)
bd83616af43a test_user: tests for subscription of pages and subpages
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2006
diff changeset
159 theUser.subscribe(pagename)
2827
c61cd68592c2 test_user: fixed indenting
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2818
diff changeset
160 assert not theUser.isSubscribedTo([testPagename]) # list(!) of pages to check
3103
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
161
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
162 def testRenameUser(self):
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
163 """ create user and then rename user and check
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
164 if the old username is removed from the cache name2id
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
165 """
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
166 # Create test user
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
167 # Use iso charset to create user with old enc_password, as if
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
168 # the user file was migrated from pre 1.3 wiki.
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
169 name = u'__Some Name__'
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
170 password = name
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
171 self.createUser(name, password)
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
172 # Login - this should replace the old password in the user file
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
173 theUser = user.User(self.request, name=name)
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
174 # Rename user
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
175 theUser.name = u'__SomeName__'
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
176 theUser.save()
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
177 theUser = user.User(self.request, name=name, password=password)
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
178
4ede355c6089 bugfix for renaming of users (/MoinMoinBugs/RenamingUserAllowsOldUsernameToLogin) (ported from 1.6)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2827
diff changeset
179 assert not theUser.exists()
2165
eed1c7da25eb test_user: fix wrong subscription tests and a few other problems
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
180
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
181 # Helpers ---------------------------------------------------------
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
182
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 def createUser(self, name, password, charset='utf-8'):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
184 """ helper to create test user
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2165
diff changeset
185
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
186 charset is used to create user with pre 1.3 password hash
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
187 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
188 # Hack self.request form to contain the password
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
189 self.request.form['password'] = [password]
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
190
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
191 # Create user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
192 self.user = user.User(self.request)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
193 self.user.name = name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
194 self.user.enc_password = user.encodePassword(password, charset=charset)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
195
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
196 # Validate that we are not modifying existing user data file!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
197 if self.user.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
198 self.user = None
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
199 py.test.skip("Test user exists, will not override existing user data file!")
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
200
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
201 # Save test user
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
202 self.user.save()
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
203
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
204 # Validate user creation
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
205 if not self.user.exists():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
206 self.user = None
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
207 py.test.skip("Can't create test user")
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
208
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
209
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
210 class TestGroupName(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
211
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
212 def setUp(self):
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
213 self.config = self.TestConfig(page_group_regex=r'.+Group')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
214
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
215 def tearDown(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216 del self.config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
217
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
218 import re
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219 group = re.compile(r'.+Group', re.UNICODE)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
220
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
221 def testGroupNames(self):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
222 """ user: isValidName: reject group names """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
223 test = u'AdminGroup'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 assert self.group.search(test)
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
225 assert not user.isValidName(self.request, test)
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
226
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
227
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
228 class TestIsValidName(object):
892
9931a09387b0 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 682
diff changeset
229
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
230 def testNonAlnumCharacters(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
231 """ user: isValidName: reject unicode non alpha numeric characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
232
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
233 : and , used in acl rules, we might add more characters to the syntax.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
234 """
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
235 invalid = u'! # $ % ^ & * ( ) = + , : ; " | ~ / \\ \u0000 \u202a'.split()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
236 base = u'User%sName'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
237 for c in invalid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
238 name = base % c
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
239 assert not user.isValidName(self.request, name)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
240
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
241 def testWhitespace(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
242 """ user: isValidName: reject leading, trailing or multiple whitespace """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
243 cases = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
244 u' User Name',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
245 u'User Name ',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246 u'User Name',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
248 for test in cases:
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
249 assert not user.isValidName(self.request, test)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
250
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
251 def testValid(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
252 """ user: isValidName: accept names in any language, with spaces """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
253 cases = (
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
254 u'Jürgen Hermann', # German
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
255 u'ניר סופר', # Hebrew
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
256 u'CamelCase', # Good old camel case
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
257 u'가각간갇갈 갉갊감 갬갯걀갼' # Hangul (gibberish)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
258 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
259 for test in cases:
2818
7fceb3588211 tests: convert user tests to py.test, fix tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
260 assert user.isValidName(self.request, test)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
261
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
262
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
263 coverage_modules = ['MoinMoin.user']
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
264