def test_logging_default_setup(self): setup = logging.setup() handler = setup.objects[1] self.assertTrue(isinstance( handler, logbook.handlers.FileHandler)) self.assertTrue(handler.level_name == 'DEBUG') self.assertTrue(handler.stream.name == settings.LOG['file'])
def test_logging_custom_file_setup(self): custom_level = 'warning' custom_logfile = '/tmp/test-dna.log' setup = logging.setup(level=custom_level, filename=custom_logfile) handler = setup.objects[1] self.assertTrue(isinstance(handler, logbook.handlers.FileHandler)) self.assertTrue(handler.level_name == custom_level.upper()) self.assertTrue(handler.stream.name == custom_logfile)
def test_logging_custom_file_setup(self): custom_level = 'warning' custom_logfile = '/tmp/test-dna.log' setup = logging.setup(level=custom_level, filename=custom_logfile) handler = setup.objects[1] self.assertTrue(isinstance( handler, logbook.handlers.FileHandler)) self.assertTrue(handler.level_name == custom_level.upper()) self.assertTrue(handler.stream.name == custom_logfile)
def test_write_log_to_file(self): os.remove(settings.LOG['file']) setup = logging.setup() body = 'TDD is awesome' event_type = 'test' with setup.applicationbound(): log = logging.logger() log.info(event_type, body=body) self.assertTrue(os.path.exists(settings.LOG['file'])) with open(settings.LOG['file'], 'r') as fd: text = fd.read() for required_info in \ [body, event_type, 'INFO', 'dna.logging']: self.assertTrue(required_info in text)
def test_logging_default_setup(self): setup = logging.setup() handler = setup.objects[1] self.assertTrue(isinstance(handler, logbook.handlers.FileHandler)) self.assertTrue(handler.level_name == 'DEBUG') self.assertTrue(handler.stream.name == settings.LOG['file'])