Browse Source

Use Project.badge_key for generating badge URLs

pull/217/head
Pēteris Caune 6 years ago
parent
commit
d04f3cc328
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
2 changed files with 16 additions and 4 deletions
  1. +14
    -1
      hc/accounts/tests/test_badges.py
  2. +2
    -3
      hc/accounts/views.py

+ 14
- 1
hc/accounts/tests/test_badges.py View File

@ -5,10 +5,10 @@ from hc.api.models import Check
class BadgesTestCase(BaseTestCase): class BadgesTestCase(BaseTestCase):
def test_it_shows_badges(self): def test_it_shows_badges(self):
self.client.login(username="[email protected]", password="password")
Check.objects.create(project=self.project, tags="foo a-B_1 baz@") Check.objects.create(project=self.project, tags="foo a-B_1 baz@")
Check.objects.create(project=self.bobs_project, tags="bobs-tag") Check.objects.create(project=self.bobs_project, tags="bobs-tag")
self.client.login(username="[email protected]", password="password")
r = self.client.get("/accounts/profile/badges/") r = self.client.get("/accounts/profile/badges/")
self.assertContains(r, "foo.svg") self.assertContains(r, "foo.svg")
self.assertContains(r, "a-B_1.svg") self.assertContains(r, "a-B_1.svg")
@ -18,3 +18,16 @@ class BadgesTestCase(BaseTestCase):
# Expect only Alice's tags # Expect only Alice's tags
self.assertNotContains(r, "bobs-tag.svg") 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="[email protected]", 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/")

+ 2
- 3
hc/accounts/views.py View File

@ -366,14 +366,13 @@ def badges(request):
sorted_tags.append("*") # For the "overall status" badge sorted_tags.append("*") # For the "overall status" badge
urls = [] urls = []
username = project.owner.username
for tag in sorted_tags: for tag in sorted_tags:
if not re.match("^[\w-]+$", tag) and tag != "*": if not re.match("^[\w-]+$", tag) and tag != "*":
continue continue
urls.append({ 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}) badge_sets.append({"project": project, "urls": urls})


Loading…
Cancel
Save