def test_build(self): mock_entity_factory = mock.Mock() mock_embed = object() mock_component = mock.Mock() mock_serialized_embed = object() mock_entity_factory.serialize_embed.return_value = ( mock_serialized_embed, []) builder = (special_endpoints.InteractionMessageBuilder( base_interactions.ResponseType.MESSAGE_CREATE).add_embed( mock_embed).add_component(mock_component).set_content( "a content").set_flags(2323).set_tts( True).set_mentions_everyone(False).set_user_mentions( [123]).set_role_mentions([54234])) result = builder.build(mock_entity_factory) mock_entity_factory.serialize_embed.assert_called_once_with(mock_embed) mock_component.build.assert_called_once_with() assert result == { "type": base_interactions.ResponseType.MESSAGE_CREATE, "data": { "content": "a content", "components": [mock_component.build.return_value], "embeds": [mock_serialized_embed], "flags": 2323, "tts": True, "allowed_mentions": { "parse": [], "users": ["123"], "roles": ["54234"] }, }, }
def test_components_property(self): mock_component = object() builder = special_endpoints.InteractionMessageBuilder(4) assert builder.components == [] builder.add_component(mock_component) assert builder.components == [mock_component]
def test_embeds_property(self): mock_embed = object() builder = special_endpoints.InteractionMessageBuilder(4) assert builder.embeds == [] builder.add_embed(mock_embed) assert builder.embeds == [mock_embed]
def test_build_handles_attachments(self): mock_entity_factory = mock.Mock() mock_entity_factory.serialize_embed.return_value = (object(), [object()]) builder = special_endpoints.InteractionMessageBuilder( base_interactions.ResponseType.MESSAGE_CREATE).add_embed(object()) with pytest.raises( ValueError, match= "Cannot send an embed with attachments in a slash command's initial response" ): builder.build(mock_entity_factory)
def test_build_for_partial_when_message_update(self): mock_entity_factory = mock.Mock() builder = special_endpoints.InteractionMessageBuilder( base_interactions.ResponseType.MESSAGE_UPDATE) result, attachments = builder.build(mock_entity_factory) mock_entity_factory.serialize_embed.assert_not_called() assert result == { "type": base_interactions.ResponseType.MESSAGE_UPDATE, "data": {} } assert attachments == []
def test_build_handles_attachments(self): mock_attachment = mock.Mock() mock_other_attachment = mock.Mock() mock_entity_factory = mock.Mock() mock_entity_factory.serialize_embed.return_value = (object(), [ mock_other_attachment ]) builder = (special_endpoints.InteractionMessageBuilder( base_interactions.ResponseType.MESSAGE_CREATE).add_attachment( mock_attachment).add_embed(object())) _, attachments = builder.build(mock_entity_factory) assert attachments == [ files.ensure_resource(mock_attachment), mock_other_attachment ]
def test_build_for_partial_when_empty_lists(self): mock_entity_factory = mock.Mock() builder = special_endpoints.InteractionMessageBuilder( base_interactions.ResponseType.MESSAGE_UPDATE, attachments=[], components=[], embeds=[]) result, attachments = builder.build(mock_entity_factory) mock_entity_factory.serialize_embed.assert_not_called() assert result == { "type": base_interactions.ResponseType.MESSAGE_UPDATE, "data": { "components": [], "embeds": [], }, } assert attachments == []
def test_type_property(self): builder = special_endpoints.InteractionMessageBuilder(4) assert builder.type == 4
def test_user_mentions_property(self): builder = special_endpoints.InteractionMessageBuilder( 4).set_user_mentions([33333, 44444]) assert builder.user_mentions == [33333, 44444]
def test_role_mentions_property(self): builder = special_endpoints.InteractionMessageBuilder( 4).set_role_mentions([999]) assert builder.role_mentions == [999]
def test_mentions_everyone_property(self): builder = special_endpoints.InteractionMessageBuilder( 4).set_mentions_everyone([123, 453]) assert builder.mentions_everyone == [123, 453]
def test_embeds_property_when_undefined(self): builder = special_endpoints.InteractionMessageBuilder(4) assert builder.embeds is undefined.UNDEFINED
def test_flags_property(self): builder = special_endpoints.InteractionMessageBuilder(4).set_flags( 95995) assert builder.flags == 95995
def test_content_property(self): builder = special_endpoints.InteractionMessageBuilder(4).set_content( "ayayayaya") assert builder.content == "ayayayaya"
def test_is_tts_property(self): builder = special_endpoints.InteractionMessageBuilder(4).set_tts(False) assert builder.is_tts is False
def test_set_content_casts_to_str(self): mock_thing = mock.Mock(__str__=mock.Mock(return_value="meow nya")) builder = special_endpoints.InteractionMessageBuilder(4).set_content( mock_thing) assert builder.content == "meow nya"
def test_attachments_property(self): mock_attachment = mock.Mock() builder = special_endpoints.InteractionMessageBuilder( 4).add_attachment(mock_attachment) assert builder.attachments == [mock_attachment]