- Timestamp:
- 21 Mar 2012, 10:41:15 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_converters.py
r7819 r7932 33 33 from waeup.kofa.app import University 34 34 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 35 from waeup.kofa.interfaces import ( 36 SimpleKofaVocabulary, SubjectSource, GradeSource) 37 from waeup.kofa.schoolgrades import ResultEntryField 35 38 from waeup.kofa.university import Faculty 36 39 from waeup.kofa.utils.converters import IObjectConverter 37 40 from waeup.kofa.utils.helpers import attrs_to_fields 38 from waeup.kofa.interfaces import SimpleKofaVocabulary39 41 40 42 colors = SimpleKofaVocabulary( … … 85 87 vocabulary = car_nums, 86 88 ) 89 grades = schema.List( 90 title = u'School Grades', 91 value_type = ResultEntryField(), 92 required = True, 93 default = [], 94 ) 95 friends = schema.List( 96 title = u'Friends', 97 value_type = schema.TextLine( 98 title = u'Name', 99 ) 100 ) 101 87 102 @invariant 88 103 def kevinIsYoung(contact): … … 330 345 assert data['num_cars'] == 1 331 346 return 347 348 def test_list_of_textlines(self): 349 # We can convert lists of text lines 350 converter = IObjectConverter(IContact) 351 err, inv_err, data = converter.fromStringDict( 352 {"friends": "['Fred', 'Wilma']"}, 'contact') 353 self.assertEqual( 354 data, {'friends': ['Fred', 'Wilma']}) 355 return 356 357 def test_list_of_resultentries(self): 358 # We can handle lists of result entries 359 converter = IObjectConverter(IContact) 360 # get currently valid values 361 s_src, g_src = SubjectSource(), GradeSource() 362 s_val1, s_val2 = list(s_src.factory.getValues())[0:2] 363 g_val1, g_val2 = list(g_src.factory.getValues())[0:2] 364 req_string = u"[('%s', '%s'), ('%s', '%s')]" % ( 365 s_val1, g_val1, s_val2, g_val2) 366 err, inv_err, data = converter.fromStringDict( 367 {"grades": req_string, 368 }, 369 'contact') 370 result_grades = data['grades'] 371 self.assertTrue(isinstance(result_grades, list)) 372 self.assertEqual(len(result_grades), 2) 373 self.assertEqual(result_grades[0].subject, s_val1) 374 self.assertEqual(result_grades[0].grade, g_val1) 375 return
Note: See TracChangeset for help on using the changeset viewer.