Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
Archetypes.tests.test_widgets.WidgetTests Class Reference
Inheritance diagram for Archetypes.tests.test_widgets.WidgetTests:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.tests.test_widgets.WidgetTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def afterSetUp
def beforeTearDown
def test_subject_keyword_widget
def test_subject_keyword_widget2
def test_appendtextarea_widget
def test_appendtextarea_timestamp_widget
def test_maxlength_textarea_widget
def test_rich_text_widget
def test_getBestIcon

Private Member Functions

def _test_widgets

Detailed Description

Definition at line 42 of file test_widgets.py.


Member Function Documentation

Definition at line 112 of file test_widgets.py.

00112 
00113     def _test_widgets(self):
00114         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00115 
00116         #Now render this doc in view and edit modes. If this works
00117         #then we have pretty decent assurance that things are working
00118         view = doc.base_view()
00119         edit = doc.base_edit()
00120 
00121         #No exceptions are good, parse the results more if you need to
00122         #I feel fine...

Here is the call graph for this function:

Definition at line 44 of file test_widgets.py.

00044 
00045     def afterSetUp(self):
00046         # XXX messing up with global vars is bad!
00047         global stub_text_file, stub_text_content, \
00048                stub_bin_file, stub_bin_content
00049         stub_text_file = open(os.path.join(PACKAGE_HOME, 'input', 'rest1.rst'))
00050         stub_text_content = stub_text_file.read()
00051         stub_text_file.seek(0)
00052         stub_bin_file = open(os.path.join(PACKAGE_HOME, 'input', 'word.doc'))
00053         stub_bin_content = stub_bin_file.read()
00054         stub_bin_file.seek(0)
00055         # Make SESSION var available
00056         self.app.REQUEST['SESSION'] = {}

Definition at line 57 of file test_widgets.py.

00057 
00058     def beforeTearDown(self):
00059         global stub_text_file, stub_bin_file
00060         stub_text_file.close()
00061         stub_bin_file.close()

This is a test I can write 

Definition at line 147 of file test_widgets.py.

00147 
00148     def test_appendtextarea_timestamp_widget(self):
00149         """ This is a test I can write """
00150         request = FakeRequest()
00151         mystring = str('<<<<this is a test string>>>>')
00152         
00153         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00154         field = doc.Schema()['textarea_appendonly_timestamp']
00155         widget = field.widget
00156         
00157         form = {'textarea_appendonly_timestamp':''}
00158         result = widget.process_form(doc, field, form)
00159         expected = '', {}
00160         self.assertEqual(expected, result)
00161         
00162         form = {'textarea_appendonly_timestamp': mystring}
00163         expected = mystring, {}
00164         result = widget.process_form(doc, field, form)
00165         self.assertEqual(expected, result)
00166 
00167         doc.Schema()[field.getName()].set(doc, mystring)
00168         form = {'textarea_appendonly_timestamp': mystring}
00169         expectation = mystring + '\n\n' + str(DateTime()) + widget.divider + mystring, {}
00170         results = widget.process_form(doc, field, form)
00171         
00172         # some magic (nightmares?) here for rectifying DateTime delay        
00173         result = results[0].split('\n\n')
00174         expected = expectation[0].split('\n\n')
00175         
00176         result[1] = result[1].split(' ')
00177         expected[1] = expected[1].split(' ')
00178         
00179         result[1][1] = expected[1][1][:-3]
00180         expected[1][1] = expected[1][1][:-3]
00181         
00182         self.assertEqual(expected, result)

Here is the call graph for this function:

Definition at line 123 of file test_widgets.py.

