Skip to content

Commit

Permalink
[FIX] Updated unit test case by replacing called_once_with to assert_…
Browse files Browse the repository at this point in the history
…called_once_with for python3.12
  • Loading branch information
JkhatriInfobox committed Jul 2, 2024
1 parent 31d65e3 commit 8f74c6f
Show file tree
Hide file tree
Showing 25 changed files with 151 additions and 72 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ jobs:

- name: Generate coverage report
run: |
if [ "${{ matrix.ansible-version }}" == "stable-2.16" ]; then
pip install coverage==7.3.2;
if [ "${{ matrix.ansible-version }}" == "devel" ]; then
pip install coverage==7.5.3;
elif [ "${{ matrix.ansible-version }}" == "stable-2.15" ]; then
pip install coverage==6.5.0;
fi
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel]

steps:
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v1
with:
# it is just required to run that once as "ansible-test sanity" in the docker image
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/plugins/module_utils/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ def test_wapi_no_change(self):
def test_wapi_change(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
'comment': 'updated comment', 'extattrs': None}

ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "default",
"extattrs": {}
}
Expand All @@ -99,16 +99,16 @@ def test_wapi_change(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(test_object)
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'default'})

def test_wapi_change_false(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
'comment': 'updated comment', 'extattrs': None, 'fqdn': 'foo'}

ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "default",
"extattrs": {}
}
Expand All @@ -125,7 +125,9 @@ def test_wapi_change_false(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(test_object)
wapi.update_object.assert_called_once_with(
ref, {'comment': 'updated comment', 'name': 'default'}
)

def test_wapi_extattrs_change(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
Expand Down Expand Up @@ -161,9 +163,10 @@ def test_wapi_extattrs_nochange(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'default',
'comment': 'test comment', 'extattrs': {'Site': 'test'}}

ref = "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [{
"comment": "test comment",
"_ref": "networkview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "default",
"extattrs": {'Site': {'value': 'test'}}
}]
Expand All @@ -178,6 +181,7 @@ def test_wapi_extattrs_nochange(self):
res = wapi.run('testobject', test_spec)

self.assertFalse(res['changed'])
wapi.update_object.assert_not_called()

def test_wapi_create(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible',
Expand Down
17 changes: 10 additions & 7 deletions tests/unit/plugins/modules/test_nios_a_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _get_wapi(self, test_object):
wapi = api.WapiModule(self.module)
wapi.get_object = Mock(name='get_object', return_value=test_object)
wapi.create_object = Mock(name='create_object')
wapi.update_object = Mock(name='update_object')
wapi.update_object = Mock(name='update_object', )
wapi.delete_object = Mock(name='delete_object')
return wapi

Expand Down Expand Up @@ -86,10 +86,11 @@ def test_nios_a_record_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1',
'comment': 'updated comment', 'extattrs': None}

ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "a.ansible.com",
"ipv4": "192.168.10.1",
"extattrs": {}
Expand All @@ -105,8 +106,10 @@ def test_nios_a_record_update_comment(self):

wapi = self._get_wapi(test_object)
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(
ref, {'comment': 'updated comment', 'ipv4': '192.168.10.1', 'name': 'a.ansible.com'}
)

def test_nios_a_record_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'a.ansible.com', 'ipv4': '192.168.10.1',
Expand Down Expand Up @@ -139,12 +142,12 @@ def test_nios_a_record_update_record_name(self):
self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'a_new.ansible.com', 'old_name': 'a.ansible.com'},
'comment': 'comment', 'extattrs': None}

ref = "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "arecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"name": "a_new.ansible.com",
"old_name": "a.ansible.com",
"_ref": ref,
"name": "a.ansible.com",
"extattrs": {}
}
]
Expand All @@ -159,4 +162,4 @@ def test_nios_a_record_update_record_name(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(test_object)
wapi.update_object.assert_called_once_with(ref, {'name': 'a_new.ansible.com', 'comment': 'comment'})
19 changes: 13 additions & 6 deletions tests/unit/plugins/modules/test_nios_aaaa_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ def test_nios_aaaa_record_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'aaaa.ansible.com',
'ipv6': '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'comment': 'updated comment', 'extattrs': None}

ref = "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "aaaa.ansible.com",
"ipv6": "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
"extattrs": {}
Expand All @@ -107,6 +108,10 @@ def test_nios_aaaa_record_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(
ref,
{'comment': 'updated comment', 'ipv6': '2001:0db8:85a3:0000:0000:8a2e:0370:7334', 'name': 'aaaa.ansible.com'}
)

def test_nios_aaaa_record_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'aaaa.ansible.com',
Expand Down Expand Up @@ -138,13 +143,12 @@ def test_nios_aaaa_record_remove(self):
def test_nios_aaaa_record_update_record_name(self):
self.module.params = {'provider': None, 'state': 'present', 'name': {'new_name': 'aaaa_new.ansible.com', 'old_name': 'aaaa.ansible.com'},
'comment': 'comment', 'extattrs': None}

ref = "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "aaaarecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"name": "aaaa_new.ansible.com",
"old_name": "aaaa.ansible.com",
"_ref": ref,
"name": "aaaa.ansible.com",
"extattrs": {}
}
]
Expand All @@ -159,4 +163,7 @@ def test_nios_aaaa_record_update_record_name(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(test_object)
wapi.update_object.assert_called_once_with(
ref,
{'comment': 'comment', 'name': 'aaaa_new.ansible.com'}
)
8 changes: 6 additions & 2 deletions tests/unit/plugins/modules/test_nios_cname_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def test_nios_cname_record_create(self):
def test_nios_cname_record_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'cname.ansible.com',
'canonical': 'realhost.ansible.com', 'comment': 'updated comment', 'extattrs': None}

