class TwitterApiTests(TestCase): def setUp(self): self.team = Team.objects.create( name='Kansas', mascot='Jayhawks', slug='kansas-jayhawks' ) def test_is_twitter_api_result_caching(self): self.twitter_api = TwitterApi() self.team.get_tweets() params = {'q': self.team.name + ' ' + self.team.mascot, 'count': 15, 'result_type': 'popular' } cache_key = u'%s' % str(params) cache_key = cache_key.replace(' ','') tweets = self.twitter_api._get_tweets(params) self.assertEqual(cache.get(cache_key), tweets) def test_regex_for_web_links(self): tweet = "A closer look at Duke's first national ranking since Dec. 6, 1994. One writer had the Blue Devils as high as No. 21 https://t.co/1VJegEg3CY" tweet = re.sub(r'((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;\'">\:\s\<\>\)\]\!])', r'<a href="\1">\1</a>', tweet) self.assertEqual(tweet, "A closer look at Duke's first national ranking since Dec. 6, 1994. One writer had the Blue Devils as high as No. 21 <a href=\"https://t.co/1VJegEg3CY\">https://t.co/1VJegEg3CY</a>")