Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
CMFPlone.tests.testPloneTool.TestPloneTool Class Reference
Inheritance diagram for CMFPlone.tests.testPloneTool.TestPloneTool:
Inheritance graph
[legend]
Collaboration diagram for CMFPlone.tests.testPloneTool.TestPloneTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def testvalidateSingleEmailAddress
def testvalidateEmailAddresses
def testEditFormatMetadataOfFile
def testEditFormatMetadataOfImage
def testNormalizeStringPunctuation
def testNormalizeStringFileExtensions
def testNormalizeStringIgnoredCharacters
def testNormalizeStringObject
def testNormalizeStringDangerousCharsInExtension
def testNormalizeStringRelaxedKeepsUppercaseAndSpaces
def testNormalizeStringRelaxedStripsDangerousChars
def testNormalizeStringRelaxedKeepsOtherSymbols
def testTypesToList
def setRequestMethod
def getAuthenticator
def setupAuthenticator

Public Attributes

 utils

Detailed Description

Definition at line 25 of file testPloneTool.py.


Member Function Documentation

Definition at line 27 of file testPloneTool.py.

00027 
00028     def afterSetUp(self):
00029         self.utils = self.portal.plone_utils

Definition at line 30 of file PloneTestCase.py.

00030 
00031     def getAuthenticator(self):
00032         tag = AuthenticatorView('context', 'request').authenticator()
00033         pattern = '<input .*name="(\w+)".*value="(\w+)"'
00034         return match(pattern, tag).groups()

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFPlone.tests.PloneTestCase.PloneTestCase.setRequestMethod (   self,
  method 
) [inherited]
This is a stub now, but in case you want to try
   something fancy on Your Branch (tm), put it here.

Definition at line 26 of file PloneTestCase.py.

00026 
00027     def setRequestMethod(self, method):
00028         self.app.REQUEST.set('REQUEST_METHOD', method)
00029         self.app.REQUEST.method = method

Here is the caller graph for this function:

Definition at line 35 of file PloneTestCase.py.

00035 
00036     def setupAuthenticator(self):
00037         name, token = self.getAuthenticator()
00038         self.app.REQUEST.form[name] = token
00039 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file testPloneTool.py.

00091 
00092     def testEditFormatMetadataOfFile(self):
00093         # Test fix for http://dev.plone.org/plone/ticket/1323
00094         # Fixed in CMFDefault.File, not Plone.
00095         self.folder.invokeFactory('File', id='file')
00096         self.folder.file.edit(file=dummy.File('foo.zip'))
00097         self.assertEqual(self.folder.file.Format(), 'application/zip')
00098         self.assertEqual(self.folder.file.getFile().content_type, 'application/zip')
00099         # Changing the format should be reflected in content_type property
00100         self.utils.editMetadata(self.folder.file, format='image/gif')
00101         self.assertEqual(self.folder.file.Format(), 'image/gif')
00102         self.assertEqual(self.folder.file.getFile().content_type, 'image/gif')

Definition at line 103 of file testPloneTool.py.

00103 
00104     def testEditFormatMetadataOfImage(self):
00105         # Test fix for http://dev.plone.org/plone/ticket/1323
00106         # Fixed in CMFDefault.Image, not Plone.
00107         self.folder.invokeFactory('Image', id='image')
00108         self.folder.image.edit(file=dummy.Image('foo.zip'))
00109         self.assertEqual(self.folder.image.Format(), 'application/zip')
00110         self.assertEqual(self.folder.image.getImage().content_type, 'application/zip')
00111         # Changing the format should be reflected in content_type property
00112         self.utils.editMetadata(self.folder.image, format='image/gif')
00113         self.assertEqual(self.folder.image.Format(), 'image/gif')
00114         self.assertEqual(self.folder.image.getImage().content_type, 'image/gif')

Definition at line 140 of file testPloneTool.py.

00140 
00141     def testNormalizeStringDangerousCharsInExtension(self):
00142         # Punctuation and spacing is removed and replaced by '-'
00143         self.assertEqual(self.utils.normalizeString("A String.a#b"),
00144                          'a-string-a-b')

Definition at line 122 of file testPloneTool.py.

00122 
00123     def testNormalizeStringFileExtensions(self):
00124         # If there is something that looks like a file extensions
00125         # it will be preserved.
00126         self.assertEqual(self.utils.normalizeString("this is a file.gif"),
00127                          'this-is-a-file.gif')
00128         self.assertEqual(self.utils.normalizeString("this is. also. a file.html"),
00129                          'this-is-also-a-file.html')

Definition at line 130 of file testPloneTool.py.

00130 
00131     def testNormalizeStringIgnoredCharacters(self):
00132         # Some characters should be ignored
00133         self.assertEqual(self.utils.normalizeString("test'test"), 'testtest')

Definition at line 134 of file testPloneTool.py.

00134 
00135     def testNormalizeStringObject(self):
00136         # Objects should be converted to strings using repr()
00137         self.assertEqual(self.utils.normalizeString(None), 'none')
00138         self.assertEqual(self.utils.normalizeString(True), 'true')
00139         self.assertEqual(self.utils.normalizeString(False), 'false')

