Back to index

plone3  3.1.7
test_RegistrationTool.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for RegistrationTool module.
00014 
00015 $Id: test_RegistrationTool.py 77113 2007-06-26 20:36:26Z yuppie $
00016 """
00017 
00018 import unittest
00019 from Testing import ZopeTestCase
00020 
00021 from Acquisition import Implicit
00022 from zope.testing.cleanup import cleanUp
00023 
00024 from Products.CMFCore.tests.base.testcase import RequestTest
00025 from Products.CMFDefault.testing import FunctionalLayer
00026 
00027 
00028 class FauxMembershipTool(Implicit):
00029 
00030     def getMemberById( self, username ):
00031         return None
00032 
00033 
00034 class RegistrationToolTests(RequestTest):
00035 
00036     def _getTargetClass(self):
00037         from Products.CMFDefault.RegistrationTool import RegistrationTool
00038 
00039         return RegistrationTool
00040 
00041     def _makeOne(self, *args, **kw):
00042         return self._getTargetClass()(*args, **kw)
00043 
00044     def tearDown(self):
00045         cleanUp()
00046         RequestTest.tearDown(self)
00047 
00048     def test_z2interfaces(self):
00049         from Interface.Verify import verifyClass
00050         from Products.CMFCore.interfaces.portal_registration \
00051                 import portal_registration as IRegistrationTool
00052 
00053         verifyClass(IRegistrationTool, self._getTargetClass())
00054 
00055     def test_z3interfaces(self):
00056         from zope.interface.verify import verifyClass
00057         from Products.CMFCore.interfaces import IRegistrationTool
00058 
00059         verifyClass(IRegistrationTool, self._getTargetClass())
00060 
00061     def test_spamcannon_collector_243( self ):
00062 
00063         INJECTED_HEADERS = """
00064 To:someone@example.com
00065 cc:another_victim@elsewhere.example.com
00066 From:someone@example.com
00067 Subject:Hosed by Spam Cannon!
00068 
00069 Spam, spam, spam
00070 """
00071 
00072         rtool = self._makeOne().__of__(self.app)
00073         self.app.portal_membership = FauxMembershipTool()
00074 
00075         props = { 'email' : INJECTED_HEADERS
00076                 , 'username' : 'username'
00077                 }
00078 
00079         result = rtool.testPropertiesValidity(props, None)
00080 
00081         self.failIf( result is None, 'Invalid e-mail passed inspection' )
00082 
00083 
00084 def test_suite():
00085     suite = unittest.TestSuite()
00086     suite.addTest(unittest.makeSuite(RegistrationToolTests))
00087     s = ZopeTestCase.FunctionalDocFileSuite('RegistrationTool.txt')
00088     s.layer = FunctionalLayer
00089     suite.addTest(s)
00090     return suite
00091 
00092 if __name__ == '__main__':
00093     from Products.CMFCore.testing import run
00094     run(test_suite())