Exemple #1
0
    def test_rate_limit_error(self):
        """Test if a rate limit error is raised when rate is exhausted"""

        wait = 2
        reset = int(time.time() + wait)
        rate_limit_headers = {
            'X-RateLimit-Remaining': '0',
            'X-RateLimit-Reset': reset
        }

        setup_http_server(rate_limit_headers=rate_limit_headers)

        client = GitterClient('aaaa', max_items=1, sleep_for_rate=False)

        room_id = client.get_room_id('testapicomm/community')
        with self.assertRaises(RateLimitError):
            _ = [m for m in client.message_page(room_id, before_id=None)]
Exemple #2
0
    def test_message(self):
        """Test whether messages are fetched"""

        setup_http_server()

        client = GitterClient(api_token='aaa', ssl_verify=True)

        messages = [
            m for m in client.message_page(GITTER_ROOM_ID, before_id=None)
        ]

        self.assertEqual(len(messages), 6)

        # Check requests
        expected = {
            'limit': ['100'],
        }

        self.assertEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"],
                         'Bearer aaa')
Exemple #3
0
    def test_sleep_for_rate(self):
        """Test if the clients sleeps when the rate limit is reached"""

        wait = 10
        reset = int(time.time() + wait)
        rate_limit_headers = {
            'X-RateLimit-Remaining': '0',
            'X-RateLimit-Reset': reset
        }

        setup_http_server(rate_limit_headers=rate_limit_headers)

        client = GitterClient('aaaa',
                              max_items=2,
                              min_rate_to_sleep=5,
                              sleep_for_rate=True)

        room_id = client.get_room_id('testapicomm/community')
        _ = [m for m in client.message_page(room_id, before_id=None)]
        after = float(time.time())

        self.assertTrue(reset >= after)