Back to index

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

List of all members.

Public Member Functions

def afterSetUp
def makeDummy
def test_processing
def test_processing_fieldset
def test_get_size
def test_validation
def test_required
def test_required_empty_request
def test_static_vocabulary
def test_dynamic_vocabulary
def test_factory_vocabulary
def test_defaults

Public Attributes

 context

Private Member Functions

def _test_required

Private Attributes

 _dummy

Detailed Description

Definition at line 158 of file test_fields.py.


Member Function Documentation

def Archetypes.tests.test_fields.ProcessingTest._test_required (   self,
  request 
) [private]

Definition at line 235 of file test_fields.py.

00235 
00236     def _test_required(self, request):
00237         dummy = self.makeDummy()
00238         f_names = []
00239 
00240         schema = dummy.Schema()
00241         for f in schema.fields():
00242             name = f.getName()
00243             f.required = 1
00244             f_names.append(name)
00245         errors = {}
00246         dummy.validate(REQUEST=request, errors=errors)
00247         self.failUnless(errors, "Errors dictionary is empty.")
00248         err_fields = errors.keys()
00249         failures = []
00250         for f_name in f_names:
00251             if f_name not in err_fields:
00252                 failures.append(f_name)
00253         self.failIf(failures, "%s failed to report error." % failures)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 160 of file test_fields.py.

00160 
00161     def afterSetUp(self):
00162         self.setRoles(['Manager'])
00163         ATSiteTestCase.afterSetUp(self)
00164         self._dummy = mkDummyInContext(Dummy, oid='dummy', context=self.portal,
00165                                        schema=schema)
00166         txt_file.seek(0)
00167         img_file.seek(0)

Here is the call graph for this function:

Definition at line 168 of file test_fields.py.

00168 
00169     def makeDummy(self):
00170         return self._dummy

Here is the caller graph for this function:

Definition at line 311 of file test_fields.py.

00311 
00312     def test_defaults(self):
00313         dummy = self.makeDummy()
00314         request = FakeRequest()
00315         field = dummy.Schema().fields()[0]
00316 
00317         # Default
00318         self.failUnlessEqual(field.getDefault(dummy), None)
00319         
00320         # Value
00321         field.default = "Hello"
00322         self.failUnlessEqual(field.getDefault(dummy), 'Hello')
00323         
00324         # Method
00325         field.default = None
00326         field.default_method = 'default_val'
00327         self.failUnlessEqual(field.getDefault(dummy), 'World')
00328 
00329         # Adapter
00330         field.default_method = None
00331         
00332         class DefaultFor(object):
00333             implements(IFieldDefaultProvider)
00334             def __init__(self, context):
00335                 self.context = context
00336             def __call__(self):
00337                 return "Adapted"
00338         
00339         getSiteManager().registerAdapter(factory=DefaultFor, required=(Dummy,), name=field.__name__)
00340         self.failUnlessEqual(field.getDefault(dummy), 'Adapted')
00341         getSiteManager().unregisterAdapter(factory=DefaultFor, required=(Dummy,), name=field.__name__)
00342 

Here is the call graph for this function:

Definition at line 271 of file test_fields.py.

00271 
00272     def test_dynamic_vocabulary(self):
00273         dummy = self.makeDummy()
00274         request = FakeRequest()
00275         field = dummy.Schema().fields()[0]
00276 
00277         # Default
00278         self.failUnlessEqual(field.Vocabulary(dummy), DisplayList())
00279         # Method
00280         field.vocabulary = 'aMethod'
00281         self.failUnlessEqual(field.Vocabulary(dummy), sampleDisplayList)
00282         # DisplayList
00283         field.vocabulary = sampleDisplayList()
00284         self.failUnlessEqual(field.Vocabulary(dummy), sampleDisplayList)
00285         # List
00286         field.vocabulary = ['e1', 'element2']
00287         self.failUnlessEqual(field.Vocabulary(dummy), sampleDisplayList)
00288         # 2-Tuples
00289         field.vocabulary = [('e1', 'e1'), ('element2', 'element2')]
00290         self.failUnlessEqual(field.Vocabulary(dummy), sampleDisplayList)
00291         # Interface
00292         field.vocabulary = sampleInterfaceVocabulary()
00293         self.failUnlessEqual(field.Vocabulary(dummy), sampleDisplayList)

Here is the call graph for this function:

Definition at line 294 of file test_fields.py.

