|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from unittest.mock import MagicMock, patch |
| 3 | + |
| 4 | +import pytest |
| 5 | +from chaoslib.exceptions import FailedActivity |
| 6 | + |
| 7 | +from chaosaws.awslambda.actions import put_function_concurrency |
| 8 | +from chaosaws.awslambda.actions import delete_function_concurrency |
| 9 | + |
| 10 | + |
| 11 | +@patch('chaosaws.awslambda.actions.aws_client', autospec=True) |
| 12 | +def test_aws_lambda_put_function_concurrency(aws_client): |
| 13 | + client = MagicMock() |
| 14 | + aws_client.return_value = client |
| 15 | + lambda_function_name = 'my-lambda-function' |
| 16 | + concurrency = 0 |
| 17 | + put_function_concurrency(lambda_function_name, concurrency) |
| 18 | + client.put_function_concurrency.assert_called_with(FunctionName=lambda_function_name, |
| 19 | + ReservedConcurrentExecutions=concurrency) |
| 20 | + |
| 21 | +@patch('chaosaws.awslambda.actions.aws_client', autospec=True) |
| 22 | +def test_aws_lambda_put_function_concurrency_empty_string(aws_client): |
| 23 | + client = MagicMock() |
| 24 | + aws_client.return_value = client |
| 25 | + lambda_function_name = '' |
| 26 | + concurrency = 0 |
| 27 | + with pytest.raises(FailedActivity): |
| 28 | + put_function_concurrency(lambda_function_name, concurrency) |
| 29 | + |
| 30 | + |
| 31 | +@patch('chaosaws.awslambda.actions.aws_client', autospec=True) |
| 32 | +def test_aws_lambda_put_function_concurrency_failedactivity(aws_client): |
| 33 | + client = MagicMock() |
| 34 | + aws_client.return_value = client |
| 35 | + lambda_function_name = 'my-lambda-function' |
| 36 | + concurrency = 0 |
| 37 | + |
| 38 | + with patch.object(client, 'put_function_concurrency', FailedActivity): |
| 39 | + with pytest.raises(Exception): |
| 40 | + put_function_concurrency(lambda_function_name, concurrency) |
| 41 | + |
| 42 | + |
| 43 | +@patch('chaosaws.awslambda.actions.aws_client', autospec=True) |
| 44 | +def test_aws_lambda_delete_function_concurrency(aws_client): |
| 45 | + client = MagicMock() |
| 46 | + aws_client.return_value = client |
| 47 | + lambda_function_name = 'my-lambda-function' |
| 48 | + delete_function_concurrency(lambda_function_name) |
| 49 | + client.delete_function_concurrency.assert_called_with(FunctionName=lambda_function_name) |
0 commit comments