"""Tests for ad action comment handler.""" from unittest.mock import MagicMock from oto import status from podcast.logic import ad_action_comment def test_get_ad_action_comment_handler(fixture_client, ad_read_comment_fixture, monkeypatch): """Test get ad actions comment handler.""" monkeypatch.setattr( ad_action_comment, 'get_ad_action_comments', MagicMock(return_value={'items': [ad_read_comment_fixture]}) ) result = fixture_client.get('/ad-read-comments-by-id/1') assert result.status_code == status.OK assert len(result.json['items']) == 1 def test_create_ad_action_comment_handler(fixture_client, new_ad_read_comment_fixture, monkeypatch): """Test create ad action comment handler.""" monkeypatch.setattr( ad_action_comment, 'create_ad_action_comment', MagicMock(return_value=new_ad_read_comment_fixture) ) result = fixture_client.post('/ad-read-comment', json=new_ad_read_comment_fixture) assert result.status_code == status.CREATED ad_action_comment.create_ad_action_comment.assert_called_once_with(new_ad_read_comment_fixture) def test_delete_ad_action_comment_handler(fixture_client, new_ad_read_comment_fixture, monkeypatch): """Test delete ad action comment handler.""" monkeypatch.setattr( ad_action_comment, 'delete_ad_action_comment', MagicMock(return_value=new_ad_read_comment_fixture) ) result = fixture_client.delete('/ad-read-comment/1') assert result.status_code == status.OK ad_action_comment.delete_ad_action_comment.assert_called_once_with(1) def test_get_ad_read_comments_count_handler(fixture_client, monkeypatch): """Test get ad actions comments count handler.""" monkeypatch.setattr( ad_action_comment, 'get_ad_action_comments_count', MagicMock(return_value={'items': ['test']}) ) params = '?ad_read_ids=1,2' result = fixture_client.get('/ad-read-comments-count' + params) assert result.status_code == status.OK assert len(result.json['items']) == 1