def test_get_retweeted_tweet_caches(self, get_method):
     "Should only fetch retweeted Tweet from DB once."
     retweeted_tweet = TweetFactory(text='Retweeted tweet!', twitter_id=123)
     tweet = TweetFactory(retweeted_status_id=123)
     tweet.get_retweeted_tweet()
     tweet.get_retweeted_tweet()
     self.assertEqual(get_method.call_count, 1)
    def setUp(self):
        self.user_1 = UserFactory(screen_name='terry')
        self.user_2 = UserFactory(screen_name='bob')
        self.user_3 = UserFactory(screen_name='thelma', is_private=True)
        self.account_1 = AccountFactory(user=self.user_1)
        account_2 = AccountFactory(user=self.user_2)
        account_3 = AccountFactory(user=self.user_3) # private

        # Public tweets in 2015 and 2016:
        tweets2015 = TweetFactory.create_batch(3,
                            post_time=datetime_from_str('2015-01-01 12:00:00'))
        tweets2016 = TweetFactory.create_batch(2,
                            post_time=datetime_from_str('2016-01-01 12:00:00'))
        # One private tweet in 2015:
        private_tweet = TweetFactory(
                            post_time=datetime_from_str('2015-01-01 12:00:00'))
        private_tweet.user.is_private = True
        private_tweet.user.save()

        self.account_1.user.favorites.add(private_tweet)
        self.account_1.user.favorites.add(tweets2015[0])
        self.account_1.user.favorites.add(tweets2015[1])
        self.account_1.user.favorites.add(tweets2015[2])
        self.account_1.user.favorites.add(tweets2016[0])
        self.account_1.user.favorites.add(tweets2016[1])

        account_2.user.favorites.add(tweets2015[1])
        account_2.user.favorites.add(tweets2016[1])
        account_3.user.favorites.add(tweets2015[1]) # private user favoriting
    def test_tweets_years(self):
        "Should include all intermediate years."
        user = TwitterUserFactory(screen_name='philgyford', is_private=False)
        TwitterAccountFactory(user=user)
        TweetFactory(user=user,
                     post_time=make_datetime('2014-01-01 12:00:00'))
        TweetFactory.create_batch(3,
                                user=user,
                                post_time=make_datetime('2016-01-01 12:00:00'))
        TweetFactory(user=user,
                     post_time=make_datetime('2018-01-01 12:00:00'))
        # From a user without an Account; should be ignored:
        TweetFactory(post_time=make_datetime('2018-01-01 12:00:00'))

        result = TwitterGenerator(
                            screen_name='philgyford').get_tweets_per_year()

        self.assertIn('data', result)
        self.assertEqual(result['data'], [
            {'label': '2014', 'value': 1},
            {'label': '2015', 'value': 0},
            {'label': '2016', 'value': 3},
            {'label': '2017', 'value': 0},
            {'label': '2018', 'value': 1},
        ])
 def test_default_manager_recent(self):
     "The default manager includes tweets from public AND private users"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweets = TweetFactory.create_batch(2, user=public_user)
     private_tweet = TweetFactory(user=private_user)
     self.assertEqual(len(Tweet.objects.all()), 3)
 def test_in_reply_to_url(self):
     tweet_1 = TweetFactory(in_reply_to_screen_name='bob',
                             in_reply_to_status_id=1234567)
     self.assertEqual(tweet_1.in_reply_to_url,
                     'https://twitter.com/bob/status/1234567')
     tweet_2 = TweetFactory(in_reply_to_screen_name='')
     self.assertEqual(tweet_2.in_reply_to_url, '')
    def setUp(self):
        self.user_1 = UserFactory(screen_name='terry')
        self.user_2 = UserFactory(screen_name='bob')
        self.user_3 = UserFactory(screen_name='thelma', is_private=True)
        self.account_1 = AccountFactory(user=self.user_1)
        account_2 = AccountFactory(user=self.user_2)
        account_3 = AccountFactory(user=self.user_3)  # private

        # Public tweets in 2015 and 2016:
        tweets2015 = TweetFactory.create_batch(
            3, post_time=datetime_from_str('2015-01-01 12:00:00'))
        tweets2016 = TweetFactory.create_batch(
            2, post_time=datetime_from_str('2016-01-01 12:00:00'))
        # One private tweet in 2015:
        private_tweet = TweetFactory(
            post_time=datetime_from_str('2015-01-01 12:00:00'))
        private_tweet.user.is_private = True
        private_tweet.user.save()

        self.account_1.user.favorites.add(private_tweet)
        self.account_1.user.favorites.add(tweets2015[0])
        self.account_1.user.favorites.add(tweets2015[1])
        self.account_1.user.favorites.add(tweets2015[2])
        self.account_1.user.favorites.add(tweets2016[0])
        self.account_1.user.favorites.add(tweets2016[1])

        account_2.user.favorites.add(tweets2015[1])
        account_2.user.favorites.add(tweets2016[1])
        account_3.user.favorites.add(tweets2015[1])  # private user favoriting
 def test_get_retweeted_tweet_caches(self, get_method):
     "Should only fetch retweeted Tweet from DB once."
     retweeted_tweet = TweetFactory(text='Retweeted tweet!', twitter_id=123)
     tweet = TweetFactory(retweeted_status_id=123)
     tweet.get_retweeted_tweet()
     tweet.get_retweeted_tweet()
     self.assertEqual(get_method.call_count, 1)
 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_ordering(self):
     """Multiple tweets are sorted by post_time descending"""
     time_now = datetime.datetime.utcnow().replace(tzinfo=pytz.utc)
     tweet_1 = TweetFactory(
                     post_time=time_now - datetime.timedelta(minutes=1))
     tweet_2 = TweetFactory(post_time=time_now)
     tweets = Tweet.objects.all()
     self.assertEqual(tweets[0].pk, tweet_2.pk)
