tweet_s3_images_test.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:lambda-tweet 作者: onema 项目源码 文件源码
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.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号