コード例 #1
0
ファイル: CoreTest.py プロジェクト: carriercomm/Spark-4
 def testSendEvent(self):
     """ EventSender should send messages that match its pattern"""
     ev = EventSender("foo")
     ev2 = EventSender("bar", int)
     ev.suscribe()
     ev2.suscribe()
     ev()
     ev2(1)
     assertMatch(Event("foo"), ev.pattern)
     assertMatch(Event("bar", int), ev2.pattern)
     assertMatch(Event("foo"), Process.receive())
     assertMatch(Event("bar", int), Process.receive())
コード例 #2
0
ファイル: IntegrationTest.py プロジェクト: xya/Spark
 def testTcpSession(self):
     with TestServer() as server:
         server.listening.suscribe()
         Process.send(server.pid, Command("bind", (BIND_ADDRESS, BIND_PORT)))
         assertMatch(Event("listening", None), Process.receive())
         with TcpMessenger() as client:
             client.protocolNegociated.suscribe()
             client.disconnected.suscribe()
             client.connect((BIND_ADDRESS, BIND_PORT))
             assertMatch(Event("protocol-negociated", basestring), Process.receive())
             client.send(Request("swap", "foo", "bar").withID(1))
             assertMatch(Response("swap", "bar", "foo").withID(1), Process.receive())
         assertMatch(Event("disconnected"), Process.receive())
コード例 #3
0
ファイル: MessagingTest.py プロジェクト: carriercomm/Spark-4
 def testMessages(self):
     """ match() should properly match message patterns """
     assertMatch(Request("swap", str, str), Request("swap", "foo", "bar").withID(1))
     assertMatch(Event("listening", None), Event('listening', ('127.0.0.1', 4550)))
     assertMatch(Block, Block(0, 1, 'foo'))
     assertNoMatch(Request("paws"), Request("swap", "foo", "bar").withID(1))
     assertNoMatch(Request("swap", "foo", "bar").withID(1), Request("swap"))
     assertNoMatch(('disconnect', ), Event("protocol-negociated", "SPARKv1"))
コード例 #4
0
ファイル: IoTest.py プロジェクト: carriercomm/Spark-4
 def startClient(self):
     with TestSecureTcpSocket(ClientSecureTcpReceiver, 'alice.pub.gpg', 'alice.priv.gpg') as client:
         client.connected.suscribe()
         client.certificateReceived.suscribe()
         client.disconnected.suscribe()
         client.connect((BIND_ADDRESS, BIND_PORT))
         assertMatch(client.connected.pattern, Process.receive())
         auth = Process.receive()
         assertMatch(Event("certificate-received", None), auth)
         peer_cert = auth[2]
         self.assertEqual("b778501ce25e5fc894c8d93364a5d23253a4402", peer_cert.fingerprint)
         client.startSession()
         client.send("foo")
         assertMatch(Event("packet-received", "foo"), Process.receive())
         client.disconnect()
         assertMatch(client.disconnected.pattern, Process.receive())
コード例 #5
0
ファイル: IoTest.py プロジェクト: carriercomm/Spark-4
 def testSecureConnection(self):
     # enable GnuTLS logging
     log_func_ptr = gnutls_log_func(lambda level, message: Process.logger().info(message.rstrip()))
     gnutls_global_set_log_function(log_func_ptr)
     gnutls_global_set_log_level(5)
     with TestSecureTcpSocket(ServerSecureTcpReceiver, 'barney.pub.gpg', 'barney.priv.gpg') as server:
         server.listening.suscribe()
         server.connected.suscribe()
         server.certificateReceived.suscribe()
         server.disconnected.suscribe()
         server.listen((BIND_ADDRESS, BIND_PORT))
         assertMatch(server.listening.pattern, Process.receive())
         server.accept()
         Process.spawn_linked(self.startClient, name="testSecureConnectionClient")
         assertMatch(server.connected.pattern, Process.receive())
         auth = Process.receive()
         assertMatch(Event("certificate-received", None), auth)
         peer_cert = auth[2]
         self.assertEqual("27fbcdf93820a93363987a1d6beca16cefaf6aa4", peer_cert.fingerprint)
         server.startSession()
         assertMatch(server.disconnected.pattern, Process.receive())
コード例 #6
0
ファイル: IoTest.py プロジェクト: carriercomm/Spark-4
 def testConection(self):
     server = TestTcpSocket(EchoTcpReceiver)
     client = TestTcpSocket(NotifierTcpReceiver)
     with server:
         server.listen((BIND_ADDRESS, BIND_PORT))
         server.accept()
         with client:
             client.connected.suscribe()
             client.disconnected.suscribe()
             client.connect((BIND_ADDRESS, BIND_PORT))
             assertMatch(client.connected.pattern, Process.receive())
             client.send("foo")
             assertMatch(Event("packet-received", "foo"), Process.receive())
             client.disconnect()
             assertMatch(client.disconnected.pattern, Process.receive())
コード例 #7
0
ファイル: MessagingTest.py プロジェクト: carriercomm/Spark-4
 def testMatchSubclass(self):
     """ match()  should match a type if it is one of its parent types """
     assertMatch(basestring, u"foo")
コード例 #8
0
ファイル: MessagingTest.py プロジェクト: carriercomm/Spark-4
 def testTuples(self):
     """ match() should properly match tuple patterns """
     assertMatch(("foo", int), ("foo", 1))
     assertNoMatch(("foo", int), ("bar", 1))
コード例 #9
0
ファイル: MessagingTest.py プロジェクト: carriercomm/Spark-4
 def testString(self):
     """ match() should properly match string patterns """
     assertMatch("foo", "foo")
     assertNoMatch("foo", "bar")
コード例 #10
0
ファイル: ProtocolTest.py プロジェクト: carriercomm/Spark-4
 def assertMessagesEqual(self, expected, actual):
     assertMatch(expected, actual)
コード例 #11
0
ファイル: CoreTest.py プロジェクト: carriercomm/Spark-4
 def testComparingMessages(self):
     assertMatch(Command('foo'), Command('foo'))
     assertNoMatch(Command('foo'), Event('foo'))