Commit 6a8ab796 authored by Michal Čihař's avatar Michal Čihař

Test all color variants for badges

Also adjusted color levels a bit to use >= instead of >.
Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 22a19232
...@@ -24,6 +24,7 @@ Tests for widgets. ...@@ -24,6 +24,7 @@ Tests for widgets.
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from weblate.trans.models import Translation
from weblate.trans.tests.test_views import ViewTestCase from weblate.trans.tests.test_views import ViewTestCase
from weblate.trans.views.widgets import WIDGETS from weblate.trans.views.widgets import WIDGETS
...@@ -71,6 +72,25 @@ class WidgetsTest(ViewTestCase): ...@@ -71,6 +72,25 @@ class WidgetsTest(ViewTestCase):
else: else:
self.assertPNG(response) self.assertPNG(response)
def test_view_widget_percents(self):
for translated in (0, 3, 4):
Translation.objects.update(translated=translated)
for widget in WIDGETS:
color = WIDGETS[widget].colors[0]
response = self.client.get(
reverse(
'widget-image',
kwargs={
'project': self.project.slug,
'widget': widget,
'color': color,
'extension': 'png',
}
)
)
self.assert_widget(widget, response)
def test_view_widget_image(self): def test_view_widget_image(self):
for widget in WIDGETS: for widget in WIDGETS:
for color in WIDGETS[widget].colors: for color in WIDGETS[widget].colors:
......
...@@ -313,9 +313,9 @@ class BadgeWidget(Widget): ...@@ -313,9 +313,9 @@ class BadgeWidget(Widget):
order = 90 order = 90
def get_filename(self): def get_filename(self):
if self.percent > 90: if self.percent >= 90:
mode = 'passing' mode = 'passing'
elif self.percent > 75: elif self.percent >= 75:
mode = 'medium' mode = 'medium'
else: else:
mode = 'failing' mode = 'failing'
...@@ -350,9 +350,9 @@ class ShieldsBadgeWidget(Widget): ...@@ -350,9 +350,9 @@ class ShieldsBadgeWidget(Widget):
order = 80 order = 80
def redirect(self): def redirect(self):
if self.percent > 90: if self.percent >= 90:
color = 'brightgreen' color = 'brightgreen'
elif self.percent > 75: elif self.percent >= 75:
color = 'yellow' color = 'yellow'
else: else:
color = 'red' color = 'red'
...@@ -388,9 +388,9 @@ class SVGBadgeWidget(Widget): ...@@ -388,9 +388,9 @@ class SVGBadgeWidget(Widget):
font = get_font(11, False, is_base(percent_text)) font = get_font(11, False, is_base(percent_text))
percent_width = font.getsize(percent_text)[0] + 7 percent_width = font.getsize(percent_text)[0] + 7
if self.percent > 90: if self.percent >= 90:
color = '#4c1' color = '#4c1'
elif self.percent > 75: elif self.percent >= 75:
color = '#dfb317' color = '#dfb317'
else: else:
color = '#e05d44' color = '#e05d44'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment