Back to index

plone3  3.1.7
testPostOnly.py
Go to the documentation of this file.
00001 from unittest import TestCase
00002 from unittest import TestSuite
00003 from unittest import makeSuite
00004 from plone.protect.postonly import check
00005 from ZPublisher.HTTPRequest import HTTPRequest
00006 from zExceptions import Forbidden
00007 
00008 
00009 class PostOnlyTests(TestCase):
00010     def makeRequest(self, method):
00011         return HTTPRequest(None,
00012                            dict(REQUEST_METHOD=method,
00013                                 SERVER_PORT="80",
00014                                 SERVER_NAME="localhost"),
00015                            None)
00016 
00017     def testNonHTTPRequestAllowed(self):
00018         check("not a request")
00019 
00020     def testGETRequestForbidden(self):
00021         self.assertRaises(Forbidden, check, self.makeRequest("GET"))
00022 
00023     def testPOSTRequestAllowed(self):
00024         check(self.makeRequest("POST"))
00025 
00026 
00027 def test_suite():
00028     suite=TestSuite()
00029     suite.addTest(makeSuite(PostOnlyTests))
00030     return suite
00031