Skip to content

Commit

Permalink
Add unit tests for ControllerVersion().is_controller_version_4x
Browse files Browse the repository at this point in the history
Add two unit tests to verify correct values are returned for ND 3.x and ND 4.x NDFC versions.
  • Loading branch information
allenrobel committed Jan 7, 2025
1 parent da30b01 commit c815529
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/unit/module_utils/common/fixtures/responses_ep_version.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,43 @@
"uuid": "",
"is_upgrade_inprogress": "false"
}
},
"test_controller_version_00300a": {
"TEST_NOTES": [
"12.2.2.238 implies ND 3.x"
],
"RETURN_CODE": 200,
"METHOD": "GET",
"REQUEST_PATH": "https://172.22.150.244:443/appcenter/cisco/ndfc/api/v1/fm/about/version",
"MESSAGE": "OK",
"DATA": {
"version": "12.2.2.238",
"mode": "LAN",
"isMediaController": "false",
"dev": "false",
"isHaEnabled": "false",
"install": "EASYFABRIC",
"uuid": "",
"is_upgrade_inprogress": "false"
}
},
"test_controller_version_00300b": {
"TEST_NOTES": [
"12.3.1.248 implies ND 4.x"
],
"RETURN_CODE": 200,
"METHOD": "GET",
"REQUEST_PATH": "https://172.22.150.244:443/appcenter/cisco/ndfc/api/v1/fm/about/version",
"MESSAGE": "OK",
"DATA": {
"version": "12.3.1.248",
"mode": "LAN",
"isMediaController": "false",
"dev": "false",
"isHaEnabled": "false",
"install": "EASYFABRIC",
"uuid": "",
"is_upgrade_inprogress": "false"
}
}
}
51 changes: 51 additions & 0 deletions tests/unit/module_utils/common/test_controller_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,3 +827,54 @@ def responses():
instance.rest_send = rest_send
instance.refresh()
assert instance.version_patch == expected


@pytest.mark.parametrize(
"key, expected",
[
("test_controller_version_00300a", False),
("test_controller_version_00300b", True),
],
)
def test_controller_version_00300(controller_version, key, expected) -> None:
"""
### Classes and Methods
- ``ControllerVersion()``
- ``refresh``
- ``is_controller_version_4x``
### Test
- is_controller_version_4x returns expected values
### Description
``is_controller_version_4x`` returns:
- True, if int(self.version_major) == 12 and int(self.version_minor) >= 3.
- False, if int(self.version_major) == 12 and int(self.version_minor) < 3.
### Expected result
1. test_controller_version_00300a is True
2. test_controller_version_00300b is False
"""

def responses():
yield responses_ep_version(key)

gen_responses = ResponseGenerator(responses())

sender = Sender()
sender.ansible_module = MockAnsibleModule()
sender.gen = gen_responses
rest_send = RestSend(params)
rest_send.response_handler = ResponseHandler()
rest_send.sender = sender

with does_not_raise():
instance = controller_version
instance.rest_send = rest_send
instance.refresh()
assert instance.is_controller_version_4x == expected

0 comments on commit c815529

Please sign in to comment.