comparison MoinMoin/_tests/test_request.py @ 0:77665d8e2254

tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0 (automatically generated log message) imported from: moin--main--1.5--base-0
author Thomas Waldmann <tw-public@gmx.de>
date Thu, 22 Sep 2005 15:09:50 +0000
parents
children ba1b39629510
comparison
equal deleted inserted replaced
-1:000000000000 0:77665d8e2254
1 # -*- coding: utf-8 -*-
2 """
3 MoinMoin - MoinMoin.module_tested Tests
4
5 Module names must start with 'test_' to be included in the tests.
6
7 @copyright: 2003-2004 by Jürgen Hermann <jh@web.de>
8 @license: GNU GPL, see COPYING for details.
9 """
10
11 import unittest
12 from MoinMoin._tests import TestConfig
13 from MoinMoin import config
14
15 class NormalizePagenameTestCase(unittest.TestCase):
16
17 def testPageInvalidChars(self):
18 """ request: normalize pagename: remove invalid unicode chars
19
20 Assume the default setting
21 """
22 test = u'\u0000\u202a\u202b\u202c\u202d\u202e'
23 expected = u''
24 result = self.request.normalizePagename(test)
25 self.assertEqual(result, expected,
26 ('Expected "%(expected)s" but got "%(result)s"') % locals())
27
28 def testNormalizeSlashes(self):
29 """ request: normalize pagename: normalize slashes """
30 cases = (
31 (u'/////', u''),
32 (u'/a', u'a'),
33 (u'a/', u'a'),
34 (u'a/////b/////c', u'a/b/c'),
35 (u'a b/////c d/////e f', u'a b/c d/e f'),
36 )
37 for test, expected in cases:
38 result = self.request.normalizePagename(test)
39 self.assertEqual(result, expected,
40 ('Expected "%(expected)s" but got "%(result)s"') %
41 locals())
42
43 def testNormalizeWhitespace(self):
44 """ request: normalize pagename: normalize whitespace """
45 cases = (
46 (u' ', u''),
47 (u' a', u'a'),
48 (u'a ', u'a'),
49 (u'a b c', u'a b c'),
50 (u'a b / c d / e f', u'a b/c d/e f'),
51 # All 30 unicode spaces
52 (config.chars_spaces, u''),
53 )
54 for test, expected in cases:
55 result = self.request.normalizePagename(test)
56 self.assertEqual(result, expected,
57 ('Expected "%(expected)s" but got "%(result)s"') %
58 locals())
59
60 def testUnderscoreTestCase(self):
61 """ request: normalize pagename: underscore convert to spaces and normalized
62
63 Underscores should convert to spaces, then spaces should be
64 normalized, order is important!
65 """
66 cases = (
67 (u'_________', u''),
68 (u'__a', u'a'),
69 (u'a__', u'a'),
70 (u'a__b__c', u'a b c'),
71 (u'a__b__/__c__d__/__e__f', u'a b/c d/e f'),
72 )
73 for test, expected in cases:
74 result = self.request.normalizePagename(test)
75 self.assertEqual(result, expected,
76 ('Expected "%(expected)s" but got "%(result)s"') %
77 locals())
78
79
80 class GroupPagesTestCase(unittest.TestCase):
81
82 def setUp(self):
83 self.config = TestConfig(self.request,
84 page_group_regex = r'.+Group')
85
86 def tearDown(self):
87 del self.config
88
89 def testNormalizeGroupName(self):
90 """ request: normalize pagename: restrict groups to alpha numeric Unicode
91
92 Spaces should normalize after invalid chars removed!
93 """
94 import re
95 group = re.compile(r'.+Group', re.UNICODE)
96 cases = (
97 # current acl chars
98 (u'Name,:Group', u'NameGroup'),
99 # remove than normalize spaces
100 (u'Name ! @ # $ % ^ & * ( ) + Group', u'Name Group'),
101 )
102 for test, expected in cases:
103 # validate we are testing valid group names
104 assert group.search(test)
105 result = self.request.normalizePagename(test)
106 self.assertEqual(result, expected,
107 ('Expected "%(expected)s" but got "%(result)s"') %
108 locals())
109
110
111 class HTTPDateTests(unittest.TestCase):
112
113 def testRFC1123Date(self):
114 """ request: httpDate default rfc1123 """
115 self.failUnlessEqual(self.request.httpDate(0),
116 'Thu, 01 Jan 1970 00:00:00 GMT',
117 'wrong date string')
118
119 def testRFC850Date(self):
120 """ request: httpDate rfc850 """
121 self.failUnlessEqual(self.request.httpDate(0, rfc='850'),
122 'Thursday, 01-Jan-70 00:00:00 GMT',
123 'wrong date string')
124
125
126 class GetPageNameFromQueryString(unittest.TestCase):
127 """ Test urls like http://netloc/wiki?pagename """
128
129 def setUp(self):
130 self.savedQuery = self.request.query_string
131
132 def tearDown(self):
133 self.request.query_string = self.savedQuery
134
135 def testAscii(self):
136 """ request: getPageNameFromQueryString: ascii """
137 name = expected = u'page name'
138 self.runTest(name, expected)
139
140 def testNonAscii(self):
141 """ request: getPageNameFromQueryString: non ascii """
142 name = expected = u'דף עברי'
143 self.runTest(name, expected)
144
145 def testUnderscore(self):
146 """ request: getPageNameFromQueryString: under_score """
147 name = u'page_name'
148 expected = u'page name'
149 self.runTest(name, expected)
150
151 def runTest(self, name, expected):
152 import urllib
153 # query as made by most browsers when you type the url into the
154 # location box.
155 query = urllib.quote(name.encode('utf-8'))
156 self.request.query_string = query
157 self.assertEqual(self.request.getPageNameFromQueryString(), expected)