def test_search_email_finds_email(self): api = mock.MagicMock(spec=API) iteration = {"counter": -1} mocked_tweets = [ mock.MagicMock(spec=Status, id=1, text="???"), mock.MagicMock( spec=Status, id=2, text="Tweet text [email protected].", author=mock.MagicMock(spec=User, screen_name="rmotr_com"), ), mock.MagicMock(spec=Status, id=3, text="???"), ] def _next(_self): iteration["counter"] += 1 return mocked_tweets[iteration["counter"]] with mock.patch.object(Tweets, next_method, new=_next): results = search_emails(api, "rmotr_com", "rmotr.com") result = next(results) self.assertIsNotNone(result) self.assertEqual(result.tweet, mocked_tweets[1]) self.assertEqual(result.email, "*****@*****.**")
def test_search_email_finds_email(self): api = mock.MagicMock(spec=API) iteration = {'counter': -1} mocked_tweets = [ mock.MagicMock(spec=Status, id=1, text="???"), mock.MagicMock(spec=Status, id=2, text="Tweet text [email protected].", author=mock.MagicMock(spec=User, screen_name='rmotr_com')), mock.MagicMock(spec=Status, id=3, text="???") ] def _next(_self): iteration['counter'] += 1 return mocked_tweets[iteration['counter']] with mock.patch.object(Tweets, next_method, new=_next): results = search_emails(api, 'rmotr_com', 'rmotr.com') result = next(results) self.assertIsNotNone(result) self.assertEqual(result.tweet, mocked_tweets[1]) self.assertEqual(result.email, '*****@*****.**')
def interactive_search_emails(handle, domain, consumer_key, secret_key, interactive): auth = tweepy.AppAuthHandler(consumer_key, secret_key) api = tweepy.API(auth) results = [] msg = "I've just found '{}'. Should I stop now?" try: for result in search_emails(api, handle, domain): if result not in results: results.append(result) if not interactive: click.echo("Found {}".format(result.email)) continue if click.confirm(msg.format(result.email)): raise KeyboardInterrupt() except KeyboardInterrupt: show_results(results) sys.exit(0) else: show_results(results)