diff --git a/src/icalendar/prop/image.py b/src/icalendar/prop/image.py index 7549d71..ebce46b 100644 --- a/src/icalendar/prop/image.py +++ b/src/icalendar/prop/image.py @@ -73,6 +73,10 @@ class Image: display: str | None = None, ): """Create a new image according to :rfc:`7986`.""" + if uri is not None and b64data is not None: + raise ValueError("Image cannot have both URI and binary data (RFC 7986)") + if uri is None and b64data is None: + raise ValueError("Image must have either URI or binary data") self.uri = uri self.b64data = b64data self.fmttype = fmttype diff --git a/src/icalendar/tests/test_image.py b/src/icalendar/tests/test_image.py index c62169f..0425db9 100644 --- a/src/icalendar/tests/test_image.py +++ b/src/icalendar/tests/test_image.py @@ -157,3 +157,11 @@ def test_create_image_with_vText_as_binary(): assert img.fmttype is None assert img.altrep is None assert img.display is None + + +def test_requires_uri_xor_binary(): + """Test forbidden parameter combinations.""" + with pytest.raises(ValueError): + Image() + with pytest.raises(ValueError): + Image(b64data="", uri="http://example.com/image.png")