Example #1
0
    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)
Example #2
0
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>")
    ('PAC 12', 'PAC 12'),
    ('SEC', 'SEC'),
    ('Big 10', 'Big 10'),
    ('Big East', 'Big East'),
    ('Mountain West', 'Mountain West'),
    ('Conference USA', 'Conference USA'),
)

SEASONS = (
    ('2015-16', '2015-16'),
    ('2014-15', '2014-15'),
    ('2013-14', '2013-14'),
)

espn_api = EspnApi()
twitter_api = TwitterApi()
kenpom_api = KenpomApi()

class Team(models.Model):
    name = models.CharField(max_length=255)
    mascot = models.CharField(max_length=255)
    nickname = models.CharField(max_length=255, blank=True)
    slug = models.SlugField(unique=True, max_length=255)
    conference = models.CharField(blank=True,max_length=255,choices=CONFERENCES)
    home_arena = models.CharField(max_length=512, blank=True)
    _espn_api_team_details = None
    kenpom_stats = None
    news = None
    game_recaps = None
    videos = None
    podcasts = None