"""Unit tests for rejection notes logic.""" from unittest import mock from oto import response import pytest from product_workflow.logic import rejection_notes from product_workflow.models import rejection_notes as rejection_notes_model from tests.factories import rejection_notes as rejection_notes_factory @pytest.fixture def release_approval_id(): """Create a release id for testing.""" return 123 @pytest.fixture def test_rejection_notes(release_approval_id): """Fixture data for a fake response from the model layer.""" rejection_notes = rejection_notes_factory.RejectionNoteFactory.build_batch( 3, release_approval_id=release_approval_id) return [note.to_dict() for note in rejection_notes] @pytest.fixture def test_model_response(test_rejection_notes): """Fake response for mocking the model layer.""" payload = {'items': rejection_notes} return response.Response(message=payload) @pytest.fixture def test_updated_rejection_notes_models(): """Updated rejections from the seeded notes.""" rejections = rejection_notes_factory.RejectionNoteFactory.build_batch(3) for note in rejections: setattr(note, 'corrected', 'Y') return [note.to_dict() for note in rejections] @pytest.fixture def test_update_model_response(test_updated_rejection_notes_models): """Fake response for mocking the model layer.""" payload = {'rejections': test_updated_rejection_notes_models} return response.Response(message=payload) def test_get_rejection_notes( monkeypatch, test_model_response, release_approval_id): """Test that the logic calls the model layer and returns its response.""" model_fetcher = mock.Mock(return_value=test_model_response) monkeypatch.setattr( rejection_notes_model, 'get_rejection_notes', model_fetcher) result = rejection_notes.get_rejection_notes(release_approval_id) assert result == test_model_response def test_update_rejections( monkeypatch, test_update_model_response, test_updated_rejection_notes_models): """Test that the logic calls the model layer and returns its response.""" model_fetcher = mock.Mock(return_value=test_update_model_response) monkeypatch.setattr( rejection_notes_model, 'update_rejection_notes', model_fetcher) result = rejection_notes.update_rejection_notes( test_updated_rejection_notes_models) assert result == test_update_model_response