def test_equality(self): m1 = PingMessage() m2 = PingMessage() m3 = PingMessage(id='m3') m4 = PingMessage(id='m4') self.assertEqual(m1, m1) self.assertEqual(m1, m2) self.assertEqual(m3, m3) self.assertNotEqual(m1, m3) self.assertNotEqual(m3, m4) self.assertNotEqual(m1, object()) self.assertNotEqual(m3, object())
def test_parse_without_id(self): message = self.parser.parse({'msg': 'ping'}) self.assertEqual(message, PingMessage())
def test_parse_with_id(self): id = 'test' message = self.parser.parse({'msg': 'ping', 'id': id}) self.assertEqual(message, PingMessage(id=id))
def test_without_id(self): message = PingMessage() self.assertFalse(message.has_id()) self.assertIsNone(message.id)
def test_with_id(self): id = 'test' message = PingMessage(id=id) self.assertTrue(message.has_id()) self.assertEqual(message.id, id)
def test_serialize_without_id(self): pod = self.serializer.serialize(PingMessage()) self.assertEqual(pod, {'msg': 'ping'})
def test_serialize_with_id(self): id = 'test' pod = self.serializer.serialize(PingMessage(id=id)) self.assertEqual(pod, {'msg': 'ping', 'id': id})