1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/unit/plugins/modules/test_dnsimple_info.py

116 lines
4 KiB
Python
Raw Normal View History

add dnsimple_info module, see issue #3569 (#3739) * add dnsimple_info module, see issue #3569 https://github.com/ansible-collections/community.general/issues/3569#issuecomment-945002861 * Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update BOTMETA.yml Update dnsimple_info.py Create dnsimple_info.py Create dnsimple_info.py pep8 Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py add returns pep8 spacing Update dnsimple_info.py Update dnsimple_info.py change return results to list fix time stamps Update dnsimple_info.py remove extra comma Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update dnsimple_info.py fix descriptions Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py missing punctuation throughout docs Update dnsimple_info.py add elements in descriptions Update dnsimple_info.py indentation error Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py refactor, remove unneeded arguments refactor and error handling formatting add unit test Update test_dnsimple_info.py Update test_dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py assert fail/exit Update test_dnsimple_info.py pep8 fixes Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-12-11 21:14:32 +01:00
# -*- coding: utf-8 -*-
# Copyright (c) Ansible project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
add dnsimple_info module, see issue #3569 (#3739) * add dnsimple_info module, see issue #3569 https://github.com/ansible-collections/community.general/issues/3569#issuecomment-945002861 * Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update BOTMETA.yml Update dnsimple_info.py Create dnsimple_info.py Create dnsimple_info.py pep8 Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py add returns pep8 spacing Update dnsimple_info.py Update dnsimple_info.py change return results to list fix time stamps Update dnsimple_info.py remove extra comma Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update dnsimple_info.py fix descriptions Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py missing punctuation throughout docs Update dnsimple_info.py add elements in descriptions Update dnsimple_info.py indentation error Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py refactor, remove unneeded arguments refactor and error handling formatting add unit test Update test_dnsimple_info.py Update test_dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py assert fail/exit Update test_dnsimple_info.py pep8 fixes Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-12-11 21:14:32 +01:00
from __future__ import absolute_import, division, print_function
__metaclass__ = type
from ansible_collections.community.general.plugins.modules import dnsimple_info
add dnsimple_info module, see issue #3569 (#3739) * add dnsimple_info module, see issue #3569 https://github.com/ansible-collections/community.general/issues/3569#issuecomment-945002861 * Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update BOTMETA.yml Update dnsimple_info.py Create dnsimple_info.py Create dnsimple_info.py pep8 Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update dnsimple_info.py add returns pep8 spacing Update dnsimple_info.py Update dnsimple_info.py change return results to list fix time stamps Update dnsimple_info.py remove extra comma Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update dnsimple_info.py fix descriptions Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py missing punctuation throughout docs Update dnsimple_info.py add elements in descriptions Update dnsimple_info.py indentation error Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py Update dnsimple_info.py refactor, remove unneeded arguments refactor and error handling formatting add unit test Update test_dnsimple_info.py Update test_dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update plugins/modules/net_tools/dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py assert fail/exit Update test_dnsimple_info.py pep8 fixes Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Update test_dnsimple_info.py Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2021-12-11 21:14:32 +01:00
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args, AnsibleExitJson
from httmock import response
from httmock import with_httmock
from httmock import urlmatch
import pytest
dnsimple = pytest.importorskip('dnsimple_info')
@urlmatch(netloc='(.)*dnsimple.com(.)*',
path='/v2/[0-9]*/zones/')
def zones_resp(url, request):
"""return domains"""
headers = {'content-type': 'application/json'}
data_content = {"data":
[{"account_id": "1234", }, ],
"pagination": {"total_pages": 1}}
content = data_content
return response(200, content, headers, None, 5, request)
@urlmatch(netloc='(.)*dnsimple.com(.)*',
path='/v2/[0-9]*/zones/(.)*/records(.*)')
def records_resp(url, request):
"""return record(s)"""
headers = {'content-type': 'application/json'}
data_content = {"data":
[{"content": "example",
"name": "example.com"}],
"pagination": {"total_pages": 1}}
content = data_content
return response(200, content, headers, None, 5, request)
class TestDNSimple_Info(ModuleTestCase):
"""Main class for testing dnsimple module."""
def setUp(self):
"""Setup."""
super(TestDNSimple_Info, self).setUp()
self.module = dnsimple_info
def tearDown(self):
"""Teardown."""
super(TestDNSimple_Info, self).tearDown()
def test_with_no_parameters(self):
"""Failure must occurs when all parameters are missing"""
with self.assertRaises(AnsibleFailJson):
set_module_args({})
self.module.main()
@with_httmock(zones_resp)
def test_only_key_and_account(self):
"""key and account will pass, returns domains"""
account_id = "1234"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
"api_key": "abcd1324",
"account_id": account_id
})
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])
# we should return at least one item with the matching account ID
assert result['dnsimple_domain_info'][0]["account_id"] == account_id
@with_httmock(records_resp)
def test_only_name_without_record(self):
"""name and no record should not fail, returns the record"""
name = "example.com"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
"api_key": "abcd1324",
"name": "example.com",
"account_id": "1234"
})
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])
# we should return at least one item with mathing domain
assert result['dnsimple_records_info'][0]['name'] == name
@with_httmock(records_resp)
def test_name_and_record(self):
"""name and record should not fail, returns the record"""
record = "example"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
"api_key": "abcd1324",
"account_id": "1234",
"name": "example.com",
"record": "example"
})
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])
# we should return at least one item and content should match
assert result['dnsimple_record_info'][0]['content'] == record