def test_drop_messages_from_decision_maker_inbox(self): """Test the drop_messages_from_decision_maker_inbox method.""" assert self.get_quantity_in_decision_maker_inbox() == 0 self.drop_messages_from_decision_maker_inbox(5) assert self.get_quantity_in_decision_maker_inbox() == 0 dummy_message_1 = Message() dummy_message_1.to = "some_to_1" dummy_message_1.sender = "some_sender_1" self.skill.skill_context.decision_maker_message_queue.put( dummy_message_1) dummy_message_2 = Message() dummy_message_2.to = "some_to_2" dummy_message_2.sender = "some_sender_2" self.skill.skill_context.decision_maker_message_queue.put( dummy_message_2) dummy_message_3 = Message() dummy_message_3.to = "some_to_3" dummy_message_3.sender = "some_sender_3" self.skill.skill_context.decision_maker_message_queue.put( dummy_message_3) assert self.get_quantity_in_decision_maker_inbox() == 3 self.drop_messages_from_decision_maker_inbox(2) assert self.get_quantity_in_decision_maker_inbox() == 1 assert self.get_message_from_decision_maker_inbox() == dummy_message_3
def test_to(self): """Test the 'to' attribute getter and setter.""" message = Message() with pytest.raises(ValueError, match="Message's 'To' field must be set."): message.to message.to = "to" assert message.to == "to" with pytest.raises(AEAEnforceError, match="To already set."): message.to = "to"
def test_to(self): """Test the 'to' attribute getter and setter.""" message = Message() with pytest.raises(AssertionError, match="To must not be None."): message.to message.to = "to" assert message.to == "to" with pytest.raises(AssertionError, match="To already set."): message.to = "to"
def _check_consistency(message: Message, to: str, sender: str) -> Message: """Check consistency of sender and to.""" if message.has_to: enforce(message.to == to, "To specified on message does not match envelope.") else: message.to = to if message.has_sender: enforce( message.sender == sender, "Sender specified on message does not match envelope.", ) else: message.sender = sender return message
def dummy_envelope( cls, to: str = "test", sender: str = "test", protocol_id: PublicId = DefaultMessage.protocol_id, message: Message = None, ) -> Envelope: """ Create envelope, if message is not passed use .dummy_message method. :return: Envelope """ message = message or cls.dummy_default_message() message.sender = sender message.to = to return Envelope( to=to, sender=sender, protocol_id=protocol_id, message=message, )