Exemple #1
0
    def test_cached_avatar(self):
        """Test cached avatar."""
        rep = UserFactory.create(groups=['Rep'])
        UserAvatarFactory.create(user=rep)

        # Check avatar db entry creation.
        ua = rep.useravatar
        self.assertNotEqual(ua.avatar_url, u'', 'Avatar is empty.')

        # Check update.
        old_date = timezone.datetime(year=1970, day=1, month=1,
                                     tzinfo=timezone.utc)
        ua.last_update = old_date
        ua.save()
        get_avatar_url(rep)
        self.assertGreater(ua.last_update, old_date, 'Avatar was not updated.')

        # Check caching.
        last_update = ua.last_update
        get_avatar_url(rep)

        get_avatar_url(rep)
        self.assertEqual(ua.last_update, last_update,
                         ('Avatar was updated when cached value '
                          'should have been used.'))
Exemple #2
0
    def test_cached_avatar(self):
        """Test cached avatar."""
        user = User.objects.get(email="*****@*****.**")

        # Check avatar db entry creation.
        ua = user.useravatar
        self.assertNotEqual(ua.avatar_url, u"", "Avatar is empty.")

        # Check update.
        old_date = timezone.datetime(year=1970, day=1, month=1, tzinfo=timezone.utc)
        ua.last_update = old_date
        ua.save()
        get_avatar_url(user)
        self.assertGreater(ua.last_update, old_date, "Avatar was not updated.")

        # Check caching.
        last_update = ua.last_update
        get_avatar_url(user)

        get_avatar_url(user)
        self.assertEqual(
            ua.last_update, last_update, ("Avatar was updated when cached value " "should have been used.")
        )
Exemple #3
0
    def test_cached_avatar(self):
        """Test cached avatar."""
        user = User.objects.get(email='*****@*****.**')

        # Check avatar db entry creation.
        ua = user.useravatar
        self.assertNotEqual(ua.avatar_url, u'', 'Avatar is empty.')

        # Check update.
        old_date = timezone.datetime(year=1970, day=1, month=1,
                                     tzinfo=timezone.utc)
        ua.last_update = old_date
        ua.save()
        get_avatar_url(user)
        self.assertGreater(ua.last_update, old_date, 'Avatar was not updated.')

        # Check caching.
        last_update = ua.last_update
        get_avatar_url(user)

        get_avatar_url(user)
        self.assertEqual(ua.last_update, last_update,
                         ('Avatar was updated when cached value '
                          'should have been used.'))
Exemple #4
0
 def dehydrate_avatar_url(self, bundle):
     """Calculate and return full avatar of Rep."""
     return get_avatar_url(bundle.obj.user, -1)
Exemple #5
0
 def dehydrate_avatar_url(self, bundle):
     """Calculate and return full avatar of Rep."""
     return get_avatar_url(bundle.obj.user, -1)