test_security_api.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from django.urls import reverse
  2. from apps.issue_events.models import Issue, IssueEvent
  3. from .utils import EventIngestTestCase
  4. class SecurityAPITestCase(EventIngestTestCase):
  5. """
  6. These test specifically test the security API and act more of integration test
  7. Use test_process_issue_events.py for testing Event Ingest more specifically
  8. """
  9. def setUp(self):
  10. super().setUp()
  11. self.url = reverse("api:event_security", args=[self.project.id]) + self.params
  12. self.small_event = self.get_json_data(
  13. "apps/event_ingest/tests/test_data/csp/mozilla_example.json"
  14. )
  15. def test_security_api(self):
  16. with self.assertNumQueries(8):
  17. res = self.client.post(
  18. self.url, self.small_event, content_type="application/json"
  19. )
  20. self.assertEqual(res.status_code, 201)
  21. self.assertEqual(self.project.issues.count(), 1)
  22. self.assertEqual(IssueEvent.objects.count(), 1)
  23. def test_csp_event(self):
  24. self.client.post(self.url, self.small_event, content_type="application/json")
  25. issue = Issue.objects.get()
  26. self.assertEqual(issue.title, "Blocked 'style-elem' from 'example.com'")
  27. event = IssueEvent.objects.get()
  28. self.assertEqual(event.data["csp"]["effective_directive"], "style-src-elem")