Пример #1
0
    def test_init(self):
        hipchat = HipChat(nick='Sarah',
                          jid='test@localhost',
                          password='******',
                          rooms=['123_homer@localhost'],
                          plugins=(),
                          proxy={
                              'host': 'localhost',
                              'port': 1234,
                              'username': '******',
                              'password': '******'
                          })

        # This doesn't work with assertpy.
        # Does this have something to do with ABCMeta?
        # assert_that(hipchat).is_instance_of(HipChat)
        assert isinstance(hipchat, HipChat) is True

        assert_that(hipchat) \
            .has_nick('Sarah') \
            .has_rooms(['123_homer@localhost'])

        assert_that(hipchat.client) \
            .is_instance_of(ClientXMPP) \
            .has_use_proxy(True) \
            .has_proxy_config({'host': 'localhost',
                               'port': 1234,
                               'username': '******',
                               'password': '******'})

        assert_that(hipchat.client.requested_jid) \
            .is_not_none() \
            .is_instance_of(JID) \
            .is_equal_to(JID('test@localhost', cache_lock=True))
Пример #2
0
 def hipchat(self, request):
     # NO h.start() for this test
     h = HipChat(nick='Sarah',
                 jid='test@localhost',
                 password='******',
                 plugins=())
     h.client.send_presence = MagicMock()
     return h
Пример #3
0
    def hipchat(self, request):
        h = HipChat(nick='Sarah',
                    jid='test@localhost',
                    password='******',
                    plugins=None,
                    max_workers=4)

        return h
Пример #4
0
    def test_connection_fail(self):
        hipchat = HipChat(nick='Sarah',
                          jid='test@localhost',
                          password='******')

        with patch.object(hipchat.client, 'connect',
                          return_value=False) as mock_connect:
            with pytest.raises(SarahHipChatException) as e:
                hipchat.connect()

            assert_that(str(e)) \
                .matches("Couldn't connect to server\.")
            assert_that(mock_connect.call_count).is_equal_to(1)
Пример #5
0
    def test_no_setting(self):
        h = HipChat(nick='Sarah',
                    jid='test@localhost',
                    password='******',
                    plugins=())

        with patch.object(h.client.plugin['xep_0045'].xmpp,
                          'send',
                          return_value=None) as mock_send:
            h.join_rooms({})

            assert_that(mock_send.call_count).is_zero()
            assert_that(h.client.plugin['xep_0045']) \
                .has_rooms({}) \
                .has_ourNicks({})
Пример #6
0
    def test_success(self):
        h = HipChat(nick='Sarah',
                    jid='test@localhost',
                    rooms=['123_homer@localhost'],
                    password='******',
                    plugins=())

        with patch.object(h.client.plugin['xep_0045'].xmpp,
                          'send',
                          return_value=None) as mock_send:
            h.join_rooms({})

            assert_that(mock_send.call_count).is_equal_to(1)
            assert_that(h.client.plugin['xep_0045']) \
                .has_rooms({'123_homer@localhost': {}}) \
                .has_ourNicks({'123_homer@localhost': h.nick})