def post(self, version): if (self.valid_version(version)): name = self.request.get('name', default_value=None) description = self.request.get('description', default_value=None) image = self.request.get('image', default_value=None) level = self.request.get('level', default_value=None) severity = Level.get_severity(level) if name and description and severity and image: slug = slugify.slugify(name) status = Status.get_by_slug(slug) # Update existing resource if status: status.description = description status.severity = severity status.image = image status.name = name status.put() self.json(status.rest(self.base_url(version))) # Create new service else: status = Status(name=name, slug=slug, description=description, severity=severity, image=image) status.put() self.json(status.rest(self.base_url(version))) else: self.error(400, "Bad Data") else: self.error(404, "API Version %s not supported" % version)
def test_status_normal(self): s = Status(name=u"Hey", slug=u"hey", description=u"runaway", image=u"helloworld.png", severity=10) s.put() data = s.rest("/api") self.assertEquals(data["level"], "NORMAL")
def test_status_warning(self): s = Status(name=u"Hey", slug=u"hey", description=u"runaway", image=u"helloworld.png", severity=30) s.put() data = s.rest("/api") self.assertEquals(data["level"], "WARNING")
def post(self, version): if not self.valid_version(version): self.error(404, "API Version %s not supported" % version) return name = self.request.get('name', default_value=None) description = self.request.get('description', default_value=None) image_slug = self.request.get('image', default_value=None) default = self.request.get('default', default_value="false") if default not in ["true", "false"]: self.error(400, "Default must be true or false") return if not name or not description or not image_slug: self.error(400, "Bad Data") return slug = slugify.slugify(name) status = Status.get_by_slug(slug) image = Image.get_by_slug(image_slug) if status is not None: self.error(400, "A Status with the slug %s already exists" % slug) return if image is None: msg = "An Image with the slug %s doesn't exist" % image_slug self.error(400, msg) return # Reset default status if default == "true": for stat in Status.all().filter("default", True): stat.default = False stat.put() default = default == "true" status = Status(name=name, slug=slug, description=description, image=image.path, default=default) status.put() invalidate_cache() self.response.set_status(201) self.json(status.rest(self.base_url(version)))
def test_create_image(self): s = Status(name=u"∆", slug=u"∑´", description=u"œˆø", image=u"©˙") s.put() data = s.rest("/api")