Skip to content

Instantly share code, notes, and snippets.

@alexlopes
Created August 8, 2019 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlopes/38a881cc6455733b8c98b21eeab48c94 to your computer and use it in GitHub Desktop.
Save alexlopes/38a881cc6455733b8c98b21eeab48c94 to your computer and use it in GitHub Desktop.
Pyhon Test messages with all chars lowercased
import ast
import logging
import sys
import unittest
from io import BytesIO
class TestFormatterMessagesOutputs(unittest.TestCase):
def setUp(self):
logging.basicConfig( level=logging.INFO)
self.logger = logging.getLogger(__name__)
self.log_capture_string = BytesIO()
self.syslog = logging.StreamHandler(self.log_capture_string)
self.syslog.setFormatter(MyLogFormatter(LOG_FORMAT))
self.logger.addHandler(self.syslog)
self.logger.propagate = False
def test_all_lowercase(self):
self.logger.info('Simple MESSAGE É necessária uma ação',
extra={'fields':
{'value_1': 'a',
'value_2': 'B',
'value_3': 'DEF'
}
})
log_contents = self.log_capture_string.getvalue()
root = ast.literal_eval(log_contents)
message = root['msg']
self.assertEquals(message.replace(" ","").islower(), True, "Message not lowercased")
def tearDown(self):
self.log_capture_string.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment