tests.py 832 B

1234567891011121314151617181920212223
  1. from django.shortcuts import reverse
  2. from rest_framework.test import APITestCase
  3. from users.models import User
  4. from glitchtip.uptime.models import Monitor
  5. class TestAPITestCase(APITestCase):
  6. def test_seed_data(self):
  7. with self.settings(ENABLE_TEST_API=True):
  8. url = reverse("seed_data")
  9. res = self.client.post(url)
  10. self.assertEqual(res.status_code, 200)
  11. self.assertEqual(User.objects.all().count(), 2)
  12. monitor = Monitor.objects.all().first()
  13. self.assertEqual(monitor.name, "cytestmonitor")
  14. def test_disabled_test_api(self):
  15. with self.settings(ENABLE_TEST_API=False):
  16. url = reverse("seed_data")
  17. res = self.client.post(url)
  18. self.assertEqual(res.status_code, 404)
  19. self.assertEqual(User.objects.all().count(), 0)