tests.py 814 B

123456789101112131415161718192021222324
  1. from django.test import TestCase
  2. from django.urls import reverse
  3. from apps.uptime.models import Monitor
  4. from apps.users.models import User
  5. class TestAPITestCase(TestCase):
  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)