[Checkins]
SVN: Sandbox/philikon/five.publication/trunk/five/publication/
First round of legacy tests
Philipp von Weitershausen
philikon at philikon.de
Fri Aug 3 19:45:55 EDT 2007
Log message for revision 78571:
First round of legacy tests
Changed:
U Sandbox/philikon/five.publication/trunk/five/publication/request.py
A Sandbox/philikon/five.publication/trunk/five/publication/tests/
A Sandbox/philikon/five.publication/trunk/five/publication/tests/__init__.py
A Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py
-=-
Modified: Sandbox/philikon/five.publication/trunk/five/publication/request.py
===================================================================
--- Sandbox/philikon/five.publication/trunk/five/publication/request.py 2007-08-03 22:21:14 UTC (rev 78570)
+++ Sandbox/philikon/five.publication/trunk/five/publication/request.py 2007-08-03 23:45:54 UTC (rev 78571)
@@ -40,8 +40,10 @@
match = URLmatch(key)
if match is not None:
pathonly, n = match.groups()
- # XXX is this correct?
- return self.getURL(int(n), pathonly)
+ try:
+ return self.getURL(int(n), bool(pathonly))
+ except IndexError:
+ raise KeyError(key)
# support BASEn, BASEPATHn
if key.startswith('BASE'):
@@ -50,7 +52,7 @@
if match is not None:
pathonly, n = match.groups()
# XXX I have no clue what to return here
- return self.getURL(int(n), pathonly)
+ return self.getURL(int(n)-1, bool(pathonly))
# support BODY
#XXX
Added: Sandbox/philikon/five.publication/trunk/five/publication/tests/__init__.py
===================================================================
--- Sandbox/philikon/five.publication/trunk/five/publication/tests/__init__.py (rev 0)
+++ Sandbox/philikon/five.publication/trunk/five/publication/tests/__init__.py 2007-08-03 23:45:54 UTC (rev 78571)
@@ -0,0 +1,2 @@
+# make this directory a package
+
Property changes on: Sandbox/philikon/five.publication/trunk/five/publication/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
+ native
Added: Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py
===================================================================
--- Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py (rev 0)
+++ Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py 2007-08-03 23:45:54 UTC (rev 78571)
@@ -0,0 +1,82 @@
+import unittest
+from StringIO import StringIO
+from ZPublisher.HTTPRequest import HTTPRequest
+from ZPublisher.HTTPResponse import HTTPResponse
+from five.publication.request import BrowserRequest
+
+environ = {
+ 'HTTP_COOKIE': 'tree-s=eJzT0MgpMOQKVneEA1dbda4CI67EkgJjLj0AeGcHew',
+ 'SCRIPT_NAME': '/john/mc/clane',
+ 'REQUEST_METHOD': 'GET',
+ 'PATH_INFO': '/john/mc/clane',
+ 'SERVER_PROTOCOL': 'HTTP/1.1',
+ 'QUERY_STRING': '',
+ 'CONTENT_LENGTH': '0',
+ 'SERVER_NAME': 'diehard.tv',
+ 'REMOTE_ADDR': '127.0.0.1',
+ 'SERVER_PORT': '8080',
+ 'CONTENT_TYPE': '',
+ 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
+ 'HTTP_CONNECTION': 'keep-alive',
+ 'HTTP_HOST': 'diehard.tv:8080',
+ 'HTTP_ACCEPT': 'application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,*/*;q=0.5',
+ 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5',
+ 'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
+ 'HTTP_KEEP_ALIVE': '300'
+ }
+
+class TestEnvironment(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def test_url(self):
+ request = self.makeRequest()
+ self.assertEqual(request['URL'], 'http://diehard.tv:8080/john/mc/clane')
+ self.assertEqual(request['URL0'], 'http://diehard.tv:8080/john/mc/clane')
+ self.assertEqual(request['URL1'], 'http://diehard.tv:8080/john/mc')
+ self.assertEqual(request['URL2'], 'http://diehard.tv:8080/john')
+ self.assertEqual(request['URL3'], 'http://diehard.tv:8080')
+ self.assertRaises(KeyError, request.get, 'URL4')
+
+ self.assertEqual(request['URLPATH0'], '/john/mc/clane')
+ self.assertEqual(request['URLPATH1'], '/john/mc')
+ self.assertEqual(request['URLPATH2'], '/john')
+ self.assertEqual(request['URLPATH3'], '')
+ self.assertRaises(KeyError, request.get, 'URLPATH4')
+
+ def test_base(self):
+ request = self.makeRequest()
+ self.assertEqual(request['BASE0'], 'http://diehard.tv:8080/john/mc')
+ self.assertEqual(request['BASE1'],
+ 'http://diehard.tv:8080/john/mc/clane')
+ self.assertRaises(KeyError, request.get, 'BASE2')
+
+ # XXX missng BASEPATHn
+
+ def test_response(self):
+ request = self.makeRequest()
+ self.assert_(request.get('RESPONSE') is not None)
+ self.assert_(getattr(request, 'RESPONSE', None) is not None)
+
+class FivePublicationTestEnvironment(TestEnvironment):
+
+ def makeRequest(self):
+ return BrowserRequest(StringIO(''), environ.copy())
+
+class ZPublisherTestEnvironment(TestEnvironment):
+
+ def makeRequest(self):
+ response = HTTPResponse()
+ request = HTTPRequest(StringIO(''), environ.copy(), response)
+ # This dance is sadly necessary to get the request's
+ # environment set up correctly
+ request['PARENTS'] = [object()]
+ request.traverse('')
+ return request
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(ZPublisherTestEnvironment))
+ suite.addTest(unittest.makeSuite(FivePublicationTestEnvironment))
+ return suite
Property changes on: Sandbox/philikon/five.publication/trunk/five/publication/tests/test_environment.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list