示例#1
0
文件: api.py 项目: samn/stashboard
    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)
示例#2
0
    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")
示例#3
0
    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)
示例#4
0
    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")
示例#5
0
    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")
示例#6
0
    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")
示例#7
0
    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)))
示例#8
0
    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)))
示例#9
0
 def test_create_image(self):
     s = Status(name=u"∆", slug=u"∑´", description=u"œˆø", image=u"©˙")
     s.put()
     data = s.rest("/api")
示例#10
0
 def test_create_image(self):
     s = Status(name=u"∆", slug=u"∑´", description=u"œˆø", image=u"©˙")
     s.put()
     data = s.rest("/api")