Beispiel #1
0
    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))
Beispiel #2
0
    def test_successfully_create_one_device_one_batch(self, mock_requests):
        """
        Should successfully create one device in one batch.
        """
        DojotAPI.divide_loads.return_value = [1]

        self.args["data"] = json.dumps({
            "templates": [self.template_id],
            "attrs": {},
            "label": "CargoContainer_0"
        })

        DojotAPI.create_devices(self.jwt, self.template_id, 1, 1)

        DojotAPI.divide_loads.assert_called_once_with(1, 1)
        self.assertEqual(DojotAPI.divide_loads.return_value, [1])
        DojotAPI.call_api.assert_called_once_with(mock_requests.post, self.args, False)
Beispiel #3
0
    def test_successfully_create_two_devices_two_batches(self, mock_requests):
        """
        Should successfully create two devices in two batches.
        """
        DojotAPI.divide_loads.return_value = [1, 1]

        self.args["data"] = json.dumps({
            "templates": [self.template_id],
            "attrs": {},
            "label": "CargoContainer_1"
        })

        DojotAPI.create_devices(self.jwt, self.template_id, 2, 2)

        DojotAPI.divide_loads.assert_called_once_with(2, 2)
        self.assertEqual(DojotAPI.divide_loads.return_value, [1, 1])
        self.assertEqual(DojotAPI.call_api.call_count, 2)
        DojotAPI.call_api.assert_has_calls([
            mock.call(mock_requests.post, self.args, False),
            mock.call(mock_requests.post, self.args, False)
        ])