test_factory.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright © 2023 Ingram Micro Inc. All rights reserved.
  2. import pytest
  3. from dj_cqrs.constants import SignalType
  4. from dj_cqrs.controller.consumer import route_signal_to_replica_model
  5. from dj_cqrs.mixins import ReplicaMixin
  6. def test_bad_model(caplog):
  7. route_signal_to_replica_model(SignalType.SAVE, 'invalid', {})
  8. assert 'No model with such CQRS_ID: invalid.' in caplog.text
  9. @pytest.mark.django_db
  10. def test_bad_signal(caplog):
  11. route_signal_to_replica_model('invalid', 'basic', {})
  12. assert 'Bad signal type "invalid" for CQRS_ID "basic".' in caplog.text
  13. @pytest.mark.django_db
  14. def test_save_model(mocker):
  15. cqrs_save_mock = mocker.patch.object(ReplicaMixin, 'cqrs_save')
  16. route_signal_to_replica_model(SignalType.SAVE, 'basic', {}, {})
  17. cqrs_save_mock.assert_called_once_with({}, previous_data={})
  18. @pytest.mark.django_db
  19. def test_delete_model(mocker):
  20. cqrs_delete_mock = mocker.patch.object(ReplicaMixin, 'cqrs_delete')
  21. route_signal_to_replica_model(SignalType.DELETE, 'basic', {'id': 1})
  22. cqrs_delete_mock.assert_called_once_with({'id': 1})