Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_configure_ec2_config_event_log_raises_filenotfound(mocker):
"""Raise FileNotFoundError when EC2_CONFIG_EVENT_LOG is missing."""
logger.EC2_CONFIG_EVENT_LOG = 'notreal.xml'
with pytest.raises(FileNotFoundError):
logger._configure_ec2_config_event_log()
def test_configure_ec2config_write_all_events(mocker):
"""Configure EC2Config Event Logging with all events."""
data = '''
'''
mo_ = mocker.mock_open(read_data=data)
mocker.patch('io.open', mo_, create=True)
logger._configure_ec2_config_event_log()
# Verify we opened the file twice, once for read and once for write
assert mo_.call_args_list == [
mocker.call(logger.EC2_CONFIG_EVENT_LOG),
mocker.call(logger.EC2_CONFIG_EVENT_LOG, mode='wb')
]
# Convert write calls to xml tree
handle = mo_()
result = xml.etree.ElementTree.ElementTree(
xml.etree.ElementTree.fromstring(
_pytest_stringify_write_calls(handle.write.call_args_list)))
# Get all the present events
events = result.getroot().findall('Event')
events_present = set()
Watchmaker
Application
Warning
999999
2008-09-10T00:00:00.000Z
Watchmaker
'''
mo_ = mocker.mock_open(read_data=data)
mocker.patch('io.open', mo_, create=True)
logger._configure_ec2_config_event_log()
# Verify we read the data
assert mo_.call_args_list == [
mocker.call(logger.EC2_CONFIG_EVENT_LOG),
]
# Verify we didn't write anything
handle = mo_()
assert handle.write.call_count == 0