def mock_user_timeline_more_active(user_id=None, count=None): status = Status() now = datetime.datetime.now() hours_since = now - datetime.timedelta(minutes=30) status.created_at = hours_since return [status]
def mock_user_timeline(user_id=None, count=None): status = Status() now = datetime.datetime.now() hours_since = now - datetime.timedelta(hours=4) status.created_at = hours_since return [status]
def test_sending_images(self): # ensure there is an image as the mock object will not do anything shutil.copy('./image.jpg', '/tmp/image.jpg') client = boto3.client('s3') client.download_file = MagicMock(return_value=None) auth = tweepy.OAuthHandler('foo', 'bar') api = tweepy.API(auth) api.update_with_media = MagicMock(return_value=Status()) tweet_images = TweetS3Images(api, client) tweet_images.send_image('test_bucket', 'image.jpg', cleanup=True) client.download_file.assert_called_with('test_bucket', 'image.jpg', '/tmp/image.jpg') api.update_with_media.assert_called_with( filename='image.jpg', status='New image image.jpg brought to you by lambda-tweet', file=tweet_images.get_file()) self.assertFalse(os.path.exists('/tmp/image-test.jpg'), 'The image was not cleaned up correctly.')
import unittest import logging import sys from tweepy.models import Status from TwitterWatcher.tweet_tracker import TweetTracker from tests.database.mock_database import MockDatabase dummy_status = Status() dummy_status._json = { 'id': 1, 'id_str': '1', 'text': 'test', 'user': { 'screen_name': 'test_user' } } dummy_reply = Status() dummy_reply._json = { 'id': 2, 'id_str': '2', 'text': 'test reply', 'user': { 'screen_name': 'test_reply_user' }, 'in_reply_to_status_id': 1 } class TwitterWatcherDatabaseTests(unittest.TestCase): def setUp(self):