예제 #1
0
 def test_publish(self):
     """ test publishing a message to the echo server """
     eb = Eventbus(port=7001,debug=True)
     handler=Handler(self.debug)
     eb.registerHandler("echo", handler.handle)
     #jsonObject -body
     body1 = {'msg': 'testpublish 1'}
     eb.wait(State.OPEN)
     # publish without headers
     eb.publish('echo', body1)
     # wait for the message to arrive
     time.sleep(RECEIVE_WAIT)
     eb.close()
     assert handler.result == body1
예제 #2
0
 def test_publishWithHeader(self):
     """ test publishing a message with headers """
     eb = Eventbus(port=7001,debug=self.debug)
     handler=Handler(self.debug)
     eb.registerHandler("echo", handler.handle)
     body2 = {'msg': 'testpublish with headers' }
     eb.addHeader('type', 'text')
     eb.addHeader('size', 'small')
     # publish with headers
     eb.publish('echo', body2)
     # wait for the message to arrive
     time.sleep(RECEIVE_WAIT)
     eb.close()
     assert handler.result == body2
     assert handler.headers == {'type': 'text', 'size': 'small'}