@@ -34,6 +34,10 @@ def default_config() -> Dict:
34
34
35
35
36
36
_RESPONSE_DATA_DIR = "tests/unit/poller/controller/sources/nautobot/responses/"
37
+ _BASE_URL = "https://127.0.0.1:8080/api/"
38
+ _DEVICES_URL = "https://127.0.0.1:8080/api/dcim/devices/"
39
+ _IP_ADDRESSES_URL = "https://127.0.0.1:8080/api/ipam/ip-addresses/"
40
+ _LOCATIONS_URL = "https://127.0.0.1:8080/api/dcim/locations/"
37
41
38
42
_TEST_CONFIGS = [
39
43
{
@@ -44,24 +48,26 @@ def default_config() -> Dict:
44
48
},
45
49
"test_params" : {
46
50
"test_urls" : {
47
- "https://127.0.0.1:8080/api/" : get_json (
48
- _RESPONSE_DATA_DIR + "base_response.json"
49
- ),
50
- "https://127.0.0.1:8080/api/dcim/devices/" : get_json (
51
+ _BASE_URL : get_json (_RESPONSE_DATA_DIR + "base_response.json" ),
52
+ _DEVICES_URL : get_json (
51
53
_RESPONSE_DATA_DIR + "all-devices.json"
52
54
),
53
55
# ang01-edge-01
54
- "https://127.0.0.1:8080/api/ipam/ip-addresses/fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
56
+ _IP_ADDRESSES_URL
57
+ + "fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
55
58
_RESPONSE_DATA_DIR + "ang01-edge-01_ip.json"
56
59
),
57
- "https://127.0.0.1:8080/api/dcim/locations/279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
60
+ _LOCATIONS_URL
61
+ + "279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
58
62
_RESPONSE_DATA_DIR + "ang01-edge-01_location.json"
59
63
),
60
64
# azd01-leaf-07
61
- "https://127.0.0.1:8080/api/ipam/ip-addresses/94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
65
+ _IP_ADDRESSES_URL
66
+ + "94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
62
67
_RESPONSE_DATA_DIR + "azd01-leaf-07_ip.json"
63
68
),
64
- "https://127.0.0.1:8080/api/dcim/locations/f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
69
+ _LOCATIONS_URL
70
+ + "f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
65
71
_RESPONSE_DATA_DIR + "azd01-leaf-07_location.json"
66
72
),
67
73
},
@@ -78,24 +84,26 @@ def default_config() -> Dict:
78
84
},
79
85
"test_params" : {
80
86
"test_urls" : {
81
- "https://127.0.0.1:8080/api/" : get_json (
82
- _RESPONSE_DATA_DIR + "base_response.json"
83
- ),
84
- "https://127.0.0.1:8080/api/dcim/devices/" : get_json (
87
+ _BASE_URL : get_json (_RESPONSE_DATA_DIR + "base_response.json" ),
88
+ _DEVICES_URL : get_json (
85
89
_RESPONSE_DATA_DIR + "all-devices.json"
86
90
),
87
91
# ang01-edge-01
88
- "https://127.0.0.1:8080/api/ipam/ip-addresses/fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
92
+ _IP_ADDRESSES_URL
93
+ + "fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
89
94
_RESPONSE_DATA_DIR + "ang01-edge-01_ip.json"
90
95
),
91
- "https://127.0.0.1:8080/api/dcim/locations/279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
96
+ _LOCATIONS_URL
97
+ + "279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
92
98
_RESPONSE_DATA_DIR + "ang01-edge-01_location.json"
93
99
),
94
100
# azd01-leaf-07
95
- "https://127.0.0.1:8080/api/ipam/ip-addresses/94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
101
+ _IP_ADDRESSES_URL
102
+ + "94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
96
103
_RESPONSE_DATA_DIR + "azd01-leaf-07_ip.json"
97
104
),
98
- "https://127.0.0.1:8080/api/dcim/locations/f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
105
+ _LOCATIONS_URL
106
+ + "f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
99
107
_RESPONSE_DATA_DIR + "azd01-leaf-07_location.json"
100
108
),
101
109
},
@@ -113,17 +121,18 @@ def default_config() -> Dict:
113
121
},
114
122
"test_params" : {
115
123
"test_urls" : {
116
- "https://127.0.0.1:8080/api/" : get_json (
117
- _RESPONSE_DATA_DIR + "base_response.json"
118
- ),
119
- "https://127.0.0.1:8080/api/dcim/devices/?"
124
+ _BASE_URL : get_json (_RESPONSE_DATA_DIR + "base_response.json" ),
125
+ _DEVICES_URL
126
+ + "?"
120
127
+ urllib .parse .urlencode ({"name" : "ang01-edge-01" }): get_json (
121
128
_RESPONSE_DATA_DIR + "ang01-edge-01_device.json"
122
129
),
123
- "https://127.0.0.1:8080/api/ipam/ip-addresses/fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
130
+ _IP_ADDRESSES_URL
131
+ + "fe06d6c1-b233-4499-b5e9-f36af5a72dc3/" : get_json (
124
132
_RESPONSE_DATA_DIR + "ang01-edge-01_ip.json"
125
133
),
126
- "https://127.0.0.1:8080/api/dcim/locations/279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
134
+ _LOCATIONS_URL
135
+ + "279b30b2-7aee-45be-8086-9d151ce22799/" : get_json (
127
136
_RESPONSE_DATA_DIR + "ang01-edge-01_location.json"
128
137
),
129
138
},
@@ -141,17 +150,18 @@ def default_config() -> Dict:
141
150
},
142
151
"test_params" : {
143
152
"test_urls" : {
144
- "https://127.0.0.1:8080/api/" : get_json (
145
- _RESPONSE_DATA_DIR + "base_response.json"
146
- ),
147
- "https://127.0.0.1:8080/api/dcim/devices/?"
153
+ _BASE_URL : get_json (_RESPONSE_DATA_DIR + "base_response.json" ),
154
+ _DEVICES_URL
155
+ + "?"
148
156
+ urllib .parse .urlencode ({"location" : "AZD01" }): get_json (
149
157
_RESPONSE_DATA_DIR + "azd01-leaf-07_device.json"
150
158
),
151
- "https://127.0.0.1:8080/api/ipam/ip-addresses/94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
159
+ _IP_ADDRESSES_URL
160
+ + "94f6cbb7-2897-4b9e-91ef-573f9c0b44d8/" : get_json (
152
161
_RESPONSE_DATA_DIR + "azd01-leaf-07_ip.json"
153
162
),
154
- "https://127.0.0.1:8080/api/dcim/locations/f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
163
+ _LOCATIONS_URL
164
+ + "f6aa82a1-c61a-4b3e-8f4d-03e09e32feb6/" : get_json (
155
165
_RESPONSE_DATA_DIR + "azd01-leaf-07_location.json"
156
166
),
157
167
},
@@ -193,7 +203,9 @@ def update_config(server_conf: Dict, config: Dict) -> Dict:
193
203
@pytest .mark .controller_source_nautobot
194
204
@pytest .mark .asyncio
195
205
@pytest .mark .parametrize ("test_conf" , _TEST_CONFIGS )
196
- async def test_valid_config (test_conf , default_config ):
206
+ async def test_valid_config (
207
+ test_conf , default_config
208
+ ): # pylint: disable=redefined-outer-name
197
209
"""Tests if the pulled inventory is valid
198
210
199
211
Args:
@@ -219,7 +231,9 @@ async def test_valid_config(test_conf, default_config):
219
231
@pytest .mark .controller_unit_tests
220
232
@pytest .mark .controller_source_nautobot
221
233
@pytest .mark .asyncio
222
- async def test_invalid_filters (default_config ):
234
+ async def test_invalid_filters (
235
+ default_config ,
236
+ ): # pylint: disable=redefined-outer-name
223
237
"""Tests for invalid filter parameters.
224
238
225
239
Args:
@@ -245,7 +259,8 @@ async def test_invalid_filters(default_config):
245
259
with pytest .raises (InventorySourceError ) as exc_info :
246
260
src = Nautobot (config .copy ())
247
261
await asyncio .wait_for (src .run (), 10 )
248
- assert (
249
- exc_info .value .args [0 ]
250
- == "nautobot0: error while getting devices: The request failed with code 400 Bad Request: {'foo': ['Unknown filter field']}"
262
+ assert exc_info .value .args [0 ] == (
263
+ "nautobot0: error while getting devices: "
264
+ "The request failed with code 400 Bad Request: "
265
+ "{'foo': ['Unknown filter field']}"
251
266
)
0 commit comments