from unittest.mock import MagicMock import faker import pytest from anydi import Container from ows_text_campaigns.adapters.scanner import ContentRecommendations, ContentScanner from ows_text_campaigns.artist.models import ArtistPhoneNumber, ArtistSettings from ows_text_campaigns.campaigns.handlers import ( ScanCampaignContentHandler, ScanCampaignContentRequest, ) from ows_text_campaigns.campaigns.models import Campaign from tests.unit.types import CreateModel class TestScanArtistContentHandler: @pytest.mark.db def test_scan_artist_content_handler( self, container: Container, handler: ScanCampaignContentHandler, create_model: CreateModel, faker: faker.Faker, identity_id: str, ) -> None: artist_name = faker.name() global_participant_id = faker.uuid4() artist_settings = create_model( ArtistSettings, artist_name=artist_name, global_participant_id=global_participant_id, phone_numbers=[ ArtistPhoneNumber( global_participant_id=global_participant_id, phone_number=faker.phone_number(), ) ], ) campaign = create_model( Campaign, global_participant_id=artist_settings.global_participant_id, ) content_scanner_mock = MagicMock(spec=ContentScanner) content_scanner_mock.scan.return_value = ContentRecommendations( sensitiveWords=[], includedArtistName=True ) with container.override( ContentScanner, content_scanner_mock, ): response = handler.handle( ScanCampaignContentRequest( identity_id=identity_id, campaign_id=campaign.id, content="Hello world!", ), ) assert response == ContentRecommendations( sensitiveWords=[], includedArtistName=True )