00123 
00124     def test_appendtextarea_widget(self):
00125         request = FakeRequest()
00126         mystring = str('<<<<this is a test string>>>>')
00127         
00128         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00129         field = doc.Schema()['textarea_appendonly']
00130         widget = field.widget
00131         
00132         form = {'textarea_appendonly':''}
00133         result = widget.process_form(doc, field, form)
00134         expected = '', {}
00135         self.assertEqual(expected, result)
00136         
00137         form = {'textarea_appendonly': mystring}
00138         expected = mystring, {}
00139         result = widget.process_form(doc, field, form)
00140         self.assertEqual(expected, result)
00141 
00142         doc.Schema()[field.getName()].set(doc, mystring)
00143         form = {'textarea_appendonly': mystring}
00144         expected = mystring + widget.divider + mystring, {}
00145         result = widget.process_form(doc, field, form)
00146         self.assertEqual(expected, result)

Here is the call graph for this function:

Definition at line 292 of file test_widgets.py.

00292 
00293     def test_getBestIcon(self):
00294         doc = makeContent(self.folder, 'SimpleType', id='doc')
00295         self.assertEqual(doc.getBestIcon(), 'txt.png')
00296 

Here is the call graph for this function:

Show me HOW to write this test and I will ~Spanky 

Definition at line 183 of file test_widgets.py.

00183 
00184     def test_maxlength_textarea_widget(self):
00185         """ Show me HOW to write this test and I will ~Spanky """
00186         
00187         request = FakeRequest()
00188         mystring = str('The little black dog jumped over the sleeping Moose')
00189         
00190         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00191         field = doc.Schema()['textarea_maxlength']
00192         widget = field.widget
00193         
00194         form = {'textarea_maxlength':''}
00195         result = widget.process_form(doc, field, form)
00196         expected = '', {}
00197         self.assertEqual(expected, result)
00198         
00199         form = {'textarea_maxlength': mystring}
00200         expected = mystring, {}
00201         result = widget.process_form(doc, field, form)
00202         self.assertEqual(expected, result)
00203 
00204         doc.Schema()[field.getName()].set(doc, mystring)
00205         form = {'textarea_maxlength': mystring}
00206         expected = 'The little black dog', {}
00207         result = widget.process_form(doc, field, form)
00208         #self.assertEqual(expected, result)
00209 

Here is the call graph for this function:

Definition at line 210 of file test_widgets.py.

00210 
00211     def test_rich_text_widget(self):
00212         request = FakeRequest()
00213         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00214         field = doc.Schema()['richtextfield']
00215         widget = field.widget
00216         form = {'richtextfield_text_format':'text/x-rst',
00217                 'richtextfield_file':stub_bin_file,
00218                 'richtextfield':'',
00219                 }
00220         expected = stub_bin_file, {}
00221         result = widget.process_form(doc, field, form)
00222         self.assertEqual(expected, result)
00223 
00224         form = {'richtextfield_text_format':'text/x-rst',
00225                 'richtextfield_file':stub_bin_file,
00226                 'richtextfield':stub_text_file,
00227                 }
00228         expected = stub_bin_file, {}
00229         result = widget.process_form(doc, field, form)
00230         self.assertEqual(expected, result)
00231 
00232         form = {'richtextfield_text_format':'text/x-rst',
00233                 'richtextfield_file':stub_text_file,
00234                 'richtextfield':'',
00235                 }
00236         expected = stub_text_file, {}
00237         result = widget.process_form(doc, field, form)
00238         self.assertEqual(expected, result)
00239 
00240         form = {'richtextfield_text_format':'text/x-rst',
00241                 'richtextfield_file':stub_text_file,
00242                 'richtextfield':stub_text_content,
00243                 }
00244         expected = stub_text_file, {}
00245         result = widget.process_form(doc, field, form)
00246         self.assertEqual(expected, result)
00247 
00248 
00249         form = {'richtextfield_text_format':'text/x-rst',
00250                 'richtextfield_file':'',
00251                 'richtextfield':stub_text_content,
00252                 }
00253         expected = stub_text_content, {'mimetype':'text/x-rst'}
00254         result = widget.process_form(doc, field, form)
00255         self.assertEqual(expected, result)
00256 
00257         form = {'richtextfield_file':stub_text_file}
00258         request.form.update(form)
00259         doc.processForm(REQUEST=request)
00260         self.assertEqual(field.getContentType(doc), 'text/x-rst')
00261 
00262         # XXX: This makes wv-1.0.3 spin.
00263         #form = {'richtextfield_file':stub_bin_file}
00264         #request.form.update(form)
00265         #doc.processForm(REQUEST=request)
00266         #self.assertEqual(field.getContentType(doc), 'application/msword')
00267         #self.assertEqual(str(doc[field.getName()]), stub_bin_content)
00268 
00269         form = {'richtextfield_text_format':'text/x-rst',
00270                 'richtextfield_file':'',
00271                 'richtextfield':stub_text_content,
00272                 }
00273         expected = stub_text_content, {'mimetype':'text/x-rst'}
00274         result = widget.process_form(doc, field, form)
00275         self.assertEqual(expected, result)
00276 
00277         form = {'richtextfield_text_format':'',
00278                 'richtextfield_file':'',
00279                 'richtextfield':stub_text_content,
00280                 }
00281         expected = stub_text_content, {}
00282         result = widget.process_form(doc, field, form)
00283         self.assertEqual(expected, result)
00284 
00285         form = {'richtextfield_text_format':'text/plain',
00286                 'richtextfield_file':stub_text_file,
00287                 }
00288         request.form.update(form)
00289         doc.processForm(REQUEST=request)
00290         self.assertEqual(field.getContentType(doc), 'text/x-rst')
00291         self.assertEqual(str(doc[field.getName()]), stub_text_content)

