def test_tweets_params(self):
        """Test tweets API call with params"""

        setup_http_server()

        client = TwitterClient("aaa", max_items=2)
        group_tweets = client.tweets("query", since_id=1, max_id=1005163131042193407,
                                     geocode="37.781157 -122.398720 1km", lang="eu",
                                     include_entities=False, result_type=TWEET_TYPE_POPULAR)
        group_tweets = [tweets for tweets in group_tweets]

        self.assertEqual(len(group_tweets), 2)

        expected = {
            'q': ['query'],
            'since_id': ['1'],
            'max_id': ['1005163131042193407'],
            'count': ['2'],
            'include_entities': ['False'],
            'result_type': ['popular'],
            'geocode': ['37.781157 -122.398720 1km'],
            'lang': ['eu']
        }

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"], "Bearer aaa")
    def test_too_many_requests(self):
        """Test if a Retry error is raised"""

        setup_http_server(status=429)

        client = TwitterClient("aaa", max_items=2, sleep_time=0.1)
        start = float(time.time())
        expected = start + (sum([i * client.sleep_time for i in range(client.MAX_RETRIES)]))

        events = client.tweets('query')
        with self.assertRaises(requests.exceptions.RetryError):
            _ = [event for event in events]

        end = float(time.time())
        self.assertGreater(end, expected)
    def test_tweets_no_params(self):
        """Test tweets API call with no params"""

        setup_http_server()

        client = TwitterClient("aaa", max_items=2)
        group_tweets = client.tweets("query")
        group_tweets = [tweets for tweets in group_tweets]

        self.assertEqual(len(group_tweets), 2)

        # Check requests
        expected = {
            'q': ['query'],
            'count': ['2'],
            'max_id': ['1005163131042193407'],
            'include_entities': ['True'],
            'result_type': ['mixed']
        }

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"], "Bearer aaa")