def test_media(self):
     tweet = TweetFactory()
     photo_1 = PhotoFactory()
     photo_2 = PhotoFactory()
     photo_1.tweets.add(tweet)
     photo_2.tweets.add(tweet)
     self.assertEqual(2, tweet.media.count())
 def test_ordering(self):
     """Multiple accounts are sorted by time_created ascending"""
     time_now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
     photo_1 = PhotoFactory(
                     time_created=time_now - datetime.timedelta(minutes=1))
     photo_2 = PhotoFactory(time_created=time_now)
     photos = Media.objects.all()
     self.assertEqual(photos[0].pk, photo_1.pk)
 def test_default_manager(self):
     "Default Manager shows both private and public photos"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweet = TweetFactory(user=public_user)
     private_tweet = TweetFactory(user=private_user)
     public_photos = PhotoFactory.create_batch(2, tweets=(public_tweet,))
     private_photos = PhotoFactory.create_batch(1, tweets=(private_tweet,))
     self.assertEqual(len(Media.objects.all()), 3)
 def test_default_manager(self):
     "Default Manager shows both private and public photos"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweet = TweetFactory(user=public_user)
     private_tweet = TweetFactory(user=private_user)
     public_photos = PhotoFactory.create_batch(2, tweets=(public_tweet,))
     private_photos = PhotoFactory.create_batch(1, tweets=(private_tweet,))
     self.assertEqual(len(Media.objects.all()), 3)
 def test_tweets(self):
     "It should be possible to belong to more than one tweet."
     tweet_1 = TweetFactory(text='1')
     tweet_2 = TweetFactory(text='2')
     photo = PhotoFactory(tweets=(tweet_1, tweet_2,))
     self.assertEqual(2, photo.tweets.count())
     self.assertEqual(photo.tweets.all()[0], tweet_2)
     self.assertEqual(photo.tweets.all()[1], tweet_1)
 def test_size_urls(self):
     url = 'http://www.example.org/image.jpg'
     photo = PhotoFactory(image_url=url)
     self.assertEqual(photo.large_url,  '%s:large' % url)
     self.assertEqual(photo.medium_url, '%s:medium' % url)
     self.assertEqual(photo.small_url,  '%s:small' % url)
     self.assertEqual(photo.thumb_url,  '%s:thumb' % url)
     self.assertEqual(photo.thumbnail_url,  '%s:thumb' % url)
 def test_broken_image(self):
     "We have an original file, but can't make a smaller version."
     photo = PhotoFactory()
     generator = Mock(side_effect=Exception('Error'))
     # A minimal version of Medial.IMAGE_SIZES for our test:
     image_sizes = {'small': {'generator': generator,},}
     with patch.dict('ditto.twitter.models.Media.IMAGE_SIZES', image_sizes):
         self.assertEqual(photo.small_url,
                          '/static/img/original_error.jpg')
 def test_size_urls(self):
     url = 'http://www.example.org/image.jpg'
     photo = PhotoFactory(image_url=url)
     self.assertEqual(photo.large_url, photo.image_file.url)
     self.assertRegexpMatches(photo.medium_url,
         'CACHE/images/twitter/media/mp/le/example.[^\.]+\.jpg')
     self.assertRegexpMatches(photo.small_url,
         'CACHE/images/twitter/media/mp/le/example.[^\.]+\.jpg')
     self.assertRegexpMatches(photo.thumb_url,
         'CACHE/images/twitter/media/mp/le/example.[^\.]+\.jpg')
     self.assertRegexpMatches(photo.thumbnail_url,
         'CACHE/images/twitter/media/mp/le/example.[^\.]+\.jpg')
    def setUp(self):
        self.fetched_image = PhotoFactory(twitter_id=99999999,
                                          image_file='downloaded.jpg')
        self.image = PhotoFactory(
            twitter_id=88888888,
            image_file='',
            image_url='https://pbs.twimg.com/media/abcdefghijklmno.png')

        self.animated_gif = AnimatedGifFactory(
            twitter_id=77777777,
            image_url=
            'https://pbs.twimg.com/tweet_video_thumb/1234567890abcde.png',
            mp4_url='https://pbs.twimg.com/tweet_video/abcde1234567890.mp4',
            image_file='',
            mp4_file='')

        self.video = VideoFactory(
            twitter_id=66666666,
            image_url=
            'https://pbs.twimg.com/ext_tw_video_thumb/740282905369444352/pu/img/zyxwvutsrqponml.jpg',
            image_file='',
            mp4_file='')
Exemple #10
0
 def test_image_url_when_original_missing(self):
     "If we have no original file, we should use the 'missing' image."
     photo = PhotoFactory(image_file='')
     self.assertEqual(photo.small_url, '/static/img/original_missing.jpg')
Exemple #11
0
 def test_video_url(self):
     photo = PhotoFactory()
     self.assertEqual('', photo.video_url)
Exemple #12
0
 def test_thumnail_dimensions(self):
     "Thumbnail dimensions should always be 150px."
     photo = PhotoFactory(thumb_w=100, thumb_h=100)
     self.assertEqual(150, photo.thumbnail_w)
     self.assertEqual(150, photo.thumbnail_h)
Exemple #13
0
 def test_unique_twitter_id(self):
     "Ensures twitter_id is unique"
     photo_1 = PhotoFactory(twitter_id=123)
     with self.assertRaises(IntegrityError):
         photo_2 = PhotoFactory(twitter_id=123)
Exemple #14
0
 def test_media_type(self):
     photo = PhotoFactory()
     self.assertEqual(photo.media_type, 'photo')
Exemple #15
0
 def test_str(self):
     photo = PhotoFactory()
     self.assertEqual(photo.__str__(), 'Photo %d' % photo.id)
 def test_str(self):
     photo = PhotoFactory()
     self.assertEqual(photo.__str__(), 'Photo %d' % photo.id)