test_emit_event.py 1016 B

12345678910111213141516171819202122232425262728293031323334353637
  1. from types import SimpleNamespace
  2. from mock import patch, ANY
  3. import pytest
  4. from backend.lambdas.tasks.emit_event import handler
  5. pytestmark = [pytest.mark.unit, pytest.mark.task]
  6. @patch("backend.lambdas.tasks.emit_event.emit_event")
  7. def test_it_logs_event(mock_emit):
  8. handler(
  9. {
  10. "JobId": "1234",
  11. "EmitterId": "5678",
  12. "EventName": "QueryFailed",
  13. "EventData": {"foo": "bar"},
  14. },
  15. SimpleNamespace(),
  16. )
  17. mock_emit.assert_called_with("1234", "QueryFailed", {"foo": "bar"}, "5678")
  18. @patch("backend.lambdas.tasks.emit_event.emit_event")
  19. @patch("backend.lambdas.tasks.emit_event.uuid4")
  20. def test_it_defaults_emiiter_id(mock_uuid4, mock_emit):
  21. mock_uuid4.return_value = "111"
  22. handler(
  23. {
  24. "JobId": "1234",
  25. "EventName": "QueryFailed",
  26. "EventData": {"foo": "bar"},
  27. },
  28. SimpleNamespace(),
  29. )
  30. mock_emit.assert_called_with("1234", "QueryFailed", {"foo": "bar"}, "111")