105 lines
2.5 KiB
Python
105 lines
2.5 KiB
Python
"""
|
|
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,
|
|
)
|