(make_stubber, capsys, error_code)
| 14 | |
| 15 | @pytest.mark.parametrize("error_code", [None, "TestException", "DocumentAlreadyExists"]) |
| 16 | def test_create(make_stubber, capsys, error_code): |
| 17 | ssm_client = boto3.client("ssm") |
| 18 | ssm_stubber = make_stubber(ssm_client) |
| 19 | document_wrapper = DocumentWrapper(ssm_client) |
| 20 | name = "python-test" |
| 21 | content = """ |
| 22 | { |
| 23 | "schemaVersion": "2.2", |
| 24 | "description": "Run a simple shell command", |
| 25 | "mainSteps": [ |
| 26 | { |
| 27 | "action": "aws:runShellScript", |
| 28 | "name": "runEchoCommand", |
| 29 | "inputs": { |
| 30 | "runCommand": [ |
| 31 | "echo 'Hello, world!'" |
| 32 | ] |
| 33 | } |
| 34 | } |
| 35 | ] |
| 36 | } |
| 37 | """ |
| 38 | |
| 39 | ssm_stubber.stub_create_document( |
| 40 | content, |
| 41 | name, |
| 42 | error_code=error_code, |
| 43 | ) |
| 44 | |
| 45 | if error_code is None: |
| 46 | document_wrapper.create( |
| 47 | content, |
| 48 | name, |
| 49 | ) |
| 50 | assert document_wrapper.name == name |
| 51 | elif error_code == "DocumentAlreadyExists": |
| 52 | document_wrapper.create( |
| 53 | content, |
| 54 | name, |
| 55 | ) |
| 56 | assert document_wrapper.name == name |
| 57 | capt = capsys.readouterr() |
| 58 | assert "already exists" in capt.out |
| 59 | else: |
| 60 | with pytest.raises(ClientError) as exc_info: |
| 61 | document_wrapper.create( |
| 62 | content, |
| 63 | name, |
| 64 | ) |
| 65 | assert exc_info.value.response["Error"]["Code"] == error_code |
| 66 | |
| 67 | |
| 68 | @pytest.mark.parametrize("error_code", [None, "TestException"]) |
nothing calls this directly
no test coverage detected