Exemplo n.º 1
0
  def test_connect_exceptions(self):
    credpatcher = patch('pika.PlainCredentials')
    mockedcred = credpatcher.start()
    
    paramspatcher = patch('pika.ConnectionParameters')
    mockedparams = paramspatcher.start()
    
    conpatcher = patch('pika.BlockingConnection')
    mockedcon = conpatcher.start()
    mockedcon.side_effect=Exception("In your face")
    
    config={"host":"host", "port":5656, "user":"******","password":"******"}
    co = RabbitmqClient(config)
    
    with self.assertRaises(RabbitmqClientException):
      co.connect()

    credpatcher.stop()
    paramspatcher.stop()
    conpatcher.stop()
Exemplo n.º 2
0
  def test_connect(self):
    credpatcher = patch('pika.PlainCredentials')
    mockedcred = credpatcher.start()
    
    paramspatcher = patch('pika.ConnectionParameters')
    mockedparams = paramspatcher.start()
    
    conpatcher = patch('pika.BlockingConnection')
    mockedcon = conpatcher.start()
    
    config={"host":"host", "port":5656, "user":"******","password":"******"}
    co = RabbitmqClient(config)

    co.connect()
    self.assertFalse(co._channel is None)


    mockedcred.assert_called_with(config["user"], config["password"])
    mockedparams.assert_called_with(host=config["host"], port=config["port"], credentials=mockedcred.return_value)
    mockedcon.assert_called_with(mockedparams.return_value)

    credpatcher.stop()
    paramspatcher.stop()
    conpatcher.stop()