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 3, 2024
1 parent 31d65e3 commit a4ea6e3
Show file tree
Hide file tree
Showing 26 changed files with 161 additions and 82 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ansible-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
strategy:
fail-fast: false
matrix:
ansible-version: [stable-2.14]
ansible-version: [stable-2.15]
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: '3.10'
python-version: '3.11'

- name: Install ansible (${{ matrix.ansible-version }})
run: pip install pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:

steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -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 @@ -131,7 +131,7 @@ jobs:
python-version: '3.12'
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -189,12 +189,12 @@ jobs:
ansible-version: [stable-2.15, stable-2.16, stable-2.17, devel]

steps:
- name: Set up Python 3.10
uses: actions/setup-python@v1
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
# it is just required to run that once as "ansible-test sanity" in the docker image
# will run on all python versions it supports.
python-version: '3.10'
python-version: 3.11

- name: Install ansible (${{ matrix.ansible-version }}) version
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible-version }}.tar.gz --disable-pip-version-check
Expand Down
4 changes: 2 additions & 2 deletions plugins/lookup/nios_next_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
- name: return the next 3 available IP addresses for network 192.168.10.0/24
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3,
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', num=3, \
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return the next 3 available IP addresses for network 192.168.10.0/24 excluding ip addresses - ['192.168.10.1', '192.168.10.2']
ansible.builtin.set_fact:
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
Loading

0 comments on commit a4ea6e3

Please sign in to comment.