Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
Archetypes.tests.test_functional.TestFunctionalObjectCreation Class Reference
Inheritance diagram for Archetypes.tests.test_functional.TestFunctionalObjectCreation:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_functional.TestFunctionalObjectCreation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def setupCTR
def assertStatusEqual
def test_id_change_on_initial_edit
def test_id_change_with_non_auto_id
def test_id_change_with_without_marker
def test_id_change_with_appended_number
def test_update_schema_does_not_reset_creation_flag
def test_createObjectViaWebDAV
def test_createObjectInCodeDoesNotSetFlag

Public Attributes

 folder_url
 folder_path
 basic_auth
 owner_auth
 error_log

Detailed Description

Tests object renaming and creation

Definition at line 45 of file test_functional.py.


Member Function Documentation

Definition at line 48 of file test_functional.py.

00048 
00049     def afterSetUp(self):
00050         # basic data
00051         # Put dummy sdm and dummy SESSION object into REQUEST
00052         if 'session_data_manager' in self.app.objectIds():
00053             self.app._delObject('session_data_manager')
00054         self.app._setObject('session_data_manager', DummySessionDataManager())
00055         sdm = self.app.session_data_manager
00056         request = self.app.REQUEST
00057         request.set('SESSION', sdm.getSessionData())
00058 
00059         self.folder_url = self.folder.absolute_url()
00060         self.folder_path = '/%s' % self.folder.absolute_url(1)
00061         self.basic_auth = '%s:secret' % default_user
00062         self.owner_auth = '%s:secret' % portal_owner
00063         # We want 401 responses, not redirects to a login page
00064         if hasattr(self.portal.aq_base, 'cookie_authentication'):
00065             self.portal._delObject('cookie_authentication')
00066 
00067         # disable portal_factory as it's a nuisance here
00068         if hasattr(self.portal.aq_base, 'portal_factory'):
00069             self.portal.portal_factory.manage_setPortalFactoryTypes(listOfTypeIds=[])
00070 
00071         # error log
00072         from Products.SiteErrorLog.SiteErrorLog import temp_logs
00073         temp_logs.clear() # clean up log
00074         self.error_log = self.portal.error_log
00075         self.error_log._ignored_exceptions = ()
00076 
00077         self.setupCTR()

Helper method that uses the error log to output useful debug infos

Definition at line 91 of file test_functional.py.

00091 
00092     def assertStatusEqual(self, a, b, msg=''):
00093         """Helper method that uses the error log to output useful debug infos
00094         """
00095         now = time.time()
00096         if a != b:
00097             entries = self.error_log.getLogEntries()
00098             if entries:
00099                 msg = entries[0]['tb_text']
00100             else:
00101                 if not msg:
00102                     msg = 'no error log msg available'
00103                     self.failUnlessEqual(a, b)
00104         self.failUnlessEqual(a, b, msg)
        

Here is the caller graph for this function:

Definition at line 78 of file test_functional.py.

00078 
00079     def setupCTR(self):
00080         #Modify the CTR to point to SimpleType
00081         ctr = self.portal.content_type_registry
00082         if ctr.getPredicate('text'):
00083             # ATCT has a predict
00084             ctr.removePredicate('text')
00085         ctr.addPredicate('text', 'major_minor' )
00086         ctr.getPredicate('text' ).edit('text', '' )
00087         ctr.assignTypeName('text', 'DDocument')
00088         ctr.reorderPredicate('text', 0)
00089 
00090         return ctr

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 339 of file test_functional.py.

00339 
00340     def test_createObjectInCodeDoesNotSetFlag(self):
00341         # Using invokeFactory from code should not set the creation flag
00342 
00343         # Functional sets the method to GET, this isn't really a functional
00344         # test but is a special case for the previous tests, so we'll unset
00345         # the REQUEST_METHOD.
00346         self.app.REQUEST.set('REQUEST_METHOD', 'nonsense')
00347 
00348         self.folder.invokeFactory('DDocument','bogus_item')
00349         self.failUnless('bogus_item' in self.folder.objectIds())
00350         self.failIf(self.folder.bogus_item.checkCreationFlag())
00351 
00352         self.app.REQUEST.set('REQUEST_METHOD','GET')
00353 