Exemple #10
0
 def test_makes_text_html(self, htmlify_method):
     "When save() is called, text_html should be created from the raw JSON"
     htmlify_method.return_value = 'my test text'
     tweet = TweetFactory()
     tweet.raw = '{"text":"my test text"}'
     tweet.save()
     htmlify_method.assert_called_once_with({'text': 'my test text'})
     self.assertEqual(tweet.text_html, 'my test text')
 def test_makes_text_html(self, htmlify_method):
     "When save() is called, text_html should be created from the raw JSON"
     htmlify_method.return_value = 'my test text'
     tweet = TweetFactory()
     tweet.raw = '{"text":"my test text"}'
     tweet.save()
     htmlify_method.assert_called_once_with({'text': 'my test text'})
     self.assertEqual(tweet.text_html, 'my test text')
Exemple #12
0
 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_saves_correct_tweet_data(self, save_tweet):
     """Assert save_tweet is called once per tweet.
     Not actually checking what's passed in."""
     save_tweet.side_effect = [
         TweetFactory(), TweetFactory(),
         TweetFactory()
     ]
     self.add_response(body=self.make_response_body())
     result = FavoriteTweetsFetcher(screen_name='jill').fetch()
     self.assertEqual(save_tweet.call_count, 3)
 def setUp(self):
     user_1 = UserFactory(screen_name='terry')
     user_2 = UserFactory(screen_name='bob', is_private=True)
     user_3 = UserFactory(screen_name='thelma')
     account_1 = AccountFactory(user=user_1)
     account_2 = AccountFactory(user=user_2)
     account_3 = AccountFactory(user=user_3)
     self.tweets_1 = TweetFactory.create_batch(2, user=user_1)
     self.tweets_2 = TweetFactory.create_batch(3, user=user_2)
     self.tweets_3 = TweetFactory.create_batch(4, user=user_3)
