Back to index

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

List of all members.

Public Member Functions

def afterSetUp
def testCreateObject
def testCreateNonGloballyAllowedObject
def testUnauthorizedToViewEditForm
def testUnauthorizedToViewEditFormOfNonFactoryObject
def testCreateObjectByDocumentEdit
def testUnauthorizedToCreateObjectByDocumentEdit
def setRequestMethod
def getAuthenticator
def setupAuthenticator

Public Attributes

 folder_url
 folder_path
 basic_auth
 factory

Detailed Description

Weeee, functional tests

Definition at line 225 of file testPortalFactory.py.


Member Function Documentation

Definition at line 228 of file testPortalFactory.py.

00228 
00229     def afterSetUp(self):
00230         self.folder_url = self.folder.absolute_url()
00231         self.folder_path = '/%s' % self.folder.absolute_url(1)
00232         self.basic_auth = '%s:%s' % (default_user, default_password)
00233         # We want 401 responses, not redirects to a login page
00234         plugins = self.portal.acl_users.plugins
00235         plugins.deactivatePlugin( IChallengePlugin, 'credentials_cookie_auth')
00236 
00237         # Enable portal_factory for Document type
00238         self.factory = self.portal.portal_factory
00239         self.factory.manage_setPortalFactoryTypes(listOfTypeIds=['Document'])

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 259 of file testPortalFactory.py.

00259 
00260     def testCreateNonGloballyAllowedObject(self):
00261         # TempFolder allows to create all portal types
00262         self.portal.portal_types.Document.manage_changeProperties(global_allow=0)
00263         response = self.publish(self.folder_path +
00264                                 '/createObject?type_name=Document',
00265                                 self.basic_auth)
00266 
00267         self.assertEqual(response.getStatus(), 302) # Redirect to document_edit_form
00268 
00269         # The redirect URL should contain the factory parts
00270         location = response.getHeader('Location')
00271         self.failUnless(location.startswith(self.folder_url+'/portal_factory/Document/'))
00272         self.failUnless(location.endswith('/edit'))
00273 
00274         # Perform the redirect
00275         edit_form_path = location[len(self.app.REQUEST.SERVER_URL):]
00276         response = self.publish(edit_form_path, self.basic_auth)
00277         self.assertEqual(response.getStatus(), 200) # OK

Definition at line 240 of file testPortalFactory.py.

00240 
00241     def testCreateObject(self):
00242         # createObject script should make a temp object
00243         response = self.publish(self.folder_path +
00244                                 '/createObject?type_name=Document',
00245                                 self.basic_auth)
00246 
00247         self.assertEqual(response.getStatus(), 302) # Redirect to document_edit_form
00248 
00249         # The redirect URL should contain the factory parts
00250         location = response.getHeader('Location')
00251         self.failUnless(location.startswith(self.folder_url+'/portal_factory/Document/'))
00252         # CMFFormController redirects should not do alias translation
00253         self.failUnless(location.endswith('/edit'))
00254 
00255         # Perform the redirect
00256         edit_form_path = location[len(self.app.REQUEST.SERVER_URL):]
00257         response = self.publish(edit_form_path, self.basic_auth)
00258         self.assertEqual(response.getStatus(), 200) # OK

Definition at line 300 of file testPortalFactory.py.

00300 
00301     def testCreateObjectByDocumentEdit(self):
00302         # document_edit should create the real object
00303         response = self.publish(self.folder_path +
00304             '/portal_factory/Document/tmp_id/document_edit?id=foo&title=Foo&text_format=plain&text=',
00305             self.basic_auth)
00306 
00307         self.assertEqual(response.getStatus(), 302) # Redirect to document_view
00308         viewAction = self.portal.portal_types['Document'].getActionInfo('object/view', self.folder.foo)['url']
00309         self.failUnless(response.getHeader('Location').startswith(viewAction))
00310 
00311         self.failUnless('foo' in self.folder.objectIds())
00312         self.assertEqual(self.folder.foo.Title(), 'Foo')
00313         self.assertEqual(self.folder.foo.get_local_roles_for_userid(default_user), ('Owner',))

Definition at line 314 of file testPortalFactory.py.

00314 
00315     def testUnauthorizedToCreateObjectByDocumentEdit(self):
00316         # Anonymous should not be able to create the real object
00317         response = self.publish(self.folder_path +
00318             '/portal_factory/Document/tmp_id/document_edit?id=foo&title=Foo&text_format=plain&text=',
00319             ) # No basic auth info
00320 
00321         self.assertEqual(response.getStatus(), 401) # Unauthorized
00322 

Definition at line 278 of file testPortalFactory.py.

00278 
00279     def testUnauthorizedToViewEditForm(self):
00280         # Anonymous should not be able to see document_edit_form
00281         response = self.publish(self.folder_path +
00282                                 '/createObject?type_name=Document',
00283                                 ) # No basic out info
00284         # We got redirected to the factory
00285         self.assertEqual(response.getStatus(), 302)
00286         newpath = response.getHeader('location')
00287         proto, host, path, query, fragment = urlparse.urlsplit(newpath)
00288         # Let's follow it
00289         response = self.publish(path)
00290         # And we are forbidden
00291         self.assertEqual(response.getStatus(), 401) # Unauthorized

Definition at line 292 of file testPortalFactory.py.

00292 
00293     def testUnauthorizedToViewEditFormOfNonFactoryObject(self):
00294         # Anonymous should not be able to see newsitem_edit_form
00295         response = self.publish(self.folder_path +
00296                                 '/createObject?type_name=News%20Item',
00297                                 ) # No basic out info
00298 
00299         self.assertEqual(response.getStatus(), 401) # Unauthorized


Member Data Documentation

Definition at line 231 of file testPortalFactory.py.

Definition at line 237 of file testPortalFactory.py.

Definition at line 230 of file testPortalFactory.py.

Definition at line 229 of file testPortalFactory.py.


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