Definition at line 325 of file test_functional.py.

00325 
00326     def test_createObjectViaWebDAV(self):
00327         # WebDAV upload should create new document without creation flag set
00328         response = self.publish(self.folder_path+'/new_html',
00329                                 env={'CONTENT_TYPE': 'text/html'},
00330                                 request_method='PUT',
00331                                 stdin=StringIO(html),
00332                                 basic=self.basic_auth)
00333 
00334         self.assertEqual(response.getStatus(), 201)
00335         self.failUnless('new_html' in self.folder.objectIds())
00336         self.assertEqual(self.folder.new_html.portal_type, 'DDocument')
00337         self.assertEqual(self.folder.new_html.getBody(), html)
00338         self.failIf(self.folder.new_html.checkCreationFlag())

Make sure Id is taken from title on initial edit and not otherwise

Definition at line 105 of file test_functional.py.

00105 
00106     def test_id_change_on_initial_edit(self):
00107         """Make sure Id is taken from title on initial edit and not otherwise"""
00108         # Make our content type use auto generated ids
00109         from Products.Archetypes.examples.DDocument import DDocument
00110         DDocument._at_rename_after_creation = True
00111 
00112         auto_id='DDocument.2005-07-12.3847392'
00113 
00114         # create an object with an autogenerated id
00115         response = self.publish(self.folder_path +
00116                                 '/invokeFactory?type_name=DDocument&id=%s'%auto_id,
00117                                 self.basic_auth)
00118         self.failUnless(auto_id in self.folder.objectIds())
00119         new_obj = getattr(self.folder, auto_id)
00120 
00121         # Perform the redirect
00122         edit_form_path = self.folder_path+'/%s/base_edit'%auto_id
00123         response = self.publish(edit_form_path, self.basic_auth)
00124 
00125         # XXX now lets test if http://plone.org/collector/4487 is present
00126         if  "base_edit.cpt" in self.portal.portal_skins.archetypes.objectIds():
00127             raise AttributeError, ("test_id_change_on_initial_edit "
00128                   "is expected to fail unless  http://plone.org/collector/4487 is fixed")
00129 
00130         self.assertStatusEqual(response.getStatus(), 200) # OK
00131 
00132         #Change the title
00133         obj_title = "New Title for Object"
00134         new_id = "new-title-for-object"
00135         new_obj_path = '/%s' % new_obj.absolute_url(1)
00136         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00137 
00138         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00139         self.assertStatusEqual(response.getStatus(), 302) # OK
00140         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00141         self.failUnlessEqual(new_obj.Title(),obj_title) # title is set
00142         self.failUnlessEqual(new_obj.getId(), new_id) # does id match
00143         new_title = "Second Title"
00144         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % ('/%s' % new_obj.absolute_url(1), new_title,), self.basic_auth) # Edit object
00145         self.assertStatusEqual(response.getStatus(), 302) # OK
00146         self.failUnlessEqual(new_obj.getId(), new_id) # id shouldn't have changed
00147 
00148         del DDocument._at_rename_after_creation

Here is the call graph for this function:

Definition at line 219 of file test_functional.py.

