Ejemplo n.º 1
0
    def test_as_png(self):
        draw = Draw("badge", settings.COLOR_BRIGHT_GREEN, "kloud51")
        png_binary = draw.as_png()
        self.assertIsNotNone(png_binary)

        with Image(blob=png_binary) as img_png:
            self.assertIsNotNone(img_png)
            self.assertIsInstance(img_png, Image)
            self.assertEqual(img_png.height, 20)
            # F*****g CodeShip is annoying, they have an old version of Python
            # Running! Which gives me different results fot the next assert.
            # self.assertEqual(int(draw.get_total_width()), img_png.width)
            self.assertEqual(img_png.height, 20)
            self.assertEqual(img_png.format, "PNG")
Ejemplo n.º 2
0
    def draw_badge(self):
        # shield_url = settings.SHIELD_URL % (
        #     self.shield_subject,
        #     status,
        #     colour,
        #     self.format,
        # )
        # style = self.request.args.get('style', 'flat')
        # if style is not None and style[0] in ['flat', 'flat-square', 'plastic' ]:
        #     style = style[0]
        # shield_url += "?style={0}".format(style)
        # shield_url = shield_url.replace(" ", "_")
        #
        # ihash = self.hash(shield_url)
        # cache = os.path.join(settings.FILE_CACHE, ihash)
        # if os.path.exists(cache) and self.cacheable:
        #     mtime = os.stat(cache).st_mtime + settings.CACHE_TIME
        #     if mtime > time.time():
        #         return open(cache).read()
        #
        # shield_response = requests.get(shield_url, stream=True)
        # img = BytesIO()
        # for chunk in shield_response.iter_content(1024):
        #     if not chunk:
        #         break
        #     img.write(chunk)
        # if self.cacheable:
        #     with open(cache, 'w') as ifile:
        #         img.seek(0)
        #         ifile.write(img.read())
        # img.seek(0)
        # return img.read()
        badge_key = self.badge_key
        badge_color = self.badge_color
        badge_value = self.badge_value

        if self.package_pulling_failed:
            badge_key = self.package_pulling_failed_key
            badge_value = self.package_pulling_failed_value
            badge_color = painter_settings.COLOR_RED

        draw = Draw(
            key_text=badge_key,
            value_color=badge_color,
            value_text=badge_value
        )

        return draw.as_svg() if self.format == 'svg' else draw.as_png()
Ejemplo n.º 3
0
    def draw_badge(self):
        # shield_url = settings.SHIELD_URL % (
        #     self.shield_subject,
        #     status,
        #     colour,
        #     self.format,
        # )
        # style = self.request.args.get('style', 'flat')
        # if style is not None and style[0] in ['flat', 'flat-square', 'plastic' ]:
        #     style = style[0]
        # shield_url += "?style={0}".format(style)
        # shield_url = shield_url.replace(" ", "_")
        #
        # ihash = self.hash(shield_url)
        # cache = os.path.join(settings.FILE_CACHE, ihash)
        # if os.path.exists(cache) and self.cacheable:
        #     mtime = os.stat(cache).st_mtime + settings.CACHE_TIME
        #     if mtime > time.time():
        #         return open(cache).read()
        #
        # shield_response = requests.get(shield_url, stream=True)
        # img = BytesIO()
        # for chunk in shield_response.iter_content(1024):
        #     if not chunk:
        #         break
        #     img.write(chunk)
        # if self.cacheable:
        #     with open(cache, 'w') as ifile:
        #         img.seek(0)
        #         ifile.write(img.read())
        # img.seek(0)
        # return img.read()
        badge_key = self.badge_key
        badge_color = self.badge_color
        badge_value = self.badge_value

        if self.package_pulling_failed:
            badge_key = self.package_pulling_failed_key
            badge_value = self.package_pulling_failed_value
            badge_color = painter_settings.COLOR_RED

        draw = Draw(key_text=badge_key,
                    value_color=badge_color,
                    value_text=badge_value)

        return draw.as_svg() if self.format == 'svg' else draw.as_png()
Ejemplo n.º 4
0
    def test_draw_badge(self):
        draw = Draw("badge", settings.COLOR_BRIGHT_GREEN, "kloud51")
        svg_text = draw.as_svg()

        self.assertIsNotNone(svg_text)