Ejemplo n.º 1
0
    def validate(self, data: dict) -> Acknowledgment:  # pylint: disable=no-self-use
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        balance = data.get('balance')
        node_type = data.get('nodeType')
        test_mode = data.get('testMode')
        test_mode_speaker = data.get('testModeSpeaker')

        if balance is not None:
            validate.boolean(balance, label='Balance')
        if test_mode is not None:
            validate.boolean(test_mode, label='Test Mode')
        if test_mode_speaker is not None and len(test_mode_speaker) > 0:
            speaker = self.config.speaker_repository.get_speaker(
                test_mode_speaker)
            if speaker is None:
                ack.add_error('test mode speaker does not exist')

        if node_type is not None and node_type != 'master' and node_type != 'tracking':
            ack.add_error('nodeType must be either master or tracking')

        if data.get('network') is not None:
            network_ack = self.networks_controller.validate(
                data.get('network'))
            if not network_ack.successful:
                for error in network_ack.errors:
                    ack.add_error(error)

        return ack
    def validate(self, data: dict) -> Acknowledgment:  # pylint: disable=no-self-use
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        start = data.get('start')
        finish = data.get('finish')
        repeat = data.get('repeat')

        if start is not None:
            validate.boolean(start, label='Start')
        if finish is not None:
            validate.boolean(finish, label='Finish')
        if repeat is not None:
            validate.boolean(repeat, label='Repeat')
        if data.get('node') is None or isinstance(data.get('node'),
                                                  dict) is False:
            ack.add_error('Node id must not be empty')
        elif validate.integer(data.get('node').get('id'),
                              label='Node id',
                              min_value=1):
            if self.config.node_repository.get_node(
                    data.get('node').get('id')) is None:
                ack.add_error('A node with this id does not exist')

        return ack
Ejemplo n.º 3
0
    def validate_update(self, data: dict) -> Acknowledgment:
        """Validates the input data.

        :param dict data: Input data
        :returns: Acknowledgment with the status and possible error messages.
        :rtype: models.acknowledgment.Acknowledgment
        """
        ack = Acknowledgment()
        validate = Validate(ack)
        start = data.get('start')
        start_volume = data.get('startVolume')
        finish = data.get('finish')
        repeat_point = data.get('repeatPoint')
        confirm_point = data.get('confirmPoint')
        next_point = data.get('nextPoint')
        next_speaker = data.get('nextSpeaker')

        if data.get('room') is None or isinstance(data.get('room'),
                                                  dict) is False:
            ack.add_error('Room id must not be empty')
        elif validate.integer(data.get('room').get('id'),
                              label='Room id',
                              min_value=1):
            room = self.config.room_repository.get_room(
                data.get('room').get('id'))
            if room is None:
                ack.add_error('A room with this id does not exist')
            elif len(room.nodes) != 2:
                ack.add_error('A room needs exactly two nodes')
        if start is not None:
            validate.boolean(start, label='Start')
            if start and self.config.room_repository.get_room(
                    data.get('room').get('id')).calibrating:
                ack.add_error('The room is already calibrating currently')
            elif start and start_volume is None:
                ack.add_error('Calibration start volume is required')
            elif start:
                validate.integer(start_volume,
                                 label='Calibration Start Volume')

        if finish is not None:
            validate.boolean(finish, label='Finish')
            if finish and not self.config.room_repository.get_room(
                    data.get('room').get('id')).calibrating:
                ack.add_error('The room wasn\'t beeing calibrated')
        if repeat_point is not None:
            validate.boolean(repeat_point, label='Repeat Point')
        if confirm_point is not None:
            validate.boolean(confirm_point, label='Confirm Point')
        if next_point is not None:
            validate.boolean(next_point, label='Next Point')
        if next_speaker is not None:
            validate.boolean(next_speaker, label='Next Speaker')

        return ack