"""Unit tests for CannedResponseHistory.""" import pytest from product_review.api import db from product_review.models import ( canned_response_history as canned_response_history_model, ) from tests.utils.db_utils import create_test_canned_response_history def test_create_canned_response_history(): """Test create canned response history.""" canned_response_history_model.create_canned_response_history( review_queue_id=4444, canned_response_id=1, ) db.session.commit() result = canned_response_history_model.get_canned_response_history(4444) assert result == [ { "canned_response_history_id": 1, "review_queue_id": 4444, "track_id": None, "canned_response_id": 1, } ] def test_create_canned_response_history_with_track_id(): """Test create canned response history with track id.""" canned_response_history_model.create_canned_response_history( review_queue_id=4445, canned_response_id=1, track_id=12345 ) db.session.commit() result = canned_response_history_model.get_canned_response_history(4445) assert result == [ { "canned_response_history_id": 1, "review_queue_id": 4445, "track_id": 12345, "canned_response_id": 1, } ] def test_create_bulk(): """Test create bulk.""" canned_response_history_model.create_bulk( review_queue_id=4444, canned_response_ids=[1, 2], ) db.session.commit() result = canned_response_history_model.get_canned_response_history(4444) assert result == [ { "canned_response_history_id": 1, "review_queue_id": 4444, "canned_response_id": 1, "track_id": None }, { "canned_response_history_id": 2, "review_queue_id": 4444, "canned_response_id": 2, "track_id": None }, ] def test_delete(): """Test delete.""" create_test_canned_response_history( review_queue_id=4444, canned_response_id=1 ) create_test_canned_response_history( review_queue_id=4444, canned_response_id=2 ) canned_response_history_model.delete(4444) db.session.commit() with pytest.raises(Exception) as er: canned_response_history_model.get_canned_response_history(4444) assert ( str(getattr(er, "value", None)) == '{"status": 404, "code": "not_found", "message": "Not Found"}' )