def test_successfully_create_template(self, mock_requests): """ Should successfully create the template. """ DojotAPI.call_api.return_value = {"template": {"id": 1}} args = { "url": "{0}/template".format(MOCK_CONFIG['dojot']['url']), "headers": { "Content-Type": "application/json", "Authorization": "Bearer {0}".format(self.jwt), }, "data": json.dumps({ "label": "CargoContainer", "attrs": [ { "label": "timestamp", "type": "dynamic", "value_type": "integer" }, ] }), } template_id = DojotAPI.create_template(self.jwt) DojotAPI.call_api.assert_called_once_with(mock_requests.post, args) self.assertEqual(template_id, 1)
def get_template_id(self): """ Retrieves the test template ID from the database or create a new one. """ template_id = self.mapped.get('template_id').decode('utf-8') if template_id == "-1": jwt = self.get_jwt() template_id = DojotAPI.create_template(jwt) self.mapped.set('template_id', template_id) return template_id
def create_devices(self): """ Create the devices in Dojot. Returns a list with device IDs. """ try: template_id = DojotAPI.create_template(self.jwt) DojotAPI.create_devices(self.jwt, template_id, self.parser_args.devices, self.parser_args.batch) except Exception as exception: LOGGER.error(str(exception))