Here is the call graph for this function:

Definition at line 62 of file test_widgets.py.

00062 
00063     def test_subject_keyword_widget(self):
00064         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00065         field = doc.Schema()['subject']
00066         widget = field.widget
00067         form = {'subject_keywords':['bla','ble'],
00068                 'subject_existing_keywords':['bli']
00069                 }
00070         expected = ['bla', 'ble', 'bli']
00071         result = widget.process_form(doc, field, form)
00072         result[0].sort()
00073         self.assertEqual(expected, result[0])
00074         form = {'subject_keywords':['bla'],
00075                 'subject_existing_keywords':['ble','bli']
00076                 }
00077         result = widget.process_form(doc, field, form)
00078         result[0].sort()
00079         self.assertEqual(expected, result[0])
00080         form = {'subject_keywords':[],
00081                 'subject_existing_keywords':['bla', 'ble','bli']
00082                 }
00083         result = widget.process_form(doc, field, form)
00084         result[0].sort()
00085         self.assertEqual(expected, result[0])
00086         form = {'subject_keywords':['bla', 'ble','bli'],
00087                 'subject_existing_keywords':['bla', 'ble','bli']
00088                 }
00089         result = widget.process_form(doc, field, form)
00090         result[0].sort()
00091         self.assertEqual(expected, result[0])
00092         form = {'subject_keywords':['bla', 'ble','bli'],
00093                 'subject_existing_keywords':[]
00094                 }
00095         result = widget.process_form(doc, field, form)
00096         result[0].sort()
00097         self.assertEqual(expected, result[0])

Here is the call graph for this function:

Definition at line 98 of file test_widgets.py.

00098 
00099     def test_subject_keyword_widget2(self):
00100         doc = makeContent(self.folder, portal_type='ComplexType', id='demodoc')
00101         field = doc.Schema()['selectionlinesfield3']
00102         widget = field.widget
00103         form = {'selectionlinesfield3':['bla','ble']}
00104         expected = ['bla', 'ble']
00105         result = widget.process_form(doc, field, form)
00106         result[0].sort()
00107         self.assertEqual(expected, result[0])
00108         form = {'selectionlinesfield3':'bla\nble'}
00109         result = widget.process_form(doc, field, form)
00110         result[0].sort()
00111         self.assertEqual(expected, result[0])

Here is the call graph for this function:


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