@@ -1433,6 +1433,34 @@ def test_missing_tx_bytes(self):
14331433 self .assertEqual (points [0 ].get ("rx_bytes" ), 324 )
14341434 self .assertEqual (points [0 ].get ("tx_bytes" ), 0 )
14351435
1436+ def test_device_metric_view_schema_not_empty (self ):
1437+ """
1438+ Regression test for https://github.com/openwisp/openwisp-monitoring/issues/716.
1439+ Ensures DeviceMetricView uses a proper serializer (not blank)
1440+ and does not shadow DRF's schema attribute with a plain dict.
1441+ """
1442+ from ..api .views import DeviceMetricView
1443+ from ..api .serializers import MonitoringDeviceDetailSerializer
1444+
1445+ # serializer_class must be the concrete serializer, not blank
1446+ self .assertIs (
1447+ DeviceMetricView .serializer_class ,
1448+ MonitoringDeviceDetailSerializer ,
1449+ )
1450+ # Serializer must expose real fields
1451+ fields = MonitoringDeviceDetailSerializer ().get_fields ()
1452+ self .assertTrue (len (fields ) > 0 , "Serializer should declare fields" )
1453+ for expected in ("id" , "name" , "monitoring" ):
1454+ self .assertIn (expected , fields )
1455+ # The view must NOT shadow DRF's schema with a plain dict
1456+ schema_attr = getattr (DeviceMetricView , "schema" , None )
1457+ if schema_attr is not None :
1458+ self .assertFalse (
1459+ isinstance (schema_attr , dict ),
1460+ "DeviceMetricView.schema must not be a plain dict; "
1461+ "it would shadow DRF's APIView.schema and break API docs." ,
1462+ )
1463+
14361464
14371465class TestGeoApi (TestGeoMixin , AuthenticationMixin , DeviceMonitoringTestCase ):
14381466 location_model = Location
0 commit comments