"""Unit tests for AdActionComment model.""" from oto import status import pytest from podcast.constants import error from podcast.models import ad_action_comment from podcast.utils import exc def test_get_ad_action_comments(): """Test get ad actions comments.""" result = ad_action_comment.get_ad_action_comments(1, 50, 0) assert len(result['items']) == 3 assert result['pagination']['total_records'] == 3 assert result['items'][0]['comment'] == 'first test comment' assert result['items'][1]['comment'] == 'second test comment' def test_get_ad_action_comments_filtered(): """Test get ad actions comments using limit and offset.""" result = ad_action_comment.get_ad_action_comments(1, 1, 1) assert len(result['items']) == 1 assert result['pagination']['total_records'] == 3 assert result['items'][0]['comment'] == 'second test comment' result = ad_action_comment.get_ad_action_comments(1, 50, 10) assert len(result['items']) == 0 assert result['pagination']['total_records'] == 3 def test_create_ad_action_comment(new_ad_read_comment_fixture): """Test create ad action comment.""" result = ad_action_comment.create_ad_action_comment(new_ad_read_comment_fixture, 1) assert result['id'] == 5 assert result['ad_read_id'] == 1 assert result['comment'] == 'test comment' assert result['created_by'] == 1 def test_create_ad_action_comment_failure(): """Test create ad action comment failure on empty data.""" with pytest.raises(exc.OwsError) as err: ad_action_comment.create_ad_action_comment({}, 1) assert err.value.status == status.BAD_REQUEST def test_delete_ad_action_comment(): """Test delete ad action comment.""" result = ad_action_comment.delete_ad_action_comment(2, 2) assert result['id'] == 2 assert result['is_deleted'] is True assert result['updated_by'] == 2 def test_delete_ad_action_comment_forbidden(): """Test delete ad action comment forbidden if it wasn't created by the same user.""" with pytest.raises(exc.OwsError) as err: ad_action_comment.delete_ad_action_comment(1, 2) assert err.value.status == status.FORBIDDEN assert err.value.message == error.ERROR_MESSAGE_AD_COMMENT_DELETE_FORBIDDEN def test_delete_ad_action_comment_not_found(): """Test delete ad action comment not found.""" with pytest.raises(exc.OwsError) as err: ad_action_comment.delete_ad_action_comment(11, 2) assert err.value.status == status.NOT_FOUND def test_delete_ad_action_comment_deleted(): """Test delete ad action comment deleted.""" with pytest.raises(exc.OwsError) as err: ad_action_comment.delete_ad_action_comment(4, 2) assert err.value.status == status.NOT_FOUND assert err.value.message == error.ERROR_MESSAGE_AD_COMMENT_NOT_FOUND def test_get_ad_action_comments_count(): """Test get ad actions comments count.""" result = ad_action_comment.get_ad_action_comments_count([1]) assert len(result['items']) == 1 assert result['items'][0]['ad_read_id'] == 1 assert result['items'][0]['total_records'] == 3