Fix AttributeError in filter_log_events

An AttributeError would be thrown if the `interleaved` parameter was
passed.
This commit is contained in:
Josh Prendergast 2018-04-04 17:24:41 +01:00
parent 4184acc0d2
commit ca72707409
2 changed files with 30 additions and 2 deletions

View File

@ -184,7 +184,7 @@ class LogGroup:
events += stream.filter_log_events(log_group_name, log_stream_names, start_time, end_time, limit, next_token, filter_pattern, interleaved) events += stream.filter_log_events(log_group_name, log_stream_names, start_time, end_time, limit, next_token, filter_pattern, interleaved)
if interleaved: if interleaved:
events = sorted(events, key=lambda event: event.timestamp) events = sorted(events, key=lambda event: event['timestamp'])
if next_token is None: if next_token is None:
next_token = 0 next_token = 0

View File

@ -85,4 +85,32 @@ def test_put_logs():
logStreamName=log_stream_name logStreamName=log_stream_name
) )
events = res['events'] events = res['events']
events.should.have.length_of(2) events.should.have.length_of(2)
@mock_logs
def test_filter_logs_interleaved():
conn = boto3.client('logs', 'us-west-2')
log_group_name = 'dummy'
log_stream_name = 'stream'
conn.create_log_group(logGroupName=log_group_name)
conn.create_log_stream(
logGroupName=log_group_name,
logStreamName=log_stream_name
)
messages = [
{'timestamp': 0, 'message': 'hello'},
{'timestamp': 0, 'message': 'world'}
]
conn.put_log_events(
logGroupName=log_group_name,
logStreamName=log_stream_name,
logEvents=messages
)
res = conn.filter_log_events(
logGroupName=log_group_name,
logStreamNames=[log_stream_name],
interleaved=True,
)
events = res['events']
events.should.have.length_of(2)