Created
August 8, 2019 19:33
-
-
Save alexlopes/38a881cc6455733b8c98b21eeab48c94 to your computer and use it in GitHub Desktop.
Pyhon Test messages with all chars lowercased
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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