def test_colored_property_without_output_file(self, ColoredMock): ColoredMock.return_value = Mock() # No output file. It means we are printing to Terminal. Hence set the color ctx = LogsCommandContext(self.function_name, stack_name=self.stack_name, filter_pattern=self.filter_pattern, start_time=self.start_time, end_time=self.end_time, output_file=None) self.assertEqual(ctx.colored, ColoredMock.return_value) ColoredMock.assert_called_with(colorize=True) # Must enable colors
def test_context_manager_no_output_file(self, setup_output_file_mock): setup_output_file_mock.return_value = None with LogsCommandContext(self.function_name, stack_name=self.stack_name, filter_pattern=self.filter_pattern, start_time=self.start_time, end_time=self.end_time, output_file=None) as context: self.assertEquals(context._output_file_handle, None) # Context should be reset setup_output_file_mock.assert_called_with(None)
def setUp(self): self.function_name = "name" self.stack_name = "stack name" self.filter_pattern = "filter" self.start_time = "start" self.end_time = "end" self.output_file = "somefile" self.context = LogsCommandContext(self.function_name, stack_name=self.stack_name, filter_pattern=self.filter_pattern, start_time=self.start_time, end_time=self.end_time, output_file=self.output_file)
def test_context_manager_with_output_file(self, setup_output_file_mock): handle = Mock() setup_output_file_mock.return_value = handle with LogsCommandContext(self.function_name, stack_name=self.stack_name, filter_pattern=self.filter_pattern, start_time=self.start_time, end_time=self.end_time, output_file=self.output_file) as context: self.assertEquals(context._output_file_handle, handle) # Context should be reset self.assertIsNone(self.context._output_file_handle) handle.close.assert_called_with() setup_output_file_mock.assert_called_with(self.output_file)
def test_log_group_name_property_without_stack_name(self, get_resource_id_mock, LogGroupProviderMock): group = "groupname" LogGroupProviderMock.for_lambda_function.return_value = group ctx = LogsCommandContext( self.function_name, stack_name=None, # No Stack Name filter_pattern=self.filter_pattern, start_time=self.start_time, end_time=self.end_time, output_file=self.output_file, ) self.assertEqual(ctx.log_group_name, group) LogGroupProviderMock.for_lambda_function.assert_called_with(self.function_name) get_resource_id_mock.assert_not_called()