Esempio n. 1
0
    def get(self, device_id):
        """
        Retrieve skills installed on device from the database.

        :raises NotModifiedException: when etag in request matches cache
        """
        self._authenticate(device_id)
        self._validate_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))
        device_skills = self.skill_setting_repo.get_skill_settings_for_device(
            device_id
        )

        if device_skills:
            response_data = self._build_response_data(device_skills)
            response = Response(
                json.dumps(response_data),
                status=HTTPStatus.OK,
                content_type='application/json'
            )
            self._add_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))
        else:
            response = Response(
                '',
                status=HTTPStatus.NO_CONTENT,
                content_type='application/json'
            )
        return response
Esempio n. 2
0
def expire_skill_setting_etag(context):
    valid_device_skill_etag = context.etag_manager.get(
        DEVICE_SKILL_ETAG_KEY.format(device_id=context.device_id)
    )
    context.device_skill_etag = context.etag_manager.expire(
        valid_device_skill_etag
    )
Esempio n. 3
0
def get_skills_etag(context):
    response_headers = context.response.headers
    response_etag = response_headers['ETag']
    skill_etag = context.etag_manager.get(
        DEVICE_SKILL_ETAG_KEY.format(device_id=context.device_id)
    )
    assert_that(skill_etag.decode(), equal_to(response_etag))
Esempio n. 4
0
    def put(self, device_id):
        self._authenticate(device_id)
        self._validate_put_request()
        skill_id = self._update_skill_settings(device_id)
        self.etag_manager.expire(
            DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))

        return dict(uuid=skill_id), HTTPStatus.OK
Esempio n. 5
0
def check_for_expired_etag(context):
    """An E-tag is expired by changing its value."""
    expired_device_skill_etag = context.etag_manager.get(
        DEVICE_SKILL_ETAG_KEY.format(device_id=context.device_id)
    )
    assert_that(
        expired_device_skill_etag.decode(),
        is_not(equal_to(context.device_skill_etag))
    )
Esempio n. 6
0
    def get(self, device_id):
        """
        Retrieve skills installed on device from the database.

        :raises NotModifiedException: when etag in request matches cache
        """
        self._authenticate(device_id)
        self._validate_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))
        response_data = self._build_response_data(device_id)
        response = self._build_response(device_id, response_data)

        return response
Esempio n. 7
0
    def _build_response(self, device_id, response_data):
        if response_data is None:
            response = Response('',
                                status=HTTPStatus.NO_CONTENT,
                                content_type='application/json')
        else:
            response = Response(json.dumps(response_data),
                                status=HTTPStatus.OK,
                                content_type='application/json')
            self._add_etag(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))

        return response
Esempio n. 8
0
    def expire_skill_etag_by_device_id(self, device_id):
        """Expire the locations' etag for a given device

        :param device_id: device uuid
        """
        self.expire(DEVICE_SKILL_ETAG_KEY.format(device_id=device_id))
Esempio n. 9
0
def set_skill_setting_etag(context):
    context.device_skill_etag = context.etag_manager.get(
        DEVICE_SKILL_ETAG_KEY.format(device_id=context.device_id)
    )