def test_oef_message_consistency(): """Tests the consistency of an OEFMessage.""" foo_datamodel = DataModel( "foo", [Attribute("bar", int, True, "A bar attribute.")]) msg = OEFMessage(oef_type=OEFMessage.Type.SEARCH_AGENTS, id=2, query=Query([Constraint("bar", ConstraintType("==", 1))], model=foo_datamodel)) assert msg.check_consistency(), "We expect the consistency to return TRUE" with mock.patch("aea.protocols.oef.message.OEFMessage.Type")\ as mock_type_enum: mock_type_enum.SEARCH_AGENTS.value = "unknown" assert not msg.check_consistency(),\ "Expect the consistency to return False"
def test_oef_message_consistency(): """Tests the consistency of an OEFMessage.""" foo_datamodel = DataModel( "foo", [Attribute("bar", int, True, "A bar attribute.")]) msg = OEFMessage(oef_type=OEFMessage.Type.SEARCH_AGENTS, id=2, query=Query([Constraint("bar", ConstraintType("==", 1))], model=foo_datamodel)) assert msg.check_consistency(), "We expect the consistency to return TRUE" with mock.patch("aea.protocols.oef.message.OEFMessage.Type")\ as mock_type_enum: mock_type_enum.SEARCH_AGENTS.value = "unknown" assert not msg.check_consistency(),\ "Expect the consistency to return False" attribute_foo = Attribute("foo", int, True, "a foo attribute.") attribute_bar = Attribute("bar", str, True, "a bar attribute.") data_model_foobar = DataModel("foobar", [attribute_foo, attribute_bar], "A foobar data model.") description_foobar = Description({ "foo": 1, "bar": "baz" }, data_model=data_model_foobar) msg = OEFMessage(oef_type=OEFMessage.Type.REGISTER_AGENT, id=0, agent_description=description_foobar, agent_id="public_key") assert msg.check_consistency() msg = OEFMessage(oef_type=OEFMessage.Type.UNREGISTER_AGENT, id=0, agent_description=description_foobar, agent_id="public_key") assert msg.check_consistency()