annotate MoinMoin/request/_tests/test_request.py @ 4027:0d6724b87856

Refactored TestConfig creation for py.test based unit tests. The method used before had multiple problems: config creation did not use inheritance (as it does when used the wiki in production). It also didn't do the post processing done in __init__ of Config class. Also, it first created the request with some default config, then created the TestConfig (but some stuff in request was not initialized correctly)... The new method now uses config inheritance in the same way as a production wiki does. The TestConfig instance is created in RequestBase __init__, it does not use sys.path any more to import the test wikiconfig, but does an absolute import from MoinMoin._tests.wikiconfig. TODO: * fix the failing test_pysupport.TestImportExisting.testExisting * auth tests are currently skipped because they need more work * find a better way than staticmethod(TestConfig)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 24 Aug 2008 02:01:34 +0200
parents 6162f334bd5a
children
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.module_tested Tests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
5 @copyright: 2003-2004 by Juergen Hermann <jh@web.de>,
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
6 2007 by 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
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
10 import py
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
11
2172
c15ec6a2c69e reduce number of failing tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
12 from MoinMoin import config, wikiutil
4027
0d6724b87856 Refactored TestConfig creation for py.test based unit tests.
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3213
diff changeset
13 from MoinMoin._tests import wikiconfig
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
15 from MoinMoin.request import HeadersAlreadySentException
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
16
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
17 class TestNormalizePagename(object):
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
18
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
19 def testPageInvalidChars(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
20 """ request: normalize pagename: remove invalid unicode chars
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
21
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
22 Assume the default setting
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
23 """
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
24 test = u'\u0000\u202a\u202b\u202c\u202d\u202e'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
25 expected = u''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
26 result = self.request.normalizePagename(test)
2823
7d97003c0f9a tests: convert request tests to py.test
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 testNormalizeSlashes(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
30 """ request: normalize pagename: normalize slashes """
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
31 cases = (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
32 (u'/////', u''),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
33 (u'/a', u'a'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
34 (u'a/', u'a'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
35 (u'a/////b/////c', u'a/b/c'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
36 (u'a b/////c d/////e f', u'a b/c d/e f'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
37 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
38 for test, expected in cases:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
39 result = self.request.normalizePagename(test)
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
40 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
41
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
42 def testNormalizeWhitespace(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
43 """ request: normalize pagename: normalize whitespace """
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
44 cases = (
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
45 (u' ', u''),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
46 (u' a', u'a'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47 (u'a ', u'a'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 (u'a b c', u'a b c'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49 (u'a b / c d / e f', u'a b/c d/e f'),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 # All 30 unicode spaces
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 (config.chars_spaces, u''),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 for test, expected in cases:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 result = self.request.normalizePagename(test)
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
55 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
56
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57 def testUnderscoreTestCase(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 """ request: normalize pagename: underscore convert to spaces and normalized
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 Underscores should convert to spaces, then spaces should be
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61 normalized, order is important!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
62 """
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
diff changeset
63 cases = (
895
eb465f4d2af0 fixed underscore issues in test_request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
64 (u' ', u''),
eb465f4d2af0 fixed underscore issues in test_request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
65 (u' a', u'a'),
eb465f4d2af0 fixed underscore issues in test_request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
66 (u'a ', u'a'),
eb465f4d2af0 fixed underscore issues in test_request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
67 (u'a b c', u'a b c'),
eb465f4d2af0 fixed underscore issues in test_request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 891
diff changeset
68 (u'a b / c d / e f', u'a b/c d/e f'),
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 )
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
70 for test, expected in cases:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 result = self.request.normalizePagename(test)
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
72 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
73
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
74
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
75 class TestGroupPages(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
77 def testNormalizeGroupName(self):
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
78 """ request: normalize pagename: restrict groups to alpha numeric Unicode
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2270
diff changeset
79
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
80 Spaces should normalize after invalid chars removed!
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
81 """
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
82 cases = (
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
83 # current acl chars
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
84 (u'Name,:Group', u'NameGroup'),
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
85 # remove than normalize spaces
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
86 (u'Name ! @ # $ % ^ & * ( ) + Group', u'Name Group'),
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
87 )
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
88 for test, expected in cases:
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
89 # validate we are testing valid group names
2172
c15ec6a2c69e reduce number of failing tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
90 if wikiutil.isGroupPage(self.request, test):
c15ec6a2c69e reduce number of failing tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2140
diff changeset
91 result = self.request.normalizePagename(test)
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
92 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
93
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
95 class TestHTTPDate(object):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 def testRFC1123Date(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 """ request: httpDate default rfc1123 """
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
99 assert self.request.httpDate(0) == 'Thu, 01 Jan 1970 00:00:00 GMT'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
100
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 def testRFC850Date(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 """ request: httpDate rfc850 """
2823
7d97003c0f9a tests: convert request tests to py.test
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2448
diff changeset
103 assert self.request.httpDate(0, rfc='850') == 'Thursday, 01-Jan-70 00:00:00 GMT'
891
ba1b39629510 some whitespace cleanup in the tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 0
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
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
106 class TestHTTPHeaders(object):
2893
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
107 std_headers = ['Status: 200 OK', 'Content-type: text/html; charset=%s' % config.charset]
2894
f009ead62bfd PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2893
diff changeset
108
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
109 def setup_method(self, method):
2935
3670e156ec1a request: use sent_headers rather than sent_headers_trace
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2934
diff changeset
110 self.request.sent_headers = None
2894
f009ead62bfd PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2893
diff changeset
111
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
112 def testAutoAddStdHeaders(self):
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
113 """ test if the usual headers get auto-added if not specified """
2893
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
114 headers_out = self.request.emit_http_headers(testing=True)
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
115 assert headers_out == self.std_headers
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
116
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
117 def testHeadersOnlyOnce(self):
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
118 """ test if trying to call emit_http_headers multiple times raises an exception """
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
119 self.request.emit_http_headers(testing=True)
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
120 py.test.raises(HeadersAlreadySentException, self.request.emit_http_headers, [], {'testing': True})
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
121
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
122 def testDuplicateHeadersIgnored(self):
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
123 """ test if duplicate headers get ignored """
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
124 headers_in = self.std_headers + ['Status: 500 Server Error']
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
125 headers_expected = self.std_headers
2893
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
126 headers_out = self.request.emit_http_headers(headers_in, testing=True)
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
127 assert headers_out == headers_expected
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
128
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
129 def testListHeaders(self):
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
130 """ test if header values get merged into a list for headers supporting it """
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
131 headers_in = self.std_headers + ['Vary: aaa', 'vary: bbb']
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
132 headers_expected = self.std_headers + ['Vary: aaa, bbb']
2893
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
133 headers_out = self.request.emit_http_headers(headers_in, testing=True)
408b301a5e44 emit_http_headers tests: fixed (never call functions with side-effects in assert, because they get executed twice)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2892
diff changeset
134 assert headers_out == headers_expected
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2823
diff changeset
135
2448
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
136 coverage_modules = ['MoinMoin.request']
c9949c55ff5e add coverage_modules attribute for coverage testing
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
137