def test_makes_requests(self, mock_requests): TwitterAPIData.MAX_IN_A_REQUEST = 2 twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list(twitter_data.twitter_results( 'screen_name', ['mhl20', 'struan', 'symroe'])) self.assertEqual( mock_requests.post.mock_calls, [ call( 'https://api.twitter.com/1.1/users/lookup.json', headers={u'Authorization': u'Bearer madeuptoken'}, data={u'screen_name': u'mhl20,struan'}), call( 'https://api.twitter.com/1.1/users/lookup.json', headers={u'Authorization': u'Bearer madeuptoken'}, data={u'screen_name': u'symroe'}), ] ) self.assertEqual( twitter_results, [ {'id': 1234, 'screen_name': 'mhl20'}, {'id': 5678, 'screen_name': 'struan'}, {'id': 9012, 'screen_name': 'symroe'}, ] )
def test_zero_results_for_user_id_lookup(self, mock_requests): twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list(twitter_data.twitter_results( 'user_id', ['13984716923847632'])) self.assertEqual(twitter_results, [])
def test_zero_results_for_screen_name_lookup(self, mock_requests): twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list(twitter_data.twitter_results( 'screen_name', ['onlynonexistent'])) self.assertEqual(twitter_results, [])
def test_makes_requests(self, mock_requests): TwitterAPIData.MAX_IN_A_REQUEST = 2 twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list( twitter_data.twitter_results('screen_name', ['mhl20', 'struan', 'symroe'])) self.assertEqual(mock_requests.post.mock_calls, [ call('https://api.twitter.com/1.1/users/lookup.json', headers={'Authorization': 'Bearer madeuptoken'}, data={'screen_name': 'mhl20,struan'}), call('https://api.twitter.com/1.1/users/lookup.json', headers={'Authorization': 'Bearer madeuptoken'}, data={'screen_name': 'symroe'}), ]) self.assertEqual(twitter_results, [ { 'id': 1234, 'screen_name': 'mhl20' }, { 'id': 5678, 'screen_name': 'struan' }, { 'id': 9012, 'screen_name': 'symroe' }, ])
def test_unfaked_urls_raise_exception(self, mock_requests): TwitterAPIData.MAX_IN_A_REQUEST = 2 twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post with self.assertRaises(Exception): list(twitter_data.twitter_results( 'screen_name', ['foo', 'bar']))
def test_zero_results_for_screen_name_lookup(self, mock_requests): twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list( twitter_data.twitter_results('screen_name', ['onlynonexistent'])) self.assertEqual(twitter_results, [])
def test_unfaked_urls_raise_exception(self, mock_requests): TwitterAPIData.MAX_IN_A_REQUEST = 2 twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post with self.assertRaises(Exception): list(twitter_data.twitter_results('screen_name', ['foo', 'bar']))
def test_zero_results_for_user_id_lookup(self, mock_requests): twitter_data = TwitterAPIData() mock_requests.post.side_effect = fake_twitter_api_post twitter_results = list( twitter_data.twitter_results('user_id', ['13984716923847632'])) self.assertEqual(twitter_results, [])