41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
from apim_apps import AxwayClient, _AppendOnlySession, EnvConfig
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
env = EnvConfig(name="TEST", url="https://test.example.com:8075", username="u", password="p")
|
|
return AxwayClient(env)
|
|
|
|
|
|
def test_session_is_append_only(client):
|
|
assert isinstance(client.session, _AppendOnlySession)
|
|
|
|
|
|
def test_delete_raises_runtime_error(client):
|
|
with pytest.raises(RuntimeError, match="DELETE is not allowed"):
|
|
client.session.delete("https://test.example.com:8075/api/portal/v1.4/applications/123")
|
|
|
|
|
|
def test_get_is_allowed(client):
|
|
with patch("requests.Session.request") as mock_req:
|
|
mock_req.return_value = MagicMock(status_code=200)
|
|
client.session.get("https://test.example.com")
|
|
mock_req.assert_called_once()
|
|
assert mock_req.call_args[0][0].upper() == "GET"
|
|
|
|
|
|
def test_post_is_allowed(client):
|
|
with patch("requests.Session.request") as mock_req:
|
|
mock_req.return_value = MagicMock(status_code=201)
|
|
client.session.post("https://test.example.com", json={})
|
|
mock_req.assert_called_once()
|
|
assert mock_req.call_args[0][0].upper() == "POST"
|
|
|
|
|
|
def test_no_delete_method_on_client():
|
|
"""AxwayClient must not expose any delete_* method."""
|
|
delete_methods = [m for m in dir(AxwayClient) if m.startswith("delete")]
|
|
assert delete_methods == [], f"Unexpected delete methods found: {delete_methods}"
|