示例#1
0
class GravatarServiceTests(SpyAgency, TestCase):
    """Tests for djblets.avatars.services.gravatar."""

    def setUp(self):
        super(GravatarServiceTests, self).setUp()

        self.service = GravatarService()
        self.request = HttpRequest()
        self.user = User(username='******',
                         email='*****@*****.**',
                         first_name='User',
                         last_name='Name')

    def test_urls(self):
        """Testing GravatarService.get_avatar_urls"""
        urls = self.service.get_avatar_urls(self.request, self.user, 48)

        self.assertEqual(
            urls['1x'],
            get_gravatar_url_for_email(self.request, self.user.email, 48))
        self.assertEqual(
            urls['2x'],
            get_gravatar_url_for_email(self.request, self.user.email, 96))

    def test_render_safely(self):
        """Testing GravatarService.render renders to HTML safely"""
        with self.settings(GRAVATAR_RATING='G'):
            urls = self.service.get_avatar_urls(self.request, self.user, 48)

        self.assertIn('&', urls['1x'])
        self.assertNotIn('&', urls['1x'])
        self.assertIn('&', urls['2x'])
        self.assertNotIn('&', urls['2x'])
示例#2
0
    def setUp(self):
        super(GravatarServiceTests, self).setUp()

        self.service = GravatarService()
        self.request = HttpRequest()
        self.user = User(username='******',
                         email='*****@*****.**',
                         first_name='User',
                         last_name='Name')