Reformat everything.

This commit is contained in:
Felix Fontein
2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View File

@@ -1,4 +1,3 @@
# 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
@@ -7,33 +6,38 @@ from __future__ import annotations
from ansible_collections.community.general.plugins.modules import dnsimple_info
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleFailJson, ModuleTestCase, set_module_args, AnsibleExitJson
from ansible_collections.community.internal_test_tools.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
@urlmatch(netloc='(.)*dnsimple.com(.)*',
path='/v2/[0-9]*/zones/')
@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}}
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(.*)')
@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}}
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)
@@ -42,7 +46,6 @@ class TestDNSimple_Info(ModuleTestCase):
"""Main class for testing dnsimple module."""
def setUp(self):
"""Setup."""
super().setUp()
self.module = dnsimple_info
@@ -62,48 +65,38 @@ class TestDNSimple_Info(ModuleTestCase):
"""key and account will pass, returns domains"""
account_id = "1234"
with self.assertRaises(AnsibleExitJson) as exc_info:
with set_module_args({
"api_key": "abcd1324",
"account_id": account_id
}):
with 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'])
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
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:
with set_module_args({
"api_key": "abcd1324",
"name": "example.com",
"account_id": "1234"
}):
with 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'])
self.assertFalse(result["changed"])
# we should return at least one item with matching domain
assert result['dnsimple_records_info'][0]['name'] == name
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:
with set_module_args({
"api_key": "abcd1324",
"account_id": "1234",
"name": "example.com",
"record": "example"
}):
with 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'])
self.assertFalse(result["changed"])
# we should return at least one item and content should match
assert result['dnsimple_record_info'][0]['content'] == record
assert result["dnsimple_record_info"][0]["content"] == record