aucoin/tests/test_network.py

30 lines
798 B
Python
Raw Normal View History

2018-07-15 23:30:55 +02:00
import json
import logging
from twisted.test import proto_helpers
from twisted.trial import unittest
from aucoin.network import NetworkFactory, MsgType
logging.basicConfig(level=logging.DEBUG)
# http://twistedmatrix.com/documents/current/core/howto/trial.html#twisted-specific-testing
@unittest.SkipTest
class TestNetwork(unittest.TestCase):
def setUp(self):
factory = NetworkFactory()
self.protocol = factory.buildProtocol(("127.0.0.1", 0))
self.tr = proto_helpers.StringTransport()
self.protocol.makeConnection(self.tr)
self.tr.clear()
def test_ping(self):
self.protocol.send(MsgType.PING, None)
self.assertEqual(decode(self.tr.value()), {"msg_type": "PING", "payload": None})
def decode(data):
return json.loads(data)