def test_setup_logging_prod(self): setuplogging.AWS_LOGGER = None setuplogging.LOGGING_HANDLER = None setuplogging.initialize_logging(mocking=False) assert setuplogging.AWS_LOGGER is not None assert setuplogging.LOGGING_HANDLER == setuplogging.prod_logging_handler
def test_setup_logging_mocked(self): setuplogging.AWS_LOGGER = None setuplogging.LOGGING_HANDLER = None setuplogging.initialize_logging(mocking=True) assert setuplogging.AWS_LOGGER is None assert setuplogging.LOGGING_HANDLER == setuplogging.mock_logging_handler
def test_logging_to_mocked(self): """Our mocked log is just a string, so make sure we stash it in the right place""" setuplogging.AWS_LOGGER = None setuplogging.LOGGING_HANDLER = None setuplogging.initialize_logging(mocking=True) string_to_log = "log this string" setuplogging.LOGGING_HANDLER(string_to_log) assert string_to_log == setuplogging.MOCK_LOG
def test_logging_to_prod(self): """In this test we do all the prod setup but we change out where PROD logs to and log to a locally defined function""" setuplogging.AWS_LOGGER = None setuplogging.LOGGING_HANDLER = None setuplogging.initialize_logging(mocking=False) setuplogging.AWS_LOGGER = MockAWSLogging() string_to_log = "log this string" setuplogging.LOGGING_HANDLER(string_to_log)
def test_setup_logging_mocked_subsequent(self): setuplogging.AWS_LOGGER = None setuplogging.LOGGING_HANDLER = None setuplogging.initialize_logging(mocking=True) assert setuplogging.AWS_LOGGER is None assert setuplogging.LOGGING_HANDLER == setuplogging.mock_logging_handler # now do it again, this time without mocking setuplogging.initialize_logging(mocking=False) assert setuplogging.AWS_LOGGER is None assert setuplogging.LOGGING_HANDLER == setuplogging.mock_logging_handler
def lambda_handler(event, context): """ App entry point """ setuplogging.initialize_logging( mocking=False) # make sure logging is setup log('EVENT{}'.format(event)) # log the event if event['session']['new']: on_session_started() if event['request']['type'] == "LaunchRequest": return on_launch(event['request']) elif event['request']['type'] == "IntentRequest": return on_intent(event['request'], event['session']) elif event['request']['type'] == "SessionEndedRequest": return on_session_ended() return None
def setUp(self): fake = fakeredis.FakeStrictRedis() cloudredis.initialize_cloud_redis(injected_server=fake) assert cloudredis.REDIS_SERVER == fake setuplogging.initialize_logging(True)
def log(message: str) -> None: if not setuplogging.LOGGING_HANDLER: setuplogging.initialize_logging(mocking=True) setuplogging.LOGGING_HANDLER(message)