def test_successfully_create_device(self, mock_requests): """ Should successfully create the device. """ DojotAPI.call_api.return_value = {"devices": [{"id": 1}]} args = { "url": "{0}/device".format(MOCK_CONFIG['dojot']['url']), "headers": { "Content-Type": "application/json", "Authorization": "Bearer {0}".format(self.jwt), }, "data": json.dumps({ "templates": [self.template_id], "attrs": {}, "label": self.label, }), } device_id = DojotAPI.create_device(self.jwt, self.template_id, self.label) DojotAPI.call_api.assert_called_once_with(mock_requests.post, args) self.assertEqual(device_id, 1)
def get_device_id(self): """ Get the device ID. """ device_id = None if CONFIG['dojot']['env']: jwt = self.get_jwt() template_id = self.get_template_id() device_id = DojotAPI.create_device( jwt, template_id, "CargoContainer_{0}".format(str(uuid4()).replace("-", ""))) else: device_id = str(uuid4()).replace("-", "") return device_id