def format(self, record):
     if isinstance(record.msg, str):
         message = super().format(record)
         return encoder({
             'message':
             message,
             'timestamp':
             datetime.utcfromtimestamp(
                 record.created).strftime('%y-%m-%dT%h:%M%S'),
             'level':
             record.levelname
         })
     else:
         return encoder(record.msg)
Exemplo n.º 2
0
    def test_event_should_publish_events_to_event_bridge(self):
        event_client = botocore.session.get_session().create_client('events')

        with Stubber(event_client) as stubber:
            source = 'source'
            detail_type = 'detail_type'
            bus_name = 'event_bus_name'
            time = generate_timestamp()
            response = {'test': True}

            stubber.add_response('put_events', {}, {
                'Entries': [{
                    'Source': source,
                    'Detail': encoder(response),
                    'DetailType': detail_type,
                    'EventBusName': bus_name,
                    'Time': time
                }]
            })

            event = event_handler(event_client,
                                  source,
                                  detail_type,
                                  bus_name,
                                  time=time)

            @event
            def event_it():
                return response

            result = event_it()

            self.assertEqual(response, result)
            stubber.assert_no_pending_responses()
        def _wrapper(*args, **kwargs):
            result = func(*args, **kwargs)
            if result:
                if (isinstance(result, Mapping)):
                    result = filter_empty_properties(result)
                params = {
                    'TopicArn': topic_arn,
                    'Subject': subject,
                    'Message': encoder(result)
                }
                params = filter_empty_properties(params)
                sns_client.publish(**params)

            return result
        def _wrapper(*args, **kwargs):
            result = func(*args, **kwargs)
            if result:
                if (isinstance(result, Mapping)):
                    result = filter_empty_properties(result)
                entry = {
                    'Source': source,
                    'Detail': encoder(result),
                    'DetailType': detail_type,
                    'EventBusName': event_bus_name,
                    'Resources': resources,
                    'Time': time
                }
                entry = filter_empty_properties(entry)
                event_bridge_client.put_events(Entries=[entry])

            return result
Exemplo n.º 5
0
    def test_sns_event_should_publish_message(self):
        sns_client = botocore.session.get_session().create_client('sns')

        with Stubber(sns_client) as stubber:
            topic_arn = 'arn:aws:sns:us-east-1:topic/some-topic'
            subject = 'test'
            response = {'test': True}
            stubber.add_response('publish', {}, {
                'TopicArn': topic_arn,
                'Subject': subject,
                'Message': encoder(response)
            })

            sns_event = sns_event_handler(sns_client, topic_arn, subject)

            @sns_event
            def event_it():
                return response

            result = event_it()

            self.assertEqual(response, result)
            stubber.assert_no_pending_responses()