Share this Page URL
Help

Chapter 42. Writing Functional Tests > Running Functional Tests - Pg. 285

Writing Functional Tests In the preceding code block, note the following: 285 · Lines 25­29: This is a perfect example of the helper methods that are often used in Zope's functional tests. It creates a ZPT Page content object called zptpage. To write the new object to the ZODB, you have to commit the transaction by using self.commit(). · Lines 31­48: To understand this test completely, it is helpful to be familiar with the way Zope 3 adds new objects and how the widgets create an HTML form. The + in the URL is the Add view for a folder. The path that follows is simply the factory ID of the content type (line 32). Instead of the factory ID, you sometimes also find the name of the object's Add view there. The form dictionary is another piece of information that must be carefully constructed. First, the field.expand.used and field.evaluateInlineCode.used keys are required, whether you want to activate expand and evaluateInlineCode or not. This is required by the cor- responding widgets. The add_input_name key contains the name the content object will re- ceive, and UPDATE_SUBMIT just tells the form generator that the form was actually submitted and action should be taken. Also note that each form entry representing a field has a field. prefix, which is added by the widgets mechanism. (You can find all these variable names by creating a ZPT page in the browser and looking at the HTML source for the names and values.) On line 42, you check whether the request was successful. Code 302 signals a redirect, and on lines 43­44 you check that you are redirected to the correct page. Now it is time to check in the ZODB to see whether the object has really been created and to ensure that all data has been set correctly. On line 46 you retrieve the object itself and conse- quently you check that the source is set correctly and the evaluateInlineCode flag was turned on (line 48), as the request demanded in the form (line 39). · Lines 50­63: Before you can test whether the data of a ZPT page can be edited correctly, you