def _list_all_tags(self, req, resp, revision_id): """List all tags for a revision.""" try: resp_tags = db_api.revision_tag_get_all(revision_id) except errors.RevisionNotFound as e: raise falcon.HTTPNotFound(e.format_message()) resp_body = revision_tag_view.ViewBuilder().list(resp_tags) resp.status = falcon.HTTP_200 resp.body = resp_body
def _show_tag(self, req, resp, revision_id, tag): """Retrieve details for a specified tag.""" try: resp_tag = db_api.revision_tag_get(revision_id, tag) except (errors.RevisionNotFound, errors.RevisionTagNotFound) as e: raise falcon.HTTPNotFound(description=e.format_message()) resp_body = revision_tag_view.ViewBuilder().show(resp_tag) resp.status = falcon.HTTP_200 resp.body = resp_body
def _show_tag(self, req, resp, revision_id, tag): """Retrieve details for a specified tag.""" try: resp_tag = db_api.revision_tag_get(revision_id, tag) except (errors.RevisionNotFound, errors.RevisionTagNotFound) as e: with excutils.save_and_reraise_exception(): LOG.exception(e.format_message()) resp_body = revision_tag_view.ViewBuilder().show(resp_tag) resp.status = falcon.HTTP_200 resp.body = resp_body
def on_post(self, req, resp, revision_id, tag=None): """Creates a revision tag.""" tag_data = self.from_yaml(req, expect_list=False, allow_empty=True) try: resp_tag = db_api.revision_tag_create(revision_id, tag, tag_data) except (errors.RevisionNotFound, errors.RevisionTagBadFormat, errors.errors.RevisionTagNotFound) as e: with excutils.save_and_reraise_exception(): LOG.exception(e.format_message()) resp_body = revision_tag_view.ViewBuilder().show(resp_tag) resp.status = falcon.HTTP_201 resp.body = resp_body
def on_post(self, req, resp, revision_id, tag=None): """Creates a revision tag.""" body = req.stream.read(req.content_length or 0) try: tag_data = yaml.safe_load(body) except yaml.YAMLError as e: error_msg = ("Could not parse the request body into YAML data. " "Details: %s." % e) LOG.error(error_msg) raise falcon.HTTPBadRequest(description=e) try: resp_tag = db_api.revision_tag_create(revision_id, tag, tag_data) except (errors.RevisionNotFound, errors.RevisionTagNotFound) as e: raise falcon.HTTPNotFound(description=e.format_message()) except errors.RevisionTagBadFormat as e: raise falcon.HTTPBadRequest(description=e.format_message()) resp_body = revision_tag_view.ViewBuilder().show(resp_tag) resp.status = falcon.HTTP_201 resp.body = resp_body
def setUp(self): super(TestRevisionViews, self).setUp() self.view_builder = revision_tag.ViewBuilder() self.revision_id = self.create_revision()