Exemple #15
0
 def test_public_manager(self):
     "The public manager ONLY includes tweets from public users"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweets = TweetFactory.create_batch(2, user=public_user)
     private_tweet = TweetFactory(user=private_user)
     tweets = Tweet.public_objects.all()
     self.assertEqual(len(tweets), 2)
     self.assertEqual(tweets[0].pk, public_tweets[1].pk)
     self.assertEqual(tweets[1].pk, public_tweets[0].pk)
 def setUp(self):
     user_1 = UserFactory(screen_name='terry')
     user_2 = UserFactory(screen_name='bob', is_private=True)
     user_3 = UserFactory(screen_name='thelma')
     account_1 = AccountFactory(user=user_1)
     account_2 = AccountFactory(user=user_2)
     account_3 = AccountFactory(user=user_3)
     self.tweets_1 = TweetFactory.create_batch(2, user=user_1)
     self.tweets_2 = TweetFactory.create_batch(3, user=user_2)
     self.tweets_3 = TweetFactory.create_batch(4, user=user_3)
Exemple #17
0
 def test_favorites(self):
     user = UserFactory(screen_name='bill')
     tweet_1 = TweetFactory(text ='Tweet 1')
     tweet_2 = TweetFactory(text ='Tweet 2')
     user.favorites.add(tweet_1)
     user.favorites.add(tweet_2)
     faves = User.objects.get(screen_name='bill').favorites.all()
     self.assertEqual(len(faves), 2)
     self.assertIsInstance(faves[0], Tweet)
     self.assertEqual(faves[0].text, 'Tweet 2')
     self.assertEqual(faves[1].text, 'Tweet 1')
 def test_going_public(self):
     "Makes the user's tweets public if they go public"
     # Start off private:
     user = UserFactory(is_private=True)
     tweet = TweetFactory(user=user)
     self.assertTrue(tweet.is_private)
     # Now change to public:
     user.is_private = False
     # Should change the user's tweets to public:
     user.save()
     tweet.refresh_from_db()
     self.assertFalse(tweet.is_private)
Exemple #19
0
 def test_going_public(self):
     "Makes the user's tweets public if they go public"
     # Start off private:
     user = UserFactory(is_private=True)
     tweet = TweetFactory(user=user)
     self.assertTrue(tweet.is_private)
     # Now change to public:
     user.is_private = False
     # Should change the user's tweets to public:
     user.save()
     tweet.refresh_from_db()
     self.assertFalse(tweet.is_private)
Exemple #20
0
    def test_public_favorites_tweets_manager(self):
        "Should contain recent PUBLIC tweets favorited the Accounts"
        accounts = AccountFactory.create_batch(2)
        public_user = UserFactory(is_private=False)
        private_user = UserFactory(is_private=True)
        public_tweet = TweetFactory(user=public_user)
        private_tweet = TweetFactory(user=private_user)

        accounts[0].user.favorites.add(private_tweet)
        accounts[0].user.favorites.add(public_tweet)
        accounts[1].user.favorites.add(private_tweet)

        favorites = Tweet.public_favorite_objects.all()
        self.assertEqual(len(favorites), 1)
        self.assertEqual(favorites[0].pk, public_tweet.pk)
    def test_tweets_data(self):
        user = TwitterUserFactory(screen_name='philgyford', is_private=False)
        TwitterAccountFactory(user=user)
        TweetFactory.create_batch(3,
                                user=user,
                                post_time=make_datetime('2018-01-01 12:00:00'))
        # From a user without an Account; should be ignored:
        TweetFactory(post_time=make_datetime('2018-01-01 12:00:00'))

        result = TwitterGenerator(
                            screen_name='philgyford').get_tweets_per_year()

        self.assertIn('data', result)
        self.assertEqual(len(result['data']), 1)
        self.assertEqual(result['data'][0]['label'], '2018')
        self.assertEqual(result['data'][0]['value'], 3)
    def setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)

        self.tweets = TweetFactory.create_batch(6)
        # One of the tweets is private:
        self.tweets[0].user.is_private = True
        self.tweets[0].user.save()

        post_time = datetime.datetime(2015, 3, 18, 12, 0, 0).replace(
                                                            tzinfo=pytz.utc)
        self.tweets[0].post_time = post_time
        self.tweets[0].save()
        self.tweets[1].post_time = post_time + datetime.timedelta(hours=1)
        self.tweets[1].save()
        self.tweets[5].post_time = post_time + datetime.timedelta(hours=2)
        self.tweets[5].save()

        account_1.user.favorites.add(self.tweets[0]) # private tweet
        account_1.user.favorites.add(self.tweets[1])
        account_1.user.favorites.add(self.tweets[2])
        account_1.user.favorites.add(self.tweets[3])
        account_2.user.favorites.add(self.tweets[4])
        account_3.user.favorites.add(self.tweets[5]) # private user favoriting
