diff --git a/models.py b/models.py index d546476..9a9c919 100644 --- a/models.py +++ b/models.py @@ -93,13 +93,23 @@ class Device: '''Generate a JSON format request body''' obj = { - 'devices': [{ - 'mac': self.mac, - 'sensors': [], - }] + 'devices': [ + self._json_device_obj(), + ] + } + + return json.dumps(obj) + + def _json_device_obj(self) -> dict[str, Any]: + '''Create a device JSON object for json_req_data(). + Moved to a separate function to allow performing tests + with multiple devices in a request at once.''' + + dev = { + 'mac': self.mac, + 'sensors': [], } - dev = obj['devices'][0] if self.name is not None: dev['name'] = self.name if self.owner is not None: @@ -121,4 +131,4 @@ class Device: sobj['name'] = s.name sl.append(sobj) - return json.dumps(obj) + return dev