(self, mock_format, mock_colorize)
| 2521 | @mock.patch("zappa.cli.ZappaCLI.colorize_invoke_command") |
| 2522 | @mock.patch("zappa.cli.ZappaCLI.format_invoke_command") |
| 2523 | def test_cli_format_lambda_response(self, mock_format, mock_colorize): |
| 2524 | format_msg = "formatted string" |
| 2525 | colorize_msg = "colorized string" |
| 2526 | mock_format.return_value = format_msg |
| 2527 | mock_colorize.return_value = colorize_msg |
| 2528 | zappa_cli = ZappaCLI() |
| 2529 | |
| 2530 | response_without_logresult = {"StatusCode": 200, "FunctionError": "some_err"} |
| 2531 | self.assertEqual( |
| 2532 | zappa_cli.format_lambda_response(response_without_logresult), |
| 2533 | response_without_logresult, |
| 2534 | ) |
| 2535 | |
| 2536 | bad_utf8 = b"\xfc\xfc\xfc" |
| 2537 | bad_utf8_logresult = { |
| 2538 | "StatusCode": 200, |
| 2539 | "LogResult": base64.b64encode(bad_utf8), |
| 2540 | } |
| 2541 | self.assertEqual(zappa_cli.format_lambda_response(bad_utf8_logresult), bad_utf8) |
| 2542 | |
| 2543 | log_msg = "Function output logs go here" |
| 2544 | regular_logresult = { |
| 2545 | "StatusCode": 200, |
| 2546 | "LogResult": base64.b64encode(log_msg.encode()), |
| 2547 | } |
| 2548 | with mock.patch.object(sys.stdout, "isatty") as mock_isatty: |
| 2549 | mock_isatty.return_value = True |
| 2550 | formatted = zappa_cli.format_lambda_response(regular_logresult, True) |
| 2551 | mock_format.assert_called_once_with(log_msg) |
| 2552 | mock_colorize.assert_called_once_with(format_msg) |
| 2553 | self.assertEqual(formatted, colorize_msg) |
| 2554 | mock_format.reset_mock() |
| 2555 | mock_colorize.reset_mock() |
| 2556 | |
| 2557 | with mock.patch.object(sys.stdout, "isatty") as mock_isatty: |
| 2558 | mock_isatty.return_value = False |
| 2559 | formatted = zappa_cli.format_lambda_response(regular_logresult, True) |
| 2560 | mock_format.assert_not_called() |
| 2561 | mock_colorize.assert_not_called() |
| 2562 | self.assertEqual(formatted, log_msg) |
| 2563 | |
| 2564 | formatted = zappa_cli.format_lambda_response(regular_logresult, False) |
| 2565 | mock_format.assert_not_called() |
| 2566 | mock_colorize.assert_not_called() |
| 2567 | self.assertEqual(formatted, log_msg) |
| 2568 | |
| 2569 | def test_cli_save_python_settings_file(self): |
| 2570 | zappa_cli = ZappaCLI() |
nothing calls this directly
no test coverage detected