Initial commit
This commit is contained in:
commit
1b51716d1b
72 changed files with 8204 additions and 0 deletions
18
tests/api/__init__.py
Normal file
18
tests/api/__init__.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
"""API related tests"""
|
||||
from argparse import Namespace
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def secrets():
|
||||
"""Deprecated"""
|
||||
return {"server": "idrac-01", "username": "root", "password": "secrete"}
|
||||
|
||||
|
||||
def args(**kwargs):
|
||||
"""Base args for tests"""
|
||||
kwargs.update(
|
||||
{"server": "idrac-01", "username": "root", "password": "secrete"}
|
||||
)
|
||||
return Namespace(**kwargs)
|
||||
253
tests/api/test_api.py
Normal file
253
tests/api/test_api.py
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
"""
|
||||
Tests of the api
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
import requests
|
||||
|
||||
import redfish_cli.api
|
||||
import redfish_cli.api.storage
|
||||
import redfish_cli.api.systems
|
||||
from redfish_cli.api.exceptions import (
|
||||
ResponseNotOK,
|
||||
Unauthorized,
|
||||
)
|
||||
|
||||
from ..utils import get_test_json, MockRedfishResponse, MockResponse
|
||||
|
||||
|
||||
# pylint: disable=missing-function-docstring,redefined-outer-name
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def secrets():
|
||||
return {"server": "idrac-01", "username": "root", "password": "secrete"}
|
||||
|
||||
|
||||
def test_chassis(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("api_chassis.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
chassis = redfish_cli.api.chassis(**secrets)
|
||||
assert chassis["Name"] == "Chassis Collection"
|
||||
|
||||
|
||||
def test_chassis_details(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("api_chassis_details.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
secrets.update({"chassis": "System.Embedded.1"})
|
||||
chassis_details = redfish_cli.api.chassis_details(**secrets)
|
||||
assert chassis_details["Name"] == "Computer System Chassis"
|
||||
|
||||
|
||||
def test_get_base_redfish(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
_ = redfish_cli.api.utils.get(secrets["server"], "")
|
||||
assert "@odata.id" in redfish_cli.api.utils.get(secrets["server"], "")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "get", lambda *args, **kwargs: MockResponse(ok=False)
|
||||
)
|
||||
with pytest.raises(ResponseNotOK):
|
||||
_ = redfish_cli.api.utils.get(secrets["server"], "")
|
||||
|
||||
|
||||
def test_invalid_json(monkeypatch, secrets):
|
||||
"""Test processing of invalid json returned from a get"""
|
||||
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
return MockResponse(content="{'a':'invalid json'}")
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
secrets.update({"url": "/"})
|
||||
|
||||
with pytest.raises(json.decoder.JSONDecodeError):
|
||||
_ = redfish_cli.api.utils.get(**secrets)
|
||||
|
||||
|
||||
def test_post(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
_json = {"@odata.id": "dummy"}
|
||||
return MockResponse(content=json.dumps(_json))
|
||||
|
||||
monkeypatch.setattr(requests, "post", mock_get)
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
assert (
|
||||
"@odata.id"
|
||||
in redfish_cli.api.utils.post(
|
||||
secrets["server"], "", username="test", password="test"
|
||||
).json()
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(status_code=401)
|
||||
)
|
||||
with pytest.raises(Unauthorized):
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(ok=False)
|
||||
)
|
||||
with pytest.raises(ResponseNotOK):
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(content="Invalid json"),
|
||||
)
|
||||
|
||||
|
||||
def test_product(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
assert (
|
||||
redfish_cli.api.product(secrets["server"])
|
||||
== "Integrated Dell Remote Access Controller"
|
||||
)
|
||||
|
||||
|
||||
def test_response_not_ok():
|
||||
try:
|
||||
raise ResponseNotOK
|
||||
except ResponseNotOK as exc:
|
||||
assert exc.response is None
|
||||
|
||||
|
||||
def test_service_tag(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
assert "JYYZY42" in redfish_cli.api.service_tag(secrets["server"])
|
||||
|
||||
def mock_get_hp(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict["Oem"] = {"HPE": {}}
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get_hp)
|
||||
with pytest.raises(redfish_cli.api.exceptions.DellOnly):
|
||||
assert "JYYZY42" in redfish_cli.api.service_tag(secrets["server"])
|
||||
|
||||
|
||||
def test_system_details(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("system_details.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
assert (
|
||||
"/redfish/v1/Systems/System.Embedded.1"
|
||||
== redfish_cli.api.systems.system_details(
|
||||
secrets["server"],
|
||||
secrets["username"],
|
||||
secrets["password"],
|
||||
"System.Embedded.1",
|
||||
)["@odata.id"]
|
||||
)
|
||||
|
||||
|
||||
def test_unauthorized(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
return MockResponse(status_code=401, content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
secrets.update({"url": "/"})
|
||||
|
||||
with pytest.raises(redfish_cli.api.exceptions.Unauthorized):
|
||||
_ = redfish_cli.api.utils.get(**secrets)
|
||||
|
||||
|
||||
def test_version(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
assert redfish_cli.api.redfish_version(secrets["server"]) == "1.4.0"
|
||||
|
||||
|
||||
def test_manager(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("api_manager.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
args = argparse.Namespace()
|
||||
args.server = secrets["server"]
|
||||
args.username = secrets["username"]
|
||||
args.password = secrets["password"]
|
||||
args.manager = None
|
||||
|
||||
assert (
|
||||
redfish_cli.api.manager(args)["@odata.id"]
|
||||
== "/redfish/v1/Managers/iDRAC.Embedded.1"
|
||||
)
|
||||
|
||||
args = argparse.Namespace()
|
||||
args.server = secrets["server"]
|
||||
args.username = secrets["username"]
|
||||
args.password = secrets["password"]
|
||||
|
||||
assert (
|
||||
redfish_cli.api.manager(args)["@odata.id"]
|
||||
== "/redfish/v1/Managers/iDRAC.Embedded.1"
|
||||
)
|
||||
|
||||
|
||||
def test_firmware_version(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("api_manager.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
args = argparse.Namespace()
|
||||
args.server = secrets["server"]
|
||||
args.username = secrets["username"]
|
||||
args.password = secrets["password"]
|
||||
args.manager = None
|
||||
|
||||
assert redfish_cli.api.firmware_version(args) == 2656565
|
||||
40
tests/api/test_jobs.py
Normal file
40
tests/api/test_jobs.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Tests relating to the jobs api"""
|
||||
import requests
|
||||
|
||||
from redfish_cli.api import jobs
|
||||
|
||||
from tests.api import args
|
||||
|
||||
from ..utils import MockResponse, get_test_content
|
||||
|
||||
|
||||
def test_job_details(monkeypatch):
|
||||
"""Test getting job details"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content=get_test_content("api_job_details.json")
|
||||
),
|
||||
)
|
||||
|
||||
_args = args(manager="Manager.1", job_id="JOB12345xdz")
|
||||
|
||||
result = jobs.job_details(_args)
|
||||
assert result["Id"] == "JID_924369311959"
|
||||
|
||||
|
||||
def test_job_list(monkeypatch):
|
||||
"""Test getting job details"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content=get_test_content("jobs_list.json")
|
||||
),
|
||||
)
|
||||
|
||||
_args = args(manager="Manager.1")
|
||||
|
||||
result = jobs.jobs_list(_args)
|
||||
assert result["Members@odata.count"] == 5
|
||||
104
tests/api/test_power.py
Normal file
104
tests/api/test_power.py
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
"""Tests for the power related API functions"""
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from redfish_cli.api import power
|
||||
from redfish_cli.api.exceptions import FailedToSetPowerState
|
||||
from tests.api import args
|
||||
|
||||
from ..utils import get_test_json, MockRedfishResponse, MockResponse
|
||||
|
||||
|
||||
def test_power_state(monkeypatch):
|
||||
"""Test the get power_state API call"""
|
||||
|
||||
def mock_get(*aargs, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("api_power_state.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
_args = args()
|
||||
_args.system = "System.Embedded.1"
|
||||
|
||||
power_state = power.system_power_state(_args)
|
||||
assert power_state == "Off"
|
||||
|
||||
|
||||
def test_power_states_allowed(monkeypatch):
|
||||
"""Test the poert starts allowed API function"""
|
||||
|
||||
def mock_get(*aargs, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json("power_states_allowed.json")
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
_args = args()
|
||||
_args.system = "system"
|
||||
|
||||
power_states = power.system_power_states_allowed(_args)
|
||||
assert power_states == [
|
||||
"On",
|
||||
"ForceOff",
|
||||
"ForceRestart",
|
||||
"GracefulShutdown",
|
||||
"PushPowerButton",
|
||||
"Nmi",
|
||||
]
|
||||
|
||||
|
||||
def test_set_power_state(monkeypatch):
|
||||
"""Test the set power state API call"""
|
||||
|
||||
def mock_post(*aargs, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
return MockResponse(content="{}")
|
||||
|
||||
monkeypatch.setattr(requests, "post", mock_post)
|
||||
|
||||
_args = args()
|
||||
_args.system = "System.Embedded.1"
|
||||
_args.power_state = "On"
|
||||
|
||||
result = power.system_set_power_state(_args)
|
||||
assert result == "Powerstate set to On"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(ok=False)
|
||||
)
|
||||
with pytest.raises(FailedToSetPowerState):
|
||||
_ = power.system_set_power_state(_args)
|
||||
|
||||
|
||||
def test_system_reset(monkeypatch):
|
||||
"""Test resetting a system"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}"
|
||||
),
|
||||
)
|
||||
|
||||
_args = args(
|
||||
system="System.Embedded.1",
|
||||
)
|
||||
|
||||
result = power.system_reset(_args)
|
||||
assert result == "System reset"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False
|
||||
),
|
||||
)
|
||||
|
||||
with pytest.raises(FailedToSetPowerState):
|
||||
result = power.system_reset(_args)
|
||||
210
tests/api/test_storage.py
Normal file
210
tests/api/test_storage.py
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
"""Tests relating to the storage api"""
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import redfish_cli
|
||||
from redfish_cli.api import storage
|
||||
from redfish_cli.api.exceptions import ResponseNotOK
|
||||
|
||||
from tests.api import args
|
||||
|
||||
from ..utils import (
|
||||
MockRedfishResponse,
|
||||
MockResponse,
|
||||
get_test_content,
|
||||
get_test_json,
|
||||
)
|
||||
|
||||
|
||||
def test_create_logical_volume(monkeypatch):
|
||||
"""Test creating a logical volume"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"Location": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
monkeypatch.setattr(redfish_cli.api, "firmware_version", lambda args: 2)
|
||||
|
||||
_args = args(
|
||||
raid_level="0",
|
||||
size=None,
|
||||
stripe_size=None,
|
||||
name="test",
|
||||
secure=None,
|
||||
disk_cache_policy=None,
|
||||
read_cache_policy=None,
|
||||
write_cache_policy=None,
|
||||
disk=["one"],
|
||||
system="System.Embedded.1",
|
||||
controller="Raid-Controller-1",
|
||||
)
|
||||
|
||||
result = storage.create_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
monkeypatch.setattr(
|
||||
redfish_cli.api, "firmware_version", lambda args: 445445445
|
||||
)
|
||||
result = storage.create_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
# Test setting size
|
||||
_args.size = 300000000
|
||||
result = storage.create_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
# Test setting stripe_size
|
||||
_args.stripe_size = 3000
|
||||
result = storage.create_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
# Test setting other parameters
|
||||
_args.secure = "Something"
|
||||
_args.disk_cache_policy = "Something"
|
||||
_args.read_cache_policy = "Something"
|
||||
_args.write_cache_policy = "Something"
|
||||
result = storage.create_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"NoLocation": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
|
||||
with pytest.raises(redfish_cli.api.exceptions.FailedToGetJobID):
|
||||
result = storage.create_logical_volume(_args)
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False, content="{}", headers={"NoLocation": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
|
||||
with pytest.raises(
|
||||
redfish_cli.api.exceptions.LogicalVolumeCreationFailure
|
||||
):
|
||||
result = storage.create_logical_volume(_args)
|
||||
|
||||
_args.raid_level = "77"
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"NoLocation": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
|
||||
with pytest.raises(redfish_cli.api.exceptions.InvalidRaidLevel):
|
||||
result = storage.create_logical_volume(_args)
|
||||
|
||||
|
||||
def test_delete_logical_volume(monkeypatch):
|
||||
"""Test deleting a logical volume"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={"Location": "/JOB12345"}
|
||||
),
|
||||
)
|
||||
|
||||
_args = args(
|
||||
disk="disk1",
|
||||
verify=None,
|
||||
)
|
||||
|
||||
result = storage.delete_logical_volume(_args)
|
||||
assert result["job_id"] == "JOB12345"
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="{}", headers={}
|
||||
),
|
||||
)
|
||||
with pytest.raises(redfish_cli.api.exceptions.FailedToGetJobID):
|
||||
result = storage.delete_logical_volume(_args)
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False
|
||||
),
|
||||
)
|
||||
with pytest.raises(ResponseNotOK):
|
||||
result = storage.delete_logical_volume(_args)
|
||||
|
||||
|
||||
def test_list_logical_volumes(monkeypatch):
|
||||
"""Test the list logical volumes api call"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"get",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content=get_test_content("api_list_logical_volumes.json")
|
||||
),
|
||||
)
|
||||
|
||||
_args = args(
|
||||
system="System.Embedded.1",
|
||||
controller="RAID.Slot.6-1",
|
||||
expand=True,
|
||||
)
|
||||
logical_volumes = redfish_cli.api.storage.list_logical_volumes(_args)
|
||||
assert logical_volumes["Name"] == "Volume Collection"
|
||||
|
||||
_args.controller = ""
|
||||
logical_volumes = redfish_cli.api.storage.list_logical_volumes(_args)
|
||||
assert logical_volumes["Name"] == "Volume Collection"
|
||||
|
||||
|
||||
def test_list_storage_controllers(monkeypatch):
|
||||
"""Test the list storage controllers api call"""
|
||||
|
||||
def mock_get(*aargs, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json(
|
||||
"api_list_storage_controllers.json"
|
||||
)
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
_args = args(system="System.Embedded.1")
|
||||
storage_controllers = redfish_cli.api.storage.list_storage_controllers(
|
||||
_args
|
||||
)
|
||||
assert storage_controllers["Name"] == "Storage Collection"
|
||||
|
||||
|
||||
def test_logical_volume_details(monkeypatch):
|
||||
"""Test the logical volume details API call"""
|
||||
|
||||
def mock_get(*aargs, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
mock_redfish = MockRedfishResponse()
|
||||
mock_redfish.json_dict = get_test_json(
|
||||
"api_logical_volume_details.json"
|
||||
)
|
||||
return MockResponse(content=mock_redfish.text)
|
||||
|
||||
monkeypatch.setattr(requests, "get", mock_get)
|
||||
|
||||
_args = args(
|
||||
drive="Disk.Virtual.0:RAID.Slot.6-1", drive_index="0", system="system"
|
||||
)
|
||||
|
||||
logical_volume_details = redfish_cli.api.storage.logical_volume_details(
|
||||
_args
|
||||
)
|
||||
assert logical_volume_details["Name"] == "os"
|
||||
105
tests/api/test_utils.py
Normal file
105
tests/api/test_utils.py
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
"""
|
||||
Tests of the api
|
||||
"""
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
import requests
|
||||
|
||||
import redfish_cli.api
|
||||
import redfish_cli.api.storage
|
||||
import redfish_cli.api.systems
|
||||
from redfish_cli.api.exceptions import (
|
||||
ResponseNotOK,
|
||||
Unauthorized,
|
||||
)
|
||||
|
||||
from ..utils import MockResponse
|
||||
from ..api import args
|
||||
|
||||
|
||||
# pylint: disable=missing-function-docstring,redefined-outer-name
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def secrets():
|
||||
return {"server": "idrac-01", "username": "root", "password": "secrete"}
|
||||
|
||||
|
||||
def test_post(monkeypatch, secrets):
|
||||
def mock_get(*args, **kwargs):
|
||||
# pylint: disable=unused-argument
|
||||
_json = {"@odata.id": "dummy"}
|
||||
return MockResponse(content=json.dumps(_json))
|
||||
|
||||
monkeypatch.setattr(requests, "post", mock_get)
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
assert (
|
||||
"@odata.id"
|
||||
in redfish_cli.api.utils.post(
|
||||
secrets["server"], "", username="test", password="test"
|
||||
).json()
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(status_code=401)
|
||||
)
|
||||
with pytest.raises(Unauthorized):
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests, "post", lambda *args, **kwargs: MockResponse(ok=False)
|
||||
)
|
||||
with pytest.raises(ResponseNotOK):
|
||||
_ = redfish_cli.api.utils.post(secrets["server"], "")
|
||||
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"post",
|
||||
lambda *args, **kwargs: MockResponse(content="Invalid json"),
|
||||
)
|
||||
|
||||
|
||||
def test_delete(monkeypatch):
|
||||
"""Test getting job details"""
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
content="Mock Delete"
|
||||
),
|
||||
)
|
||||
|
||||
_args = args()
|
||||
|
||||
url = redfish_cli.api.redfish_url(
|
||||
_args.server, "Systems/System.Embedded.1/Storage/Volumes/Dummy"
|
||||
)
|
||||
|
||||
_args.url = url
|
||||
|
||||
result = redfish_cli.api.utils.delete(
|
||||
_args.server,
|
||||
_args.url,
|
||||
_args.username,
|
||||
_args.password,
|
||||
)
|
||||
assert result.content == "Mock Delete"
|
||||
|
||||
with pytest.raises(ResponseNotOK):
|
||||
# pylint: disable=line-too-long
|
||||
monkeypatch.setattr(
|
||||
requests,
|
||||
"delete",
|
||||
lambda args, auth=None, verify=None, data=None, headers=None, timeout=None: MockResponse(
|
||||
ok=False
|
||||
),
|
||||
)
|
||||
|
||||
result = redfish_cli.api.utils.delete(
|
||||
_args.server,
|
||||
_args.url,
|
||||
_args.username,
|
||||
_args.password,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue