Skip to content

Commit 43d33d0

Browse files
committed
Add unit tests for httpapi connection plugin
1 parent e94eda3 commit 43d33d0

File tree

5 files changed

+1354
-0
lines changed

5 files changed

+1354
-0
lines changed

tests/unit/plugins/__init__.py

Whitespace-only changes.

tests/unit/plugins/httpapi/__init__.py

Whitespace-only changes.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Copyright (c) 2025 Cisco and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Fixtures for HttpApi tests
17+
"""
18+
19+
import pytest
20+
from unittest.mock import Mock, MagicMock
21+
22+
23+
@pytest.fixture
24+
def mock_connection():
25+
"""Create a mock connection object."""
26+
connection = Mock()
27+
connection._url = "https://test.nd.com"
28+
connection._auth = None
29+
connection.get_option.return_value = 10
30+
return connection
31+
32+
33+
@pytest.fixture
34+
def mock_response_success():
35+
"""Create a mock successful HTTP response."""
36+
response = Mock()
37+
response.getcode.return_value = 200
38+
response.geturl.return_value = "/api/test"
39+
response.msg = "OK"
40+
return response
41+
42+
43+
@pytest.fixture
44+
def mock_response_failure():
45+
"""Create a mock failed HTTP response."""
46+
response = Mock()
47+
response.getcode.return_value = 401
48+
response.geturl.return_value = "/api/test"
49+
response.msg = "Unauthorized"
50+
return response
51+
52+
53+
@pytest.fixture
54+
def mock_response_data_json():
55+
"""Create mock response data with JSON."""
56+
rdata = Mock()
57+
rdata.getvalue.return_value = b'{"result": "success", "token": "test123"}'
58+
return rdata
59+
60+
61+
@pytest.fixture
62+
def mock_response_data_nd_token():
63+
"""Create mock response data with DCNM token."""
64+
rdata = Mock()
65+
rdata.getvalue.return_value = b'{"Dcnm-Token": "nd-token-123"}'
66+
return rdata
67+
68+
69+
@pytest.fixture
70+
def mock_response_data_ndfc_token():
71+
"""Create mock response data with NDFC token."""
72+
rdata = Mock()
73+
rdata.getvalue.return_value = b'{"token": "ndfc-token-456"}'
74+
return rdata
75+
76+
77+
@pytest.fixture
78+
def nd_login_config():
79+
"""Standard DCNM login configuration."""
80+
return {"controller_type": "DCNM", "version": 11, "path": "/rest/logon", "data": "{'expirationTime': 10000}", "force_basic_auth": True}
81+
82+
83+
@pytest.fixture
84+
def ndfc_login_config():
85+
"""Standard NDFC login configuration."""
86+
return {
87+
"controller_type": "NDFC",
88+
"version": 12,
89+
"path": "/login",
90+
"data": '{"userName": "admin", "userPasswd": "password", "domain": "local"}',
91+
"force_basic_auth": False,
92+
}
93+
94+
95+
@pytest.fixture
96+
def nd_logout_config():
97+
"""Standard DCNM logout configuration."""
98+
return {"controller_type": "DCNM", "path": "/rest/logout", "data": "test-token", "force_basic_auth": True}
99+
100+
101+
@pytest.fixture
102+
def ndfc_logout_config():
103+
"""Standard NDFC logout configuration."""
104+
return {"controller_type": "NDFC", "path": "/logout", "data": {}, "force_basic_auth": False}

0 commit comments

Comments
 (0)