Exemple #23
0
 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 setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)

        self.tweets = TweetFactory.create_batch(6)
        # One of the tweets is private:
        self.tweets[0].user.is_private = True
        self.tweets[0].user.save()

        post_time = datetime.datetime(2015, 3, 18, 12, 0,
                                      0).replace(tzinfo=pytz.utc)
        self.tweets[0].post_time = post_time
        self.tweets[0].save()
        self.tweets[1].post_time = post_time + datetime.timedelta(hours=1)
        self.tweets[1].save()
        self.tweets[5].post_time = post_time + datetime.timedelta(hours=2)
        self.tweets[5].save()

        account_1.user.favorites.add(self.tweets[0])  # private tweet
        account_1.user.favorites.add(self.tweets[1])
        account_1.user.favorites.add(self.tweets[2])
        account_1.user.favorites.add(self.tweets[3])
        account_2.user.favorites.add(self.tweets[4])
        account_3.user.favorites.add(self.tweets[5])  # private user favoriting
 def test_default_manager_recent(self):
     "The default manager includes tweets from public AND private users"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweets = TweetFactory.create_batch(2, user=public_user)
     private_tweet = TweetFactory(user=private_user)
     self.assertEqual(len(Tweet.objects.all()), 3)
 def test_updates_tweets(self):
     tweets = TweetFactory.create(twitter_id=200, text='Will change')
     self.add_response(body=self.make_response_body(), method='POST')
     result = TweetsFetcher(screen_name='jill').fetch([300, 200, 100])
     self.assertEqual(
         Tweet.objects.get(twitter_id=200).text,
         "@rooreynolds I've read stories of people travelling abroad who were mistaken for military/security because of that kind of thing… careful :)"
     )
 def test_empty_years(self):
     "It should include years for which there are no tweets."
     # Add a tweet in 2018, leaving a gap for 2017:
     TweetFactory(post_time=datetime_from_str('2018-01-01 12:00:00'),
                  user=self.user_1)
     tweets = ditto_twitter.annual_tweet_counts()
     self.assertEqual(len(tweets), 4)
     self.assertEqual(tweets[2]['year'], 2017)
     self.assertEqual(tweets[2]['count'], 0)
    def test_requests_all_tweets(self):
        "If no ids supplied, uses all tweets in the DB"
        tweets = TweetFactory.create_batch(5)
        result = TweetsFetcher(screen_name='jill').fetch()

        ids = Tweet.objects.values_list('twitter_id', flat=True).order_by('fetch_time')

        params = QueryDict(responses.calls[0][0].body)
        self.assertIn('id', params)
        self.assertEqual(','.join(map(str, ids)), params['id'])
    def setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)
        self.tweets_1 = TweetFactory.create_batch(2, user=user_1)
        self.tweets_2 = TweetFactory.create_batch(2, user=user_2)
        self.tweets_3 = TweetFactory.create_batch(2, user=user_3)

        post_time = datetime.datetime(2015, 3, 18, 12, 0,
                                      0).replace(tzinfo=pytz.utc)
        self.tweets_1[0].post_time = post_time
        self.tweets_1[0].save()
        self.tweets_2[1].post_time = post_time + datetime.timedelta(hours=1)
        self.tweets_2[1].save()
        self.tweets_3[0].post_time = post_time + datetime.timedelta(hours=2)
        self.tweets_3[0].save()
    def setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)
        self.tweets_1 = TweetFactory.create_batch(2, user=user_1)
        self.tweets_2 = TweetFactory.create_batch(2, user=user_2)
        self.tweets_3 = TweetFactory.create_batch(2, user=user_3)

        post_time = datetime.datetime(2015, 3, 18, 12, 0, 0).replace(
                                                            tzinfo=pytz.utc)
        self.tweets_1[0].post_time = post_time
        self.tweets_1[0].save()
        self.tweets_2[1].post_time = post_time + datetime.timedelta(hours=1)
        self.tweets_2[1].save()
        self.tweets_3[0].post_time = post_time + datetime.timedelta(hours=2)
        self.tweets_3[0].save()
 def test_public_manager(self):
     "The public manager ONLY includes tweets from public users"
     public_user = UserFactory(is_private=False)
     private_user = UserFactory(is_private=True)
     public_tweets = TweetFactory.create_batch(2, user=public_user)
     private_tweet = TweetFactory(user=private_user)
     tweets = Tweet.public_objects.all()
     self.assertEqual(len(tweets), 2)
     self.assertEqual(tweets[0].pk, public_tweets[1].pk)
     self.assertEqual(tweets[1].pk, public_tweets[0].pk)
 def test_empty_years(self):
     "It should include years for which there are no favorited tweets."
     # Add a favorite tweet in 2018, leaving a gap for 2017:
     tweet2018 = TweetFactory(
         post_time=datetime_from_str('2018-01-01 12:00:00'))
     self.account_1.user.favorites.add(tweet2018)
     tweets = ditto_twitter.annual_favorite_counts()
     self.assertEqual(len(tweets), 4)
     self.assertEqual(tweets[2]['year'], 2017)
     self.assertEqual(tweets[2]['count'], 0)
    def test_requests_all_tweets(self):
        "If no ids supplied, uses all tweets in the DB"
        tweets = TweetFactory.create_batch(5)
        result = TweetsFetcher(screen_name='jill').fetch()

        ids = Tweet.objects.values_list('twitter_id',
                                        flat=True).order_by('fetch_time')

        params = QueryDict(responses.calls[0][0].body)
        self.assertIn('id', params)
        self.assertEqual(','.join(map(str, ids)), params['id'])
 def setUp(self):
     self.user_1 = UserFactory(screen_name='terry')
     self.user_2 = UserFactory(screen_name='bob')
     self.user_3 = UserFactory(screen_name='thelma', is_private=True)
     account_1 = AccountFactory(user=self.user_1)
     account_2 = AccountFactory(user=self.user_2)
     account_3 = AccountFactory(user=self.user_3)
     # Tweets in 2015 and 2016 for user 1:
     TweetFactory.create_batch(3,
                         post_time=datetime_from_str('2015-01-01 12:00:00'),
                         user=self.user_1)
     TweetFactory.create_batch(2,
                         post_time=datetime_from_str('2016-01-01 12:00:00'),
                         user=self.user_1)
     # And one for self.user_2 in 2015:
     TweetFactory(user=self.user_2,
                         post_time=datetime_from_str('2015-01-01 12:00:00'))
     # And one tweet in 2015 for the private user 3.
     tw = TweetFactory(user=self.user_3, is_private=True,
                         post_time=datetime_from_str('2015-01-01 12:00:00'))
 def test_favorites_manager(self):
     "Should contain recent tweets favorited by any account."
     accounts = AccountFactory.create_batch(2)
     tweets = TweetFactory.create_batch(5)
     accounts[0].user.favorites.add(tweets[2])
     accounts[0].user.favorites.add(tweets[4])
     accounts[1].user.favorites.add(tweets[2])
     favorites = Tweet.favorite_objects.all()
     self.assertEqual(len(favorites), 2)
     self.assertEqual(favorites[0].pk, tweets[4].pk)
     self.assertEqual(favorites[1].pk, tweets[2].pk)
