Skip to content

Commit 77bad54

Browse files
committed
[chores] Made schema more consistent
additionalItems is always False required properties are defined in the object, not in the array
1 parent 4ba912c commit 77bad54

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

openwisp_monitoring/device/schema.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"type": "array",
139139
"title": "Interfaces",
140140
"uniqueItems": True,
141-
"additionalItems": True,
141+
"additionalItems": False,
142142
"items": {
143143
"type": "object",
144144
"title": "Interface",
@@ -200,26 +200,25 @@
200200
"type": "array",
201201
"title": "Wireless Clients",
202202
"additionalItems": False,
203-
"required": [
204-
"aid",
205-
"assoc",
206-
"auth",
207-
"authorized",
208-
"ht",
209-
"vht",
210-
"wds",
211-
"wmm",
212-
"wps",
213-
"mac",
214-
"mfp",
215-
"preauth",
216-
"rrm",
217-
"signature",
218-
],
219203
"items": {
220204
"type": "object",
221205
"title": "Client",
222206
"additionalProperties": False,
207+
"required": [
208+
"aid",
209+
"assoc",
210+
"auth",
211+
"authorized",
212+
"ht",
213+
"vht",
214+
"wds",
215+
"wmm",
216+
"wps",
217+
"mac",
218+
"mfp",
219+
"preauth",
220+
"signature",
221+
],
223222
"properties": {
224223
"aid": {"type": "integer"},
225224
"assoc": {"type": "boolean"},
@@ -239,7 +238,6 @@
239238
"type": "array",
240239
"minItems": 5,
241240
"maxItems": 5,
242-
"additionalItems": False,
243241
"items": {"type": "integer"},
244242
},
245243
},
@@ -251,7 +249,7 @@
251249
"type": "array",
252250
"title": "Addresses",
253251
"uniqueItems": True,
254-
"additionalItems": True,
252+
"additionalItems": False,
255253
"items": {
256254
"additionalProperties": True,
257255
"title": "Address",

openwisp_monitoring/device/tests/test_api.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,26 +160,30 @@ def test_200_multiple_measurements(self):
160160
# expected upload wlan1
161161
self.assertEqual(data['traces'][1][1][-1], 1.5)
162162

163-
def test_garbage_clients(self):
163+
def test_garbage_wireless_clients(self):
164164
o = self._create_org()
165165
d = self._create_device(organization=o)
166-
r = self._post_data(
167-
d.id,
168-
d.key,
166+
garbage_interfaces = [
167+
{'name': 'garbage1', 'wireless': {'clients': {}}},
169168
{
170-
'type': 'DeviceMonitoring',
171-
'interfaces': [
172-
{'name': 'garbage1', 'wireless': {'clients': {}}},
173-
{
174-
'name': 'garbage2',
175-
'wireless': {'clients': [{'what?': 'mac missing'}]},
176-
},
177-
{'name': 'garbage3', 'wireless': {}},
178-
{'name': 'garbage4'},
179-
],
169+
'name': 'garbage2',
170+
'wireless': {'clients': [{'what?': 'mac missing'}]},
180171
},
181-
)
182-
self.assertEqual(r.status_code, 400)
172+
{'name': 'garbage3', 'wireless': {}}
173+
]
174+
for garbage_interface in garbage_interfaces:
175+
interface = self._data()['interfaces'][0]
176+
interface.update(garbage_interface)
177+
r = self._post_data(
178+
d.id,
179+
d.key,
180+
{
181+
'type': 'DeviceMonitoring',
182+
'interfaces': [interface]
183+
}
184+
)
185+
with self.subTest(garbage_interface):
186+
self.assertEqual(r.status_code, 400)
183187

184188
@patch.object(monitoring_settings, 'AUTO_CHARTS', return_value=[])
185189
def test_auto_chart_disabled(self, *args):

0 commit comments

Comments
 (0)