Ticket #17649: ticket17649_2.patch

File ticket17649_2.patch, 1.5 KB (added by chomik, 13 years ago)

test improvement

  • django/contrib/auth/management/__init__.py

    diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
    index 78a51cf..ea59bc5 100644
    a b def get_system_username():  
    8282        username could not be determined.
    8383    """
    8484    try:
    85         return getpass.getuser().decode(locale.getdefaultlocale()[1])
     85        system_locale = locale.getdefaultlocale()[1]
     86        if system_locale:
     87            return getpass.getuser().decode(system_locale)
     88        else:
     89            return getpass.getuser().decode(errors='ignore')
    8690    except (ImportError, KeyError, UnicodeDecodeError):
    8791        # KeyError will be raised by os.getpwuid() (called by getuser())
    8892        # if there is no corresponding entry in the /etc/passwd file
  • django/contrib/auth/tests/management.py

    diff --git a/django/contrib/auth/tests/management.py b/django/contrib/auth/tests/management.py
    index 0af6873..afbb748 100644
    a b class GetDefaultUsernameTestCase(TestCase):  
    2525        # 'Julia' with accented 'u':
    2626        management.get_system_username = lambda: u'J\xfalia'
    2727        self.assertEqual(management.get_default_username(), 'julia')
     28
     29    def test_locale_empty(self):
     30        # Test for emty locale.
     31        import locale
     32        import getpass
     33        locale.getdefaultlocale = lambda: (None,None)
     34        getpass.getuser = lambda: 'J\xfalia'
     35        self.assertEqual(management.get_system_username(), u'Jlia')
Back to Top