tests.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from django.core.cache import cache
  2. from django.urls import reverse
  3. from glitchtip.test_utils.test_case import GlitchTipTestCase
  4. from .views import SETUP_WIZARD_CACHE_EMPTY, SETUP_WIZARD_CACHE_KEY
  5. class WizardTestCase(GlitchTipTestCase):
  6. def setUp(self):
  7. self.create_user_and_project()
  8. self.url = reverse("setup-wizard")
  9. self.url_set_token = reverse("setup-wizard-set-token")
  10. def test_get_hash(self):
  11. res = self.client.get(self.url)
  12. self.assertEqual(res.status_code, 200)
  13. wizard_hash = res.data.get("hash")
  14. self.assertEqual(len(wizard_hash), 64)
  15. key = SETUP_WIZARD_CACHE_KEY + wizard_hash
  16. self.assertEqual(cache.get(key), SETUP_WIZARD_CACHE_EMPTY)
  17. def test_set_token(self):
  18. res = self.client.get(self.url)
  19. wizard_hash = res.data.get("hash")
  20. self.client.force_login(self.user)
  21. res = self.client.post(self.url_set_token, {"hash": wizard_hash})
  22. self.assertEqual(res.status_code, 200)
  23. key = SETUP_WIZARD_CACHE_KEY + wizard_hash
  24. self.assertTrue(cache.get(key)["apiKeys"])
  25. self.assertTrue(self.user.apitoken_set.exists())
  26. res = self.client.get(self.url + wizard_hash + "/")
  27. self.assertEqual(res.status_code, 200)