Exemple #36
0
 def test_favorites_manager(self):
     "Should contain recent tweets favorited by any account."
     accounts = AccountFactory.create_batch(2)
     tweets = TweetFactory.create_batch(5)
     accounts[0].user.favorites.add(tweets[2])
     accounts[0].user.favorites.add(tweets[4])
     accounts[1].user.favorites.add(tweets[2])
     favorites = Tweet.favorite_objects.all()
     self.assertEqual(len(favorites), 2)
     self.assertEqual(favorites[0].pk, tweets[4].pk)
     self.assertEqual(favorites[1].pk, tweets[2].pk)
Exemple #37
0
class TweetNextPrevTestCase(TestCase):
    def setUp(self):
        dt = datetime.datetime.strptime(
            '2016-04-08 12:00:00',
            '%Y-%m-%d %H:%M:%S').replace(tzinfo=pytz.utc)

        user = UserFactory()
        account = AccountFactory(user=user)
        self.tweet_1 = TweetFactory(user=user, post_time=dt)

        private_user = UserFactory(is_private=True)
        private_account = AccountFactory(user=private_user)
        self.private_tweeet = TweetFactory(user=private_user,
                                           post_time=dt +
                                           datetime.timedelta(days=1))

        # Tweet by a different user:
        user_2 = UserFactory()
        account_2 = AccountFactory(user=user_2)
        self.other_tweet = TweetFactory(user=user_2,
                                        post_time=dt +
                                        datetime.timedelta(days=2))

        self.tweet_2 = TweetFactory(user=user,
                                    post_time=dt + datetime.timedelta(days=3))

    def test_next_public_by_post_time(self):
        self.assertEqual(self.tweet_1.get_next_public_by_post_time(),
                         self.tweet_2)

    def test_next_public_by_post_time_none(self):
        self.assertIsNone(self.tweet_2.get_next_public_by_post_time())

    def test_previous_public_by_post_time(self):
        self.assertEqual(self.tweet_2.get_previous_public_by_post_time(),
                         self.tweet_1)

    def test_previous_public_by_post_time_none(self):
        self.assertIsNone(self.tweet_1.get_previous_public_by_post_time())

    def test_next(self):
        self.assertEqual(self.tweet_1.get_next(), self.tweet_2)

    def test_next_none(self):
        self.assertIsNone(self.tweet_2.get_next())

    def test_previous(self):
        self.assertEqual(self.tweet_2.get_previous(), self.tweet_1)

    def test_previous_none(self):
        self.assertIsNone(self.tweet_1.get_previous())
