Back to index

plone3  3.1.7
base.py
Go to the documentation of this file.
00001 # Marshall: A framework for pluggable marshalling policies
00002 # Copyright (C) 2004-2006 Enfold Systems, LLC
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License as published by
00006 # the Free Software Foundation; either version 2 of the License, or
00007 # (at your option) any later version.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU General Public License
00015 # along with this program; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 #
00018 """
00019 $Id: test_export.py 2886 2004-08-25 03:51:04Z dreamcatcher $
00020 """
00021 
00022 if __name__ == '__main__':
00023     execfile(os.path.join(sys.path[0], 'framework.py'))
00024 
00025 import re
00026 import difflib
00027 
00028 # Load fixture
00029 from Testing import ZopeTestCase
00030 from Products.Archetypes.tests.atsitetestcase import ATSiteTestCase
00031 
00032 from AccessControl.SecurityManagement import newSecurityManager
00033 
00034 # Install our product
00035 ZopeTestCase.installProduct('Marshall')
00036 ZopeTestCase.installProduct('ATContentTypes')
00037 
00038 portal_owner = 'portal_owner'
00039 
00040 def normalize_tabs(s):
00041     s = re.sub(r"[ \t]+", " ", s)
00042     return s
00043 
00044 def normalize_space(s):
00045     s =  re.sub(r"[\r\n]+", r'\r\n', s)
00046     return s
00047 
00048 class BaseTest(ATSiteTestCase):
00049     """Base Test"""
00050 
00051     def loginPortalOwner(self):
00052         '''Use if - AND ONLY IF - you need to manipulate
00053         the portal object itself.
00054         '''
00055         uf = self.app.acl_users
00056         user = uf.getUserById(portal_owner)
00057         if not hasattr(user, 'aq_base'):
00058             user = user.__of__(uf)
00059         newSecurityManager(None, user)
00060 
00061     def compare(self, one, two):
00062         diff = difflib.ndiff(one.splitlines(), two.splitlines())
00063         diff = '\n'.join(list(diff))
00064         return diff
00065 
00066     def assertEqualsDiff(self, one, two, normalize=True):
00067         if normalize:
00068             one, two = normalize_tabs(one), normalize_tabs(two)
00069         one, two = normalize_space(one), normalize_space(two)
00070         self.failUnless(one.splitlines() == two.splitlines(),
00071                         self.compare(one, two))