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
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 )
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))
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
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)) )
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
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
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))
def set_skill_setting_etag(context): context.device_skill_etag = context.etag_manager.get( DEVICE_SKILL_ETAG_KEY.format(device_id=context.device_id) )