class TweetNextPrevTestCase(TestCase):

    def setUp(self):
        dt = datetime.datetime.strptime(
                                    '2016-04-08 12:00:00', '%Y-%m-%d %H:%M:%S'
                                ).replace(tzinfo=pytz.utc)

        user = UserFactory()
        account = AccountFactory(user=user)
        self.tweet_1 = TweetFactory(user=user, post_time=dt)

        private_user = UserFactory(is_private=True)
        private_account = AccountFactory(user=private_user)
        self.private_tweeet = TweetFactory(user=private_user,
                                post_time=dt + datetime.timedelta(days=1))

        # Tweet by a different user:
        user_2 = UserFactory()
        account_2 = AccountFactory(user=user_2)
        self.other_tweet = TweetFactory(user=user_2,
                                post_time=dt + datetime.timedelta(days=2))

        self.tweet_2 = TweetFactory(user=user,
                                    post_time=dt + datetime.timedelta(days=3))

    def test_next_public_by_post_time(self):
        self.assertEqual(self.tweet_1.get_next_public_by_post_time(),
                        self.tweet_2)

    def test_next_public_by_post_time_none(self):
        self.assertIsNone(self.tweet_2.get_next_public_by_post_time())

    def test_previous_public_by_post_time(self):
        self.assertEqual(self.tweet_2.get_previous_public_by_post_time(),
                        self.tweet_1)

    def test_previous_public_by_post_time_none(self):
        self.assertIsNone(self.tweet_1.get_previous_public_by_post_time())

    def test_next(self):
        self.assertEqual(self.tweet_1.get_next(),self.tweet_2)

    def test_next_none(self):
        self.assertIsNone(self.tweet_2.get_next())

    def test_previous(self):
        self.assertEqual(self.tweet_2.get_previous(), self.tweet_1)

    def test_previous_none(self):
        self.assertIsNone(self.tweet_1.get_previous())
    def setUp(self):
        dt = datetime.datetime.strptime(
                                    '2016-04-08 12:00:00', '%Y-%m-%d %H:%M:%S'
                                ).replace(tzinfo=pytz.utc)

        user = UserFactory()
        account = AccountFactory(user=user)
        self.tweet_1 = TweetFactory(user=user, post_time=dt)

        private_user = UserFactory(is_private=True)
        private_account = AccountFactory(user=private_user)
        self.private_tweeet = TweetFactory(user=private_user,
                                post_time=dt + datetime.timedelta(days=1))

        # Tweet by a different user:
        user_2 = UserFactory()
        account_2 = AccountFactory(user=user_2)
        self.other_tweet = TweetFactory(user=user_2,
                                post_time=dt + datetime.timedelta(days=2))

        self.tweet_2 = TweetFactory(user=user,
                                    post_time=dt + datetime.timedelta(days=3))
