tests.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import requests_mock
  2. from django.test import TestCase
  3. from django.urls import reverse
  4. from model_bakery import baker
  5. class SettingsTestCase(TestCase):
  6. def setUp(self):
  7. self.url = reverse("api:get_settings")
  8. def test_settings(self):
  9. with self.assertNumQueries(1):
  10. res = self.client.get(self.url) # Check that no auth is necessary
  11. self.assertEqual(res.status_code, 200)
  12. def test_settings_oidc(self):
  13. social_app = baker.make(
  14. "socialaccount.socialapp",
  15. provider="openid_connect",
  16. provider_id="my-openid",
  17. settings={"server_url": "https://example.com"},
  18. )
  19. for provider in [
  20. "gitlab",
  21. "microsoft",
  22. "github",
  23. "google",
  24. "nextcloud",
  25. "digitalocean",
  26. ]:
  27. baker.make(
  28. "socialaccount.socialapp",
  29. provider=provider,
  30. )
  31. with requests_mock.Mocker() as m:
  32. m.get(
  33. "https://example.com/.well-known/openid-configuration",
  34. json={"authorization_endpoint": ""},
  35. )
  36. res = self.client.get(self.url)
  37. self.assertContains(res, social_app.name)