Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Check that EC2Launch Event Log config skips pre-existing events."""
# Load all event types into the data
events = []
for msg_type in logger.MESSAGE_TYPES:
events += [{
'logName': 'Application',
'source': 'Watchmaker',
'level': msg_type,
'numEntries': '999'
}]
data = json.dumps({'events': events})
mo_ = mocker.mock_open(read_data=data)
mocker.patch('io.open', mo_, create=True)
logger._configure_ec2_launch_event_log()
# Verify we read the data
assert mo_.call_args_list == [
mocker.call(logger.EC2_LAUNCH_LOG_CONFIG),
]
# Verify we didn't write anything
handle = mo_()
assert handle.write.call_count == 0
def test_configure_ec2_launch_event_log_raises_filenotfound(mocker):
"""Raise FileNotFoundError when EC2_LAUNCH_LOG_CONFIG is missing."""
logger.EC2_LAUNCH_LOG_CONFIG = 'notreal.json'
with pytest.raises(FileNotFoundError):
logger._configure_ec2_launch_event_log()
def test_configure_ec2launch_write_all_events(mocker):
"""Configure EC2Launch Event Logging with all events."""
# Start with an empty data set, so all events should be written
data = '{}'
mo_ = mocker.mock_open(read_data=data)
mocker.patch('io.open', mo_, create=True)
logger._configure_ec2_launch_event_log()
# Verify we opened the file twice, once for read and once for write
assert mo_.call_args_list == [
mocker.call(logger.EC2_LAUNCH_LOG_CONFIG),
mocker.call(logger.EC2_LAUNCH_LOG_CONFIG, mode='w')
]
# Convert write calls to json
handle = mo_()
result = json.loads(
_pytest_stringify_write_calls(handle.write.call_args_list))
expected_events = []
for msg_type in logger.MESSAGE_TYPES:
expected_events += [{
'logName': 'Application',