Exemple #40
0
 def test_summary(self):
     "The summary should be created from the description on save."
     tweet = TweetFactory(
         title='Testing. <a href="http://example.org">A link</a> '
         'and more text which goes on a bit so that this goes to more than '
         '255 characters so that we can test it will be truncated '
         'correctly.\nLorem ipsum dolor sit amet, consectetur adipiscing '
         'elit. Etiam odio tortor, maximus ut mauris eget, sollicitudins '
         'odales felis.')
     self.assertEqual(
         tweet.summary, 'Testing. A link '
         'and more text which goes on a bit so that this goes to more than '
         '255 characters so that we can test it will be truncated '
         'correctly. Lorem ipsum dolor sit amet, consectetur adipiscing '
         'elit. Etiam odio tortor, maximus ut mauris eget,…')
    def test_public_favorites_accounts_manager(self):
        "Should only show tweets favorited by public Accounts"
        public_user = UserFactory(is_private=False)
        private_user = UserFactory(is_private=True)
        account_1 = AccountFactory(user=public_user)
        account_2 = AccountFactory(user=private_user)
        tweets = TweetFactory.create_batch(5)
        account_1.user.favorites.add(tweets[0])
        account_1.user.favorites.add(tweets[3])
        account_2.user.favorites.add(tweets[1])
        account_2.user.favorites.add(tweets[3])

        favorites = Tweet.public_favorite_objects.all()
        self.assertEqual(len(favorites), 2)
        self.assertEqual(favorites[0].pk, tweets[3].pk)
        self.assertEqual(favorites[1].pk, tweets[0].pk)
Exemple #42
0
    def test_public_favorites_accounts_manager(self):
        "Should only show tweets favorited by public Accounts"
        public_user = UserFactory(is_private=False)
        private_user = UserFactory(is_private=True)
        account_1 = AccountFactory(user=public_user)
        account_2 = AccountFactory(user=private_user)
        tweets = TweetFactory.create_batch(5)
        account_1.user.favorites.add(tweets[0])
        account_1.user.favorites.add(tweets[3])
        account_2.user.favorites.add(tweets[1])
        account_2.user.favorites.add(tweets[3])

        favorites = Tweet.public_favorite_objects.all()
        self.assertEqual(len(favorites), 2)
        self.assertEqual(favorites[0].pk, tweets[3].pk)
        self.assertEqual(favorites[1].pk, tweets[0].pk)
    def setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)

        tweets = TweetFactory.create_batch(6)
        # One of the tweets is private:
        tweets[0].user.is_private = True
        tweets[0].user.save()

        account_1.user.favorites.add(tweets[0])
        account_1.user.favorites.add(tweets[1])
        account_1.user.favorites.add(tweets[3])
        account_2.user.favorites.add(tweets[5])
        # Private user favoriting public tweets:
        account_3.user.favorites.add(tweets[5])
    def setUp(self):
        user_1 = UserFactory(screen_name='terry')
        user_2 = UserFactory(screen_name='bob')
        user_3 = UserFactory(screen_name='thelma', is_private=True)
        account_1 = AccountFactory(user=user_1)
        account_2 = AccountFactory(user=user_2)
        account_3 = AccountFactory(user=user_3)

        tweets = TweetFactory.create_batch(6)
        # One of the tweets is private:
        tweets[0].user.is_private = True
        tweets[0].user.save()

        account_1.user.favorites.add(tweets[0])
        account_1.user.favorites.add(tweets[1])
        account_1.user.favorites.add(tweets[3])
        account_2.user.favorites.add(tweets[5])
        # Private user favoriting public tweets:
        account_3.user.favorites.add(tweets[5])
