Changeset 14594 for main/waeup.aaue/trunk/src/waeup/aaue/utils
- Timestamp:
- 27 Feb 2017, 06:50:46 (8 years ago)
- Location:
- main/waeup.aaue/trunk/src/waeup/aaue/utils
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.aaue/trunk/src/waeup/aaue/utils/tests.py
r8444 r14594 18 18 from waeup.kofa.testing import FunctionalTestCase 19 19 from waeup.aaue.testing import FunctionalLayer 20 from waeup.aaue.utils.utils import CustomKofaUtils 20 21 21 22 … … 24 25 layer = FunctionalLayer 25 26 26 def test_foo(self): 27 '''Test method foo. 28 ''' 29 return 27 def test_fullname(self): 28 util = CustomKofaUtils() 29 firstname = 'John' 30 middlename = 'Z' 31 lastname = 'Streep' 32 self.assertEqual( 33 util.fullname(firstname, lastname, middlename), 'STREEP, John') 34 firstname = 'J' 35 self.assertEqual( 36 util.fullname(firstname, lastname, middlename), 'STREEP') 37 lastname = None 38 self.assertEqual( 39 util.fullname(firstname, lastname, middlename), '') 40 firstname = 'John' 41 self.assertEqual( 42 util.fullname(firstname, lastname, middlename), 'John') 43 firstname = 'J' 44 middlename = 'Babatunde' 45 lastname = 'Iron' 46 self.assertEqual( 47 util.fullname(firstname, lastname, middlename), 'IRON, Babatunde') -
main/waeup.aaue/trunk/src/waeup/aaue/utils/utils.py
r14571 r14594 215 215 except AttributeError: 216 216 pass 217 # We do not necessarily have the middlename attribute 218 if middlename: 217 # We remove single initial 218 if firstname and len(firstname) == 1: 219 firstname = '' 220 if middlename and len(middlename) == 1: 221 middlename = '' 222 if lastname and len(lastname) == 1: 223 lastname = '' 224 # We construct givennames 225 givennames = '' 226 if middlename and firstname: 219 227 givennames = '%s %s' % (firstname, middlename) 220 else: 221 givennames = '%s' % firstname 228 elif firstname: 229 givennames = firstname 230 elif middlename: 231 givennames = middlename 222 232 givennames = string.capwords( 223 233 givennames.replace('-', ' - ')).replace(' - ', '-') 224 fullname = '%s, %s' % (lastname, givennames) 234 # We construct fullname 235 fullname = '' 236 if lastname and givennames: 237 fullname = '%s, %s' % (lastname, givennames) 238 elif lastname: 239 fullname = lastname 240 elif givennames: 241 fullname = givennames 225 242 if '<' in fullname: 226 243 return 'XXX'
Note: See TracChangeset for help on using the changeset viewer.