예제 #1
0
  def test_mpdclient_connect_no_password(self):
    mpdconf={"host":"host","port":6600}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdmock=Mock()
    mpdclient.client=mpdmock
    # Call
    mpdclient.connect()
    # Test
    mpdmock.connect.assert_called_with(mpdconf["host"], mpdconf["port"])
예제 #2
0
  def test_mpdclient_disconnect_none_doesnt_raises(self):
    """
    Test that when a connection error is raised on disconnect
    """
    mpdconf={"host":"badhost","port":6600}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdclient.client=None

    # Call
    mpdclient.disconnect()
예제 #3
0
  def test_mpdclient_disconnect_mpdexception_raises_mpdclientexception(self):
    mpdconf={"host":"badhost","port":6600}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdmock=Mock()
    mpdclient.client=mpdmock
    #Mock the connect method
    disconnect=Mock(side_effect=MPDError())
    mpdmock.disconnect=disconnect

    # Call
    with self.assertRaises(MpdClientException):
      mpdclient.disconnect()
예제 #4
0
  def test_mpdclient_disconnect_connectionexception_doesnt_raises(self):
    """
    Test that when a connection error is raised on disconnect no exception is raised
    """
    mpdconf={"host":"badhost","port":6600}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdmock=Mock()
    mpdclient.client=mpdmock
    #Mock the connect method
    disconnect=Mock(side_effect=ConnectionError())
    mpdmock.disconnect=disconnect

    # Call
    mpdclient.disconnect()
예제 #5
0
  def test_mpdclient_connectexception_raises_mpdclientexception(self):
    mpdconf={"host":"badhost","port":6600}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdmock=Mock()
    mpdclient.client=mpdmock
    #Mock the connect method and reaise MPDError
    connect=Mock(side_effect=MPDError())
    mpdmock.connect=connect
    # Call
    with self.assertRaises(MpdClientException):
      mpdclient.connect()

    # Methods call assertions
    mpdmock.connect.assert_called_with(mpdconf["host"], mpdconf["port"])
예제 #6
0
  def test_mpdclient_connect_bad_password_raises_mpdclientexception(self):
    mpdconf={"host":"badhost","port":6600, "password":"******"}
    mpdclient = MpdClient(mpdconf)

    #Mock the mpd client
    mpdmock=Mock()
    mpdclient.client=mpdmock
    #Mock the password method
    password=Mock(side_effect=CommandError())
    mpdmock.password=password

    # Call
    with self.assertRaises(MpdClientException):
      mpdclient.connect()

    # Methods call assertions
    mpdmock.connect.assert_called_with(mpdconf["host"], mpdconf["port"])
    mpdmock.password.assert_called_with(mpdconf["password"])
예제 #7
0
class MpdRmqAgent(RabbitMqAgent):
  def __init__(self, config={}, mpdconf={}, rmqconf={}):
    RabbitMqAgent.__init__(self, config, rmqconf)
    self.mpdclient = MpdClient(mpdconf)
    
    
  def before_execute(self):
    LOGGER.debug("before_execute")
    self.mpdclient.connect()
    RabbitMqAgent.before_execute(self)
  
  def after_execute(self):
    LOGGER.debug("after_execute")
    RabbitMqAgent.after_execute(self)

  def ensure_after_execute(self):
    LOGGER.debug("ensure_after_execute")
    try:
      RabbitMqAgent.ensure_after_execute(self)
    except Exception, ex:
      LOGGER.error("Error on error calling parent ensure_after_execute")
      raise MpdRmqException, MpdRmqException(ex), sys.exc_info()[2] # keep stacktrace
    finally:
예제 #8
0
 def __init__(self, config={}, mpdconf={}, rmqconf={}):
   RabbitMqAgent.__init__(self, config, rmqconf)
   self.mpdclient = MpdClient(mpdconf)