tests.py 1005 B

1234567891011121314151617181920212223242526272829
  1. from django.test import TestCase
  2. from django.urls import reverse
  3. from apps.issue_events.models import Issue
  4. from apps.uptime.models import Monitor
  5. from apps.users.models import User
  6. class TestAPITestCase(TestCase):
  7. def test_seed_data(self):
  8. with self.settings(ENABLE_TEST_API=True):
  9. url = reverse("seed_data")
  10. res = self.client.post(
  11. url,
  12. QUERY_STRING="extras=true&seedIssues=true"
  13. )
  14. self.assertEqual(res.status_code, 200)
  15. self.assertEqual(User.objects.all().count(), 2)
  16. self.assertEqual(Issue.objects.all().count(), 55)
  17. monitor = Monitor.objects.all().first()
  18. self.assertEqual(monitor.name, "cytestmonitor")
  19. def test_disabled_test_api(self):
  20. with self.settings(ENABLE_TEST_API=False):
  21. url = reverse("seed_data")
  22. res = self.client.post(url)
  23. self.assertEqual(res.status_code, 404)
  24. self.assertEqual(User.objects.all().count(), 0)