00219 
00220     def test_id_change_with_appended_number(self):
00221         # Make sure Id is taken from title on initial edit and not otherwise,
00222         # and that a number is appended to avoid duplicates
00223         # Make our content type use auto generated ids
00224         from Products.Archetypes.examples.DDocument import DDocument
00225         DDocument._at_rename_after_creation = True
00226     
00227         auto_id='DDocument.2005-07-12.3847392'
00228     
00229         # create an object with an autogenerated id
00230         response = self.publish(self.folder_path +
00231                                 '/invokeFactory?type_name=DDocument&id=%s'%auto_id,
00232                                 self.basic_auth)
00233         self.failUnless(auto_id in self.folder.objectIds())
00234         new_obj = getattr(self.folder, auto_id)
00235     
00236         # Perform the redirect
00237         edit_form_path = self.folder_path+'/%s/base_edit'%auto_id
00238         response = self.publish(edit_form_path, self.basic_auth)
00239     
00240         # XXX now lets test if http://plone.org/collector/4487 is present
00241         if  "base_edit.cpt" in self.portal.portal_skins.archetypes.objectIds():
00242             raise AttributeError, ("test_id_change_on_initial_edit "
00243                   "is expected to fail unless  http://plone.org/collector/4487 is fixed")
00244     
00245         self.assertStatusEqual(response.getStatus(), 200) # OK
00246     
00247         #Change the title
00248         obj_title = "New Title for Object"
00249         new_id = "new-title-for-object"
00250         new_obj_path = '/%s' % new_obj.absolute_url(1)
00251         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00252     
00253         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00254         self.assertStatusEqual(response.getStatus(), 302) # OK
00255         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00256         self.failUnlessEqual(new_obj.Title(),obj_title) # title is set
00257         self.failUnlessEqual(new_obj.getId(), new_id) # does id match
00258         new_title = "Second Title"
00259         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % ('/%s' % new_obj.absolute_url(1), new_title,), self.basic_auth) # Edit object
00260         self.assertStatusEqual(response.getStatus(), 302) # OK
00261         self.failUnlessEqual(new_obj.getId(), new_id) # id shouldn't have changed
00262         
00263         # Now do another document with the same title:
00264         auto_id='DDocument.2005-12-18.3847393'
00265     
00266         # create an object with an autogenerated id
00267         response = self.publish(self.folder_path +
00268                                 '/invokeFactory?type_name=DDocument&id=%s'%auto_id,
00269                                 self.basic_auth)
00270         self.failUnless(auto_id in self.folder.objectIds())
00271         new_obj = getattr(self.folder, auto_id)
00272     
00273         # Perform the redirect
00274         edit_form_path = self.folder_path+'/%s/base_edit'%auto_id
00275         response = self.publish(edit_form_path, self.basic_auth)
00276     
00277         self.assertStatusEqual(response.getStatus(), 200) # OK
00278     
00279         #Change the title
00280         obj_title = "New Title for Object"
00281         new_id = "new-title-for-object-1"
00282         new_obj_path = '/%s' % new_obj.absolute_url(1)
00283         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00284     
00285         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00286         self.assertStatusEqual(response.getStatus(), 302) # OK
00287         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00288         self.failUnlessEqual(new_obj.Title(),obj_title) # title is set
00289         self.failUnlessEqual(new_obj.getId(), new_id) # does id match
00290         new_title = "Second Title"
00291         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % ('/%s' % new_obj.absolute_url(1), new_title,), self.basic_auth) # Edit object
00292         self.assertStatusEqual(response.getStatus(), 302) # OK
00293         self.failUnlessEqual(new_obj.getId(), new_id) # id shouldn't have changed
00294     
00295         del DDocument._at_rename_after_creation
00296     
00297     
    

Here is the call graph for this function:

Make sure Id is only set when original id is autogenerated

Definition at line 149 of file test_functional.py.

00149 
00150     def test_id_change_with_non_auto_id(self):
00151         """Make sure Id is only set when original id is autogenerated"""
00152         # Make our content type use auto generated ids
00153         from Products.Archetypes.examples.DDocument import DDocument
00154         DDocument._at_rename_after_creation = True
00155     
00156         auto_id='orig_id'
00157     
00158         # create an object with an autogenerated id
00159         response = self.publish(self.folder_path +
00160                                 '/invokeFactory?type_name=DDocument&id=%s'%auto_id,
00161                                 self.basic_auth)
00162     
00163         # XXX now lets test if http://plone.org/collector/4487 is present
00164         if  "base_edit.cpt" in self.portal.portal_skins.archetypes.objectIds():
00165             raise AttributeError, ("test_id_change_with_non_auto_id "
00166                   "is expected to fail unless  http://plone.org/collector/4487 is fixed")
00167     
00168         self.failUnless(auto_id in self.folder.objectIds())
00169         new_obj = getattr(self.folder, auto_id)
00170     
00171         #Change the title
00172         obj_title = "New Title for Object"
00173         new_obj_path = '/%s' % new_obj.absolute_url(1)
00174         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00175     
00176         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00177         self.assertStatusEqual(response.getStatus(), 302) # OK
00178         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00179         self.failUnlessEqual(new_obj.Title(),obj_title) # title is set
00180         self.failUnlessEqual(new_obj.getId(), auto_id) # id should not have changed
00181     
00182         del DDocument._at_rename_after_creation
    

