def setup_mock_data(self, mocker: requests_mock.Mocker) -> None: """Fetch tweets from ch and twitter. Setup mocking if self.mock_enabled.""" # add the mocker for the ch api calls mocker.get('https://api.crimsonhexagon.com/api/monitor/posts', text=_mock_ch_posts) # seaprately we need to add the mocker for the twitter api calls twitter.add_mockers(mocker)
def test_fetch_100_users() -> None: """Test fetch_100_tweets using mock.""" with requests_mock.Mocker() as m: twitter.add_mockers(m) got_users = twitter.fetch_100_users(['foo', 'bar', 'bat']) got_screen_names = [u['screen_name'] for u in got_users] assert sorted(got_screen_names) == ['bar', 'bat', 'foo']
def setup_mock_data(self, mocker: requests_mock.Mocker) -> None: """Fetch tweets from ch and twitter. Setup mocking if self.mock_enabled.""" # add the mockers for the bw api calls matcher = re.compile('.*api.brandwatch.com/oauth/token.*') mocker.post('https://api.brandwatch.com/oauth/token', text=_mock_oauth) matcher = re.compile('.*api.brandwatch.com/projects.*') mocker.get(matcher, text=_mock_posts) # seaprately we need to add the mocker for the twitter api calls twitter.add_mockers(mocker)
def test_fetch_100_tweets() -> None: """Test fetch_100_tweets using mock.""" fetch_ids = range(100) with requests_mock.Mocker() as m: twitter.add_mockers(m) got_tweets = twitter.fetch_100_tweets(fetch_ids) got_tweets = sorted(got_tweets, key=lambda t: int(t['id_str'])) for (i, tweet) in enumerate(got_tweets): assert (tweet['id_str'] == str(i))