ref = "cnamerecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "cnamerecord/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "cname.ansible.com",
"canonical": "realhost.ansible.com",
"extattrs": {}
Expand All @@ -107,6 +107,10 @@ def test_nios_cname_record_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(
ref,
{'comment': 'updated comment', 'name': 'cname.ansible.com', 'canonical': 'realhost.ansible.com'}
)

def test_nios_cname_record_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'cname.ansible.com',
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/plugins/modules/test_nios_dns_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def _get_wapi(self, test_object):
return wapi

def load_fixtures(self, commands=None):
"""
Load fixtures for the module
"""
self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None)
self.load_config.return_value = dict(diff=None, session='session')

Expand All @@ -84,10 +87,11 @@ def test_nios_dns_view_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'ansible-dns',
'comment': 'updated comment', 'extattrs': None}

ref = "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:ansible/true"
test_object = [
{
"comment": "test comment",
"_ref": "dnsview/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "ansible-dns",
"extattrs": {}
}
Expand All @@ -103,6 +107,7 @@ def test_nios_dns_view_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'ansible-dns'})

def test_nios_dns_view_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'ansible-dns',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/plugins/modules/test_nios_dtc_monitor_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ def test_nios_dtc_monitor_http_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "https_monitor",
"port": 443,
"secure": True,
Expand All @@ -105,6 +106,7 @@ def test_nios_dtc_monitor_http_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'https_monitor'})

def test_nios_dtc_monitor_http_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'https_monitor',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def test_nios_dtc_monitor_icmp_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "icmp_monitor",
"extattrs": {}
}
Expand All @@ -100,6 +101,7 @@ def test_nios_dtc_monitor_icmp_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'icmp_monitor'})

def test_nios_dtc_monitor_icmp_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'icmp_monitor',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def test_nios_dtc_monitor_pdp_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "pdp_monitor",
"port": 2123,
"extattrs": {}
Expand All @@ -101,6 +102,7 @@ def test_nios_dtc_monitor_pdp_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'pdp_monitor'})

def test_nios_dtc_monitor_pdp_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'pdp_monitor',
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def test_nios_dtc_monitor_sip_create(self):
def test_nios_dtc_monitor_sip_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "sip_monitor",
"extattrs": {}
}
Expand All @@ -100,6 +100,7 @@ def test_nios_dtc_monitor_sip_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'sip_monitor'})

def test_nios_dtc_monitor_sip_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'sip_monitor',
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ def test_nios_dtc_monitor_snmp_create(self):
def test_nios_dtc_monitor_snmp_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "snmp_monitor",
"port": 161,
"version": "V2C",
Expand All @@ -107,6 +107,7 @@ def test_nios_dtc_monitor_snmp_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'snmp_monitor'})

def test_nios_dtc_monitor_snmp_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'snmp_monitor',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ def test_nios_dtc_monitor_tcp_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
"comment": "test comment",
"_ref": "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true",
"_ref": ref,
"name": "tcp_monitor",
"port": 8080,
"extattrs": {}
Expand All @@ -103,6 +104,7 @@ def test_nios_dtc_monitor_tcp_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'tcp_monitor'})

def test_nios_dtc_monitor_tcp_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'tcp_monitor',
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/plugins/modules/test_nios_dtc_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ def test_nios_dtc_topology_create(self):
def test_nios_dtc_topology_update_comment(self):
self.module.params = {'provider': None, 'state': 'present', 'name': 'a_topology',
'comment': 'updated comment', 'extattrs': None}

ref = "dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true"
test_object = [
{
'_ref': 'dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true',
'_ref': ref,
'name': 'a_topology',
'rules': [{
'_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool'
Expand All @@ -124,6 +124,7 @@ def test_nios_dtc_topology_update_comment(self):
res = wapi.run('testobject', test_spec)

self.assertTrue(res['changed'])
wapi.update_object.assert_called_once_with(ref, {'comment': 'updated comment', 'name': 'a_topology'})

def test_nios_dtc_topology_remove(self):
self.module.params = {'provider': None, 'state': 'absent', 'name': 'a_topology',
Expand Down
Loading

0 comments on commit 8f74c6f

Please sign in to comment.