Here is the call graph for this function:

Definition at line 183 of file test_functional.py.

00183 
00184     def test_id_change_with_without_marker(self):
00185         # Id should not be changed unless _at_rename_after_creation is set
00186         # on the class.
00187         # Make our content type use auto generated ids
00188         from Products.Archetypes.examples.DDocument import DDocument
00189         try:
00190             del DDocument._at_rename_after_creation
00191         except (AttributeError, KeyError):
00192             pass
00193     
00194         auto_id='orig_id'
00195     
00196         # create an object with an autogenerated id
00197         response = self.publish(self.folder_path +
00198                                 '/invokeFactory?type_name=DDocument&id=%s'%auto_id,
00199                                 self.basic_auth)
00200     
00201         # XXX now lets test if http://plone.org/collector/4487 is present
00202         if  "base_edit.cpt" in self.portal.portal_skins.archetypes.objectIds():
00203             raise AttributeError, ("test_id_change_with_without_marker "
00204                   "is expected to fail unless  http://plone.org/collector/4487 is fixed")
00205     
00206         self.failUnless(auto_id in self.folder.objectIds())
00207         new_obj = getattr(self.folder, auto_id)
00208     
00209         #Change the title
00210         obj_title = "New Title for Object"
00211         new_obj_path = '/%s' % new_obj.absolute_url(1)
00212         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00213     
00214         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00215         self.assertStatusEqual(response.getStatus(), 302) # OK
00216         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00217         self.failUnlessEqual(new_obj.Title(),obj_title) # title is set
00218         self.failUnlessEqual(new_obj.getId(), auto_id) # id should not have changed
    

Here is the call graph for this function:

Definition at line 298 of file test_functional.py.

00298 
00299     def test_update_schema_does_not_reset_creation_flag(self):
00300         # This is functional so that we get a full request and set the flag
00301 
00302         # create an object with flag set
00303         response = self.publish(self.folder_path +
00304                               '/invokeFactory?type_name=DDocument&id=new_doc',
00305                               self.basic_auth)
00306         self.failUnless('new_doc' in self.folder.objectIds())
00307         new_obj = self.folder.new_doc
00308         self.failUnless(new_obj.checkCreationFlag()) # object is not yet edited
00309         obj_title = "New Title for Object"
00310         new_obj_path = '/%s' % new_obj.absolute_url(1)
00311         response = self.publish('%s/base_edit?form.submitted=1&title=%s&body=Blank' % (new_obj_path, obj_title,), self.basic_auth) # Edit object
00312 
00313         # now lets test if http://plone.org/collector/4487 is present
00314         if  "base_edit.cpt" in self.portal.portal_skins.archetypes.objectIds():
00315             raise AttributeError, ("test_update_schema_does_not_reset_creation_flag "
00316                   "is expected to fail unless  http://plone.org/collector/4487 is fixed")
00317 
00318         self.failIf(new_obj.checkCreationFlag()) # object is fully created
00319         # Now run the schema update
00320         req = self.app.REQUEST
00321         req.form['update_all']=True
00322         req.form['Archetypes.DDocument']=True
00323         self.portal.archetype_tool.manage_updateSchema(REQUEST=req)
00324         self.failIf(new_obj.checkCreationFlag())


Member Data Documentation

Definition at line 60 of file test_functional.py.

Definition at line 73 of file test_functional.py.

Definition at line 59 of file test_functional.py.

Definition at line 58 of file test_functional.py.

Definition at line 61 of file test_functional.py.


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