예제 #1
0
def test_upload_api(monkeypatch):
    class FakeConnection:
        def put_rest_api(self, *args, **kwargs):
            assert kwargs["body"] == "the-swagger-text-is-fake"
            return {"msg": "success!"}

    def return_fake_connection(*args, **kwargs):
        return FakeConnection()

    # Because it's imported into the aws_modules namespace we need to override
    # it there, even though the function itself lives in module_utils.botocore
    monkeypatch.setattr(aws_modules, "boto3_conn", return_fake_connection)
    monkeypatch.setattr(aws_modules.AnsibleAWSModule, "exit_json",
                        fake_exit_json)

    set_module_args({
        "api_id": "fred",
        "state": "present",
        "swagger_text": "the-swagger-text-is-fake",
        "region": 'mars-north-1',
        "_ansible_tmpdir": "/tmp/ansibl-abcdef",
    })
    with pytest.raises(SystemExit):
        agw.main()
    assert exit_return_dict["changed"]
예제 #2
0
def test_warn_if_region_not_specified():

    set_module_args({
        "name": "aws_api_gateway",
        "state": "present",
        "runtime": 'python2.7',
        "role": 'arn:aws:iam::987654321012:role/lambda_basic_execution',
        "handler": 'lambda_python.my_handler'})
    with pytest.raises(SystemExit):
        print(agw.main())
def test_upload_api(monkeypatch):
    class FakeConnection:
        def put_rest_api(self, *args, **kwargs):
            assert kwargs["body"] == "the-swagger-text-is-fake"
            return {"msg": "success!"}

    def return_fake_connection(*args, **kwargs):
        return FakeConnection()

    monkeypatch.setattr(core, "boto3_conn", return_fake_connection)
    monkeypatch.setattr(core.AnsibleAWSModule, "exit_json", fake_exit_json)

    set_module_args({
        "api_id": "fred",
        "state": "present",
        "swagger_text": "the-swagger-text-is-fake",
        "region": 'mars-north-1',
        "_ansible_tmpdir": "/tmp/ansibl-abcdef",
    })
    with pytest.raises(SystemExit):
        agw.main()
    assert exit_return_dict["changed"]