Exemple #1
0
    def test_getTweetsByUsername_obtainResultFromApiSuccessfully(
            self, mocked_header, mocked_url, mocked_get):
        twitter_api = TwitterApi()

        mocked_url.return_value = "api_url"
        mocked_header.return_value = "header"

        json_response = "json_response"
        mocked_get.return_value.status_code = 200
        mocked_get.return_value.text = json_response

        twitter_api.getTweetsByUsername('hashtag', '3')

        mocked_get.assert_called_with("api_url", headers="header")
Exemple #2
0
    def test_getTweetsByUsername_handleExceptionOnApiBadRequest(
            self, mocked_header, mocked_url, mocked_get):
        twitter_api = TwitterApi()

        mocked_url.return_value = "api_url"
        mocked_header.return_value = "header"

        json_response = "json_response"
        mocked_get.return_value.status_code = 400
        mocked_get.return_value.text = json_response

        with self.assertRaises(Exception):
            twitter_api.getTweetsByUsername('nasa', '3')

        mocked_get.assert_called_with("api_url", headers="header")
Exemple #3
0
def tweets_user(user):
    limit = request.args.get('limit')
    if limit is None:
        limit = DEFAULT_LIMIT
    twitter_api = TwitterApi()
    json_response = twitter_api.getTweetsByUsername(user, limit)
    summary = twitter_api.extractTweetInfo(json_response)
    return json.dumps(summary)