コード例 #1
0
ファイル: test_xmpp_receiver.py プロジェクト: shnaizerk/gts
    def test_receive_one_message(self):
        # mock out the xmpp connection and have it connect and authenticate
        fake_connection = flexmock(name='fake_connection', _sock="the socket")
        fake_client = flexmock(name='fake_client', Connection=fake_connection)
        fake_client.should_receive('connect').and_return(True)
        fake_client.should_receive('auth').with_args(
            self.appid, self.password, resource='').and_return(True)

        # also add in mocks for when messages are received or when we see
        # presence notifications
        fake_client.should_receive('RegisterHandler').and_return()

        # add in a mock for when we send our presence message to the XMPP server
        fake_client.should_receive('sendInitPresence').and_return()

        # and make sure that we only process one message
        fake_client.should_receive('Process').and_return(len('the message')).\
          and_return(0)

        flexmock(xmpp)
        xmpp.should_receive('Client').with_args(self.login_ip, debug=[]) \
          .and_return(fake_client)

        receiver = XMPPReceiver(self.appid, self.login_ip,
                                self.load_balancer_ip, self.password)
        receiver.listen_for_messages()
コード例 #2
0
    def test_receive_one_message(self):
        # mock out the xmpp connection and have it connect and authenticate
        fake_connection = flexmock(name='fake_connection', _sock="the socket")
        fake_client = flexmock(name='fake_client', Connection=fake_connection)
        fake_client.should_receive('connect').and_return(True)
        fake_client.should_receive('auth').with_args(
            self.appid, self.password, resource='').and_return(True)

        # also add in mocks for when messages are received or when we see
        # presence notifications
        fake_client.should_receive('RegisterHandler').and_return()

        # add in a mock for when we send our presence message to the XMPP server
        fake_client.should_receive('sendInitPresence').and_return()

        # and make sure that we only process one message
        fake_client.should_receive('Process').with_args(1).once()

        flexmock(xmpp)
        xmpp.should_receive('Client').with_args(self.login_ip, debug=[]) \
          .and_return(fake_client)

        # finally, mock out 'select', and have it put in a message
        flexmock(select)
        message = {"the socket": "xmpp"}
        select.should_receive('select').with_args(['the socket'], [], [], 1) \
          .and_return(message, None, None)

        receiver = XMPPReceiver(self.appid, self.login_ip,
                                self.load_balancer_ip, self.password)
        actual_messages_sent = receiver.listen_for_messages(
            messages_to_listen_for=1)
        self.assertEquals(1, actual_messages_sent)
コード例 #3
0
  def test_receive_one_message(self):
    # mock out the xmpp connection and have it connect and authenticate
    fake_connection = flexmock(name='fake_connection', _sock="the socket")
    fake_client = flexmock(name='fake_client', Connection=fake_connection)
    fake_client.should_receive('connect').and_return(True)
    fake_client.should_receive('auth').with_args(self.appid, self.password,
      resource='').and_return(True)

    # also add in mocks for when messages are received or when we see
    # presence notifications
    fake_client.should_receive('RegisterHandler').and_return()

    # add in a mock for when we send our presence message to the XMPP server
    fake_client.should_receive('sendInitPresence').and_return()

    # and make sure that we only process one message
    fake_client.should_receive('Process').with_args(1).once()

    flexmock(xmpp)
    xmpp.should_receive('Client').with_args(self.login_ip, debug=[]) \
      .and_return(fake_client)

    # finally, mock out 'select', and have it put in a message
    flexmock(select)
    message = {"the socket" : "xmpp"}
    select.should_receive('select').with_args(['the socket'], [], [], 1) \
      .and_return(message, None, None)

    receiver = XMPPReceiver(self.appid, self.login_ip, self.load_balancer_ip,
                            self.password)
    actual_messages_sent = receiver.listen_for_messages(
      messages_to_listen_for=1)
    self.assertEquals(1, actual_messages_sent)