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.

34 lines
1.2 KiB

  1. from django.conf import settings
  2. from django.core.signing import base64_hmac
  3. from hc.api.models import Check
  4. from hc.test import BaseTestCase
  5. class BadgeTestCase(BaseTestCase):
  6. def setUp(self):
  7. super(BadgeTestCase, self).setUp()
  8. self.check = Check.objects.create(user=self.alice, tags="foo bar")
  9. def test_it_rejects_bad_signature(self):
  10. r = self.client.get("/badge/%s/12345678/foo.svg" % self.alice.username)
  11. assert r.status_code == 404
  12. def test_it_returns_svg(self):
  13. sig = base64_hmac(str(self.alice.username), "foo", settings.SECRET_KEY)
  14. sig = sig[:8]
  15. url = "/badge/%s/%s/foo.svg" % (self.alice.username, sig)
  16. r = self.client.get(url)
  17. self.assertEqual(r["Access-Control-Allow-Origin"], "*")
  18. self.assertContains(r, "#4c1")
  19. def test_it_handles_options(self):
  20. sig = base64_hmac(str(self.alice.username), "foo", settings.SECRET_KEY)
  21. sig = sig[:8]
  22. url = "/badge/%s/%s/foo.svg" % (self.alice.username, sig)
  23. r = self.client.options(url)
  24. self.assertEqual(r.status_code, 204)
  25. self.assertEqual(r["Access-Control-Allow-Origin"], "*")