Definition at line 115 of file testPloneTool.py.

00115 
00116     def testNormalizeStringPunctuation(self):
00117         # Punctuation and spacing is removed and replaced by '-'
00118         self.assertEqual(self.utils.normalizeString("a string with spaces"),
00119                          'a-string-with-spaces')
00120         self.assertEqual(self.utils.normalizeString("p.u,n;c(t)u!a@t#i$o%n"),
00121                          'p-u-n-c-t-u-a-t-i-o-n')

Definition at line 155 of file testPloneTool.py.

00155 
00156     def testNormalizeStringRelaxedKeepsOtherSymbols(self):
00157         # Punctuation and spacing is removed and replaced by '-'
00158         self.assertEqual(self.utils.normalizeString("A ?String&/\\.foo_#xx", relaxed=True),
00159                          'A -String-.foo_#xx')

Definition at line 145 of file testPloneTool.py.

00145 
00146     def testNormalizeStringRelaxedKeepsUppercaseAndSpaces(self):
00147         # Punctuation and spacing is removed and replaced by '-'
00148         self.assertEqual(self.utils.normalizeString("Capital Letters and Spaces", relaxed=True),
00149                          'Capital Letters and Spaces')

Definition at line 150 of file testPloneTool.py.

00150 
00151     def testNormalizeStringRelaxedStripsDangerousChars(self):
00152         # Punctuation and spacing is removed and replaced by '-'
00153         self.assertEqual(self.utils.normalizeString("A ?String&/\\foo.x!$#x", relaxed=True),
00154                          'A -String-foo.x-#x')

Definition at line 160 of file testPloneTool.py.

00160 
00161     def testTypesToList(self):
00162         # Make sure typesToList() returns the expected types
00163         wl = self.utils.typesToList()
00164         self.failUnless('Folder' in wl)
00165         self.failUnless('Large Plone Folder' in wl)
00166         self.failUnless('Topic' in wl)
00167         self.failIf('ATReferenceCriterion' in wl)
00168 

Definition at line 65 of file testPloneTool.py.

00065 
00066     def testvalidateEmailAddresses(self):
00067         # Any RFC 822 email address allowed and address list allowed
00068         val = self.utils.validateEmailAddresses
00069 
00070         validInputs = (
00071             # 'user',
00072             # 'user@example',
00073             'user@example.org',
00074             #'user@example.org\n user2',
00075             #'user@example.org\r user2',
00076             'user@example.org,\n user2@example.org',
00077             'user@example.org\n user2@example.org', # omitting comma is ok
00078             'USER@EXAMPLE.ORG,\n User2@Example.Org',
00079         )
00080         invalidInputs = (
00081             'user@example.org\n\nfoo', # double new lines
00082             'user@example.org\n\rfoo',
00083             'user@example.org\r\nfoo',
00084             'user@example.org\r\rfoo',
00085             #py stdlib bug? 'user@example.org\nuser2@example.org', # continuation line doesn't begin with white space
00086         )
00087         for address in validInputs:
00088             self.failUnless(val(address), '%s should validate' % address)
00089         for address in invalidInputs:
00090             self.failIf(val(address), '%s should fail' % address)

Definition at line 30 of file testPloneTool.py.

00030 
00031     def testvalidateSingleEmailAddress(self):
00032         # Any RFC 822 email address allowed, but address list must fail
00033         val = self.utils.validateSingleEmailAddress
00034         validInputs = (
00035             'user@example.org',
00036             'user@host.example.org',
00037             'm@t.nu',
00038             'USER@EXAMPLE.ORG',
00039             'USER@HOST.EXAMPLE.ORG',
00040             'USER@hoST.Example.Org',
00041         )
00042         invalidInputs = (
00043             'user@example.org, user2@example.org',   # only single address allowed
00044             'user@example.org,user2@example.org',
00045             'user@example.org\n\nfoo', # double new lines
00046             'user@example.org\n\rfoo',
00047             'user@example.org\r\nfoo',
00048             'user@example.org\r\rfoo',
00049             'user@example.org\nfoo@example.org', # only single address allowed, even if given one per line
00050             'user@example.org\nBcc: user@example.org',
00051             'user@example.org\nCc: user@example.org',
00052             'user@example.org\nSubject: Spam',
00053             # and a full email (note the missing ,!)
00054             'From: foo@example.org\n'
00055             'To: bar@example.org, spam@example.org\n'
00056             'Cc: egg@example.org\n'
00057             'Subject: Spam me plenty\n'
00058             'Spam Spam Spam\n'
00059             'I hate spam',
00060         )
00061         for address in validInputs:
00062             self.failUnless(val(address), '%s should validate' % address)
00063         for address in invalidInputs:
00064             self.failIf(val(address), '%s should fail' % address)


Member Data Documentation

Definition at line 28 of file testPloneTool.py.


The documentation for this class was generated from the following file: