Exemple #1
0
    def test_get_room_id(self):
        """Test whether room id is returned"""

        setup_http_server()

        client = GitterClient(api_token='aaa', ssl_verify=True)
        room_id = client.get_room_id('testapicomm/community')
        self.assertEqual(room_id, GITTER_ROOM_ID)
Exemple #2
0
    def test_room_id_not_found(self):
        """Test whether room id returned is
        None when room id is not found
        """
        setup_http_server()

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

        self.assertIsNone(client.get_room_id('testapicomm/community_not'))
Exemple #3
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 #4
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)