import base64 import faker import pytest from ows_text_campaigns.artist.vcard import ArtistVCard from ows_text_campaigns.assets.types import BinaryAsset class TestArtistVCard: def test_render_without_photo(self) -> None: vcard = ArtistVCard(name="Harry Styles", phone="+123456789") rendered = vcard.render() content = [ "BEGIN:VCARD", "VERSION:3.0", "FN:Harry Styles", "TEL;TYPE=CELL:+123456789", "END:VCARD", ] assert rendered == "\n".join(content) @pytest.mark.parametrize( ("image_format", "photo_type"), [ ("PNG", "PNG"), ("JPEG", "JPEG"), ("GIF", "GIF"), ("BMP", "BINARY"), ], ) def test_render_with_photo( self, image_format: str, photo_type: str, faker: faker.Faker ) -> None: photo_data = faker.image(size=(10, 10), image_format=image_format) photo = BinaryAsset.from_data(photo_data) vcard = ArtistVCard(name="Harry Styles", phone="+123456789", photo=photo) rendered = vcard.render() content = [ "BEGIN:VCARD", "VERSION:3.0", "FN:Harry Styles", "TEL;TYPE=CELL:+123456789", f"PHOTO;ENCODING=b;TYPE={photo_type}:{base64.b64encode(photo_data).decode()}", "END:VCARD", ] assert rendered == "\n".join(content)