Exemple #45
0
    def setUp(self):
        dt = datetime.datetime.strptime(
                                    '2016-04-08 12:00:00', '%Y-%m-%d %H:%M:%S'
                                ).replace(tzinfo=pytz.utc)

        user = UserFactory()
        account = AccountFactory(user=user)
        self.tweet_1 = TweetFactory(user=user, post_time=dt)

        private_user = UserFactory(is_private=True)
        private_account = AccountFactory(user=private_user)
        self.private_tweeet = TweetFactory(user=private_user,
                                post_time=dt + datetime.timedelta(days=1))

        # Tweet by a different user:
        user_2 = UserFactory()
        account_2 = AccountFactory(user=user_2)
        self.other_tweet = TweetFactory(user=user_2,
                                post_time=dt + datetime.timedelta(days=2))

        self.tweet_2 = TweetFactory(user=user,
                                    post_time=dt + datetime.timedelta(days=3))
 def setUp(self):
     self.user_1 = UserFactory(screen_name='terry')
     self.user_2 = UserFactory(screen_name='bob')
     self.user_3 = UserFactory(screen_name='thelma', is_private=True)
     account_1 = AccountFactory(user=self.user_1)
     account_2 = AccountFactory(user=self.user_2)
     account_3 = AccountFactory(user=self.user_3)
     # Tweets in 2015 and 2016 for user 1:
     TweetFactory.create_batch(
         3,
         post_time=datetime_from_str('2015-01-01 12:00:00'),
         user=self.user_1)
     TweetFactory.create_batch(
         2,
         post_time=datetime_from_str('2016-01-01 12:00:00'),
         user=self.user_1)
     # And one for self.user_2 in 2015:
     TweetFactory(user=self.user_2,
                  post_time=datetime_from_str('2015-01-01 12:00:00'))
     # And one tweet in 2015 for the private user 3.
     tw = TweetFactory(user=self.user_3,
                       is_private=True,
                       post_time=datetime_from_str('2015-01-01 12:00:00'))
 def test_updates_tweets(self):
     tweets = TweetFactory.create(twitter_id=200, text='Will change')
     self.add_response(body=self.make_response_body(), method='POST')
     result = TweetsFetcher(screen_name='jill').fetch([300,200,100])
     self.assertEqual(Tweet.objects.get(twitter_id=200).text,
         "@rooreynolds I've read stories of people travelling abroad who were mistaken for military/security because of that kind of thing… careful :)")
Exemple #48
0
 def test_post_year(self):
     "The post_year should be set based on post_time on save."
     tweet = TweetFactory(post_time=datetime_from_str('2015-01-01 12:00:00'))
     self.assertEqual(tweet.post_year, 2015)
Exemple #49
0
 def test_get_retweeted_tweet_none(self):
     tweet = TweetFactory(retweeted_status_id=None)
     self.assertIsNone(tweet.get_retweeted_tweet())
 def test_get_retweeted_tweet_none(self):
     tweet = TweetFactory(retweeted_status_id=None)
     self.assertIsNone(tweet.get_retweeted_tweet())
 def test_get_quoted_tweet(self):
     quoted_tweet = TweetFactory(text='The quote!', twitter_id=123)
     tweet = TweetFactory(quoted_status_id=123)
     self.assertEqual(tweet.get_quoted_tweet().text, 'The quote!')
 def test_get_absolute_url(self):
     tweet = TweetFactory(user=UserFactory(screen_name='bob'),
                         twitter_id=1234567890)
     self.assertEqual(tweet.get_absolute_url(), '/twitter/bob/1234567890/')
 def test_get_retweeted_tweet(self):
     retweeted_tweet = TweetFactory(text='Retweeted tweet!', twitter_id=123)
     tweet = TweetFactory(retweeted_status_id=123)
     self.assertEqual(tweet.get_retweeted_tweet().text, 'Retweeted tweet!')