Ticket #18160: auth_unknown_encoding.diff

File auth_unknown_encoding.diff, 1.3 KB (added by mitnk, 13 years ago)
  • django/contrib/auth/tests/management.py

     
    2929        management.get_system_username = lambda: u'J\xfalia'
    3030        self.assertEqual(management.get_default_username(), 'julia')
    3131
     32    def test_unknown_encoding(self):
     33        import locale
     34        locale.getdefaultlocale = lambda: ("en_US", "x-mac-simp-chinese")
     35        self.assertEqual(management.get_default_username(), '')
    3236
     37
    3338class ChangepasswordManagementCommandTestCase(TestCase):
    3439
    3540    def setUp(self):
  • django/contrib/auth/management/__init__.py

     
    8383    """
    8484    try:
    8585        return getpass.getuser().decode(locale.getdefaultlocale()[1])
    86     except (ImportError, KeyError, UnicodeDecodeError):
     86    except (ImportError, KeyError, LookupError, UnicodeDecodeError):
    8787        # KeyError will be raised by os.getpwuid() (called by getuser())
    8888        # if there is no corresponding entry in the /etc/passwd file
    8989        # (a very restricted chroot environment, for example).
Back to Top