diff --git a/tests/test_logging.py b/tests/test_logging.py index 08fe3b0ffd2857ccb2daf8faa4a3e73f77d7e2d6..f821c81a77e69bd976af409916580a504e4f9ff8 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -10,13 +10,17 @@ from rattail import logging as rattail_logging class TestLogging(TestCase): + @patch('rattail.logging.os') @patch('rattail.logging.sys') @patch('rattail.logging.socket') - def test_adapter_adds_all_context(self, socket, sys): + @patch('rattail.logging.getpass') + def test_adapter_adds_all_context(self, getpass, socket, sys, os): socket.getfqdn.return_value = 'testing.rattailproject.org' socket.gethostbyname.return_value = '127.0.0.1' sys.argv = ['just', 'testing'] - formatter = logging.Formatter(u"%(hostname)s %(hostip)s %(argv)s %(levelname)s %(message)s") + os.getuid.return_value = 420 + getpass.getuser.return_value = 'joeschmoe' + formatter = logging.Formatter(u"%(hostname)s %(hostip)s %(argv)s %(username)s %(uid)s %(levelname)s %(message)s") string = StringIO() handler = logging.StreamHandler(string) handler.setFormatter(formatter) @@ -26,5 +30,5 @@ class TestLogging(TestCase): log = rattail_logging.RattailAdapter(log) self.assertEqual(string.getvalue(), "") log.debug("some random thing") - self.assertEqual(string.getvalue(), u"testing.rattailproject.org 127.0.0.1 ['just', 'testing'] DEBUG some random thing\n") + self.assertEqual(string.getvalue(), u"testing.rattailproject.org 127.0.0.1 ['just', 'testing'] joeschmoe 420 DEBUG some random thing\n") string.close()