From d04f3cc328486f5bbef88d2358fae1e04f70d005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Thu, 31 Jan 2019 22:51:19 +0200 Subject: [PATCH] Use Project.badge_key for generating badge URLs --- hc/accounts/tests/test_badges.py | 15 ++++++++++++++- hc/accounts/views.py | 5 ++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hc/accounts/tests/test_badges.py b/hc/accounts/tests/test_badges.py index 01389cd7..338b16b6 100644 --- a/hc/accounts/tests/test_badges.py +++ b/hc/accounts/tests/test_badges.py @@ -5,10 +5,10 @@ from hc.api.models import Check class BadgesTestCase(BaseTestCase): def test_it_shows_badges(self): - self.client.login(username="alice@example.org", password="password") Check.objects.create(project=self.project, tags="foo a-B_1 baz@") Check.objects.create(project=self.bobs_project, tags="bobs-tag") + self.client.login(username="alice@example.org", password="password") r = self.client.get("/accounts/profile/badges/") self.assertContains(r, "foo.svg") self.assertContains(r, "a-B_1.svg") @@ -18,3 +18,16 @@ class BadgesTestCase(BaseTestCase): # Expect only Alice's tags self.assertNotContains(r, "bobs-tag.svg") + + def test_it_uses_badge_key(self): + Check.objects.create(project=self.project, tags="foo bar") + Check.objects.create(project=self.bobs_project, tags="bobs-tag") + + self.project.badge_key = "alices-badge-key" + self.project.save() + + self.client.login(username="alice@example.org", password="password") + r = self.client.get("/accounts/profile/badges/") + print(r.content) + self.assertContains(r, "badge/alices-badge-key/") + self.assertContains(r, "badge/alices-badge-key/") diff --git a/hc/accounts/views.py b/hc/accounts/views.py index ed7e7b8d..afd89b78 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -366,14 +366,13 @@ def badges(request): sorted_tags.append("*") # For the "overall status" badge urls = [] - username = project.owner.username for tag in sorted_tags: if not re.match("^[\w-]+$", tag) and tag != "*": continue urls.append({ - "svg": get_badge_url(username, tag), - "json": get_badge_url(username, tag, format="json"), + "svg": get_badge_url(project.badge_key, tag), + "json": get_badge_url(project.badge_key, tag, format="json"), }) badge_sets.append({"project": project, "urls": urls})