You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.6 KiB

  1. from hc.test import BaseTestCase
  2. from hc.api.models import Check
  3. class BadgesTestCase(BaseTestCase):
  4. def setUp(self):
  5. super(BadgesTestCase, self).setUp()
  6. self.url = "/projects/%s/badges/" % self.project.code
  7. def test_it_shows_badges(self):
  8. Check.objects.create(project=self.project, tags="foo a-B_1 baz@")
  9. Check.objects.create(project=self.bobs_project, tags="bobs-tag")
  10. self.client.login(username="[email protected]", password="password")
  11. r = self.client.get(self.url)
  12. self.assertContains(r, "foo.svg")
  13. self.assertContains(r, "a-B_1.svg")
  14. # Expect badge URLs only for tags that match \w+
  15. self.assertNotContains(r, "[email protected]")
  16. # Expect only Alice's tags
  17. self.assertNotContains(r, "bobs-tag.svg")
  18. def test_it_uses_badge_key(self):
  19. Check.objects.create(project=self.project, tags="foo bar")
  20. Check.objects.create(project=self.bobs_project, tags="bobs-tag")
  21. self.project.badge_key = "alices-badge-key"
  22. self.project.save()
  23. self.client.login(username="[email protected]", password="password")
  24. r = self.client.get(self.url)
  25. self.assertContains(r, "badge/alices-badge-key/")
  26. self.assertContains(r, "badge/alices-badge-key/")
  27. def test_it_handles_special_characers_in_tags(self):
  28. Check.objects.create(project=self.project, tags="db@dc1")
  29. self.client.login(username="[email protected]", password="password")
  30. r = self.client.get(self.url)
  31. self.assertContains(r, "db%2540dc1.svg")