mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.3 KiB
Python
81 lines
2.3 KiB
Python
8 years ago
|
#
|
||
|
# (c) 2016 Michael De La Rue
|
||
|
#
|
||
|
# This file is part of Ansible
|
||
|
#
|
||
|
# Ansible is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# Ansible is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
# Make coding more python3-ish
|
||
|
|
||
|
from __future__ import (absolute_import, division, print_function)
|
||
|
|
||
|
import sys
|
||
7 years ago
|
|
||
|
import pytest
|
||
|
|
||
8 years ago
|
from ansible.module_utils.ec2 import HAS_BOTO3
|
||
7 years ago
|
from units.modules.utils import set_module_args
|
||
8 years ago
|
|
||
|
if not HAS_BOTO3:
|
||
7 years ago
|
pytestmark = pytest.mark.skip("test_api_gateway.py requires the `boto3` and `botocore` modules")
|
||
8 years ago
|
|
||
|
import ansible.modules.cloud.amazon.aws_api_gateway as agw
|
||
6 years ago
|
import ansible.module_utils.aws.core as core
|
||
8 years ago
|
|
||
|
|
||
|
exit_return_dict = {}
|
||
|
|
||
|
|
||
|
def fake_exit_json(self, **kwargs):
|
||
|
""" store the kwargs given to exit_json rather than putting them out to stdout"""
|
||
|
global exit_return_dict
|
||
|
exit_return_dict = kwargs
|
||
|
sys.exit(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()
|
||
|
|
||
6 years ago
|
monkeypatch.setattr(core, "boto3_conn", return_fake_connection)
|
||
|
monkeypatch.setattr(core.AnsibleAWSModule, "exit_json", fake_exit_json)
|
||
8 years ago
|
|
||
|
set_module_args({
|
||
|
"api_id": "fred",
|
||
|
"state": "present",
|
||
|
"swagger_text": "the-swagger-text-is-fake",
|
||
|
"region": 'mars-north-1',
|
||
|
})
|
||
|
with pytest.raises(SystemExit):
|
||
|
agw.main()
|
||
|
assert exit_return_dict["changed"]
|
||
|
|
||
|
|
||
|
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())
|