00294 
00295     def test_factory_vocabulary(self):
00296         dummy = self.makeDummy()
00297         request = FakeRequest()
00298         field = dummy.Schema().fields()[0]
00299 
00300         # Default
00301         self.failUnlessEqual(field.Vocabulary(dummy), DisplayList())
00302         
00303         expected = DisplayList([('value1', 'title1'), ('v2', 't2')])
00304         
00305         # # Vocabulary factory
00306         field.vocabulary = ()
00307         field.vocabulary_factory = 'archetypes.tests.dummyvocab'
00308         getSiteManager().registerUtility(component=DummyVocabFactory, name='archetypes.tests.dummyvocab')
00309         self.failUnlessEqual(field.Vocabulary(dummy), expected)
00310         getSiteManager().unregisterUtility(component=DummyVocabFactory, name='archetypes.tests.dummyvocab')

Here is the call graph for this function:

Definition at line 198 of file test_fields.py.

00198 
00199     def test_get_size(self):
00200         dummy = self.makeDummy()
00201         request = FakeRequest()
00202         request.form.update(field_values)
00203         request.form['fieldset'] = 'default'
00204         dummy.REQUEST = request
00205         dummy.processForm()
00206         size = 0
00207         for k, v in expected_values.items():
00208             field = dummy.getField(k)
00209             s = field.get_size(dummy)
00210             size+=s
00211             self.failUnless(s, 'got: %s, field: %s' % (s, k))
00212         self.failUnlessEqual(size, dummy.get_size())

Here is the call graph for this function:

Definition at line 171 of file test_fields.py.

00171 
00172     def test_processing(self):
00173         dummy = self.makeDummy()
00174         request = FakeRequest()
00175         request.form.update(field_values)
00176         dummy.REQUEST = request
00177         dummy.processForm(data=1)
00178         for k, v in expected_values.items():
00179             got = dummy.getField(k).get(dummy)
00180             if isinstance(got, File):
00181                 got = str(got)
00182             self.assertEquals(got, v, 'got: %r, expected: %r, field "%s"' %
00183                               (got, v, k))

Here is the call graph for this function:

Definition at line 184 of file test_fields.py.

00184 
00185     def test_processing_fieldset(self):
00186         dummy = self.makeDummy()
00187         request = FakeRequest()
00188         request.form.update(field_values)
00189         request.form['fieldset'] = 'default'
00190         dummy.REQUEST = request
00191         dummy.processForm()
00192         for k, v in expected_values.items():
00193             got = dummy.getField(k).get(dummy)
00194             if isinstance(got, (File, ScalableImage, Image)):
00195                 got = str(got)
00196             self.assertEquals(got, v, 'got: %r, expected: %r, field "%s"' %
00197                               (got, v, k))

Here is the call graph for this function:

Definition at line 223 of file test_fields.py.

00223 
00224     def test_required(self):
00225         request = FakeRequest()
00226         request.form.update(empty_values)
00227         request.form['fieldset'] = 'default'
00228         self._test_required(request)
        

Here is the call graph for this function:

Definition at line 229 of file test_fields.py.

00229 
00230     def test_required_empty_request(self):
00231         request = FakeRequest()
00232         request.form = {}
00233         request.form['fieldset'] = 'default'
00234         self._test_required(request)

Here is the call graph for this function:

Definition at line 254 of file test_fields.py.

00254 
00255     def test_static_vocabulary(self):
00256         dummy = self.makeDummy()
00257         request = FakeRequest()
00258         field = dummy.Schema().fields()[0]
00259 
00260         # Default
00261         self.failUnlessEqual(field.Vocabulary(), DisplayList())
00262         # DisplayList
00263         field.vocabulary = sampleDisplayList()
00264         self.failUnlessEqual(field.Vocabulary(), sampleDisplayList)
00265         # List
00266         field.vocabulary = ['e1', 'element2']
00267         self.failUnlessEqual(field.Vocabulary(), sampleDisplayList)
00268         # 2-Tuples
00269         field.vocabulary = [('e1', 'e1'), ('element2', 'element2')]
00270         self.failUnlessEqual(field.Vocabulary(), sampleDisplayList)

Here is the call graph for this function:

Definition at line 213 of file test_fields.py.

00213 
00214     def test_validation(self):
00215         dummy = self.makeDummy()
00216         request = FakeRequest()
00217         request.form.update(field_values)
00218         request.form['fieldset'] = 'default'
00219         dummy.REQUEST = request
00220         errors = {}
00221         dummy.validate(errors=errors)
00222         self.failIf(errors, errors)

Here is the call graph for this function:


Member Data Documentation

Definition at line 163 of file test_fields.py.

Definition at line 334 of file test_fields.py.


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