Beispiel #1
0
 def test_get_gravatar_url_for_email_uppercase(self):
     """Testing get_gravatar_url_for_email with uppercase characters"""
     self.assertEqual(get_gravatar_url_for_email(email='*****@*****.**'),
                      get_gravatar_url_for_email(email='*****@*****.**'))
     self.assertEqual(
         get_gravatar_url_for_email(email='*****@*****.**'),
         '%s%s' % (self._URL_BASE, md5(b'*****@*****.**').hexdigest()))
Beispiel #2
0
    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))
Beispiel #3
0
    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(email=self.user.email, size=48))
        self.assertEqual(
            urls['2x'],
            get_gravatar_url_for_email(email=self.user.email, size=96))
Beispiel #4
0
    def test_get_gravatar_url_for_email_unicode(self):
        """Testing get_gravatar_url_for_email with unicode characters"""
        raw_email = 'こんにちは@example.com'
        encoded_email = raw_email.encode('utf-8')

        self.assertEqual(get_gravatar_url_for_email(email=raw_email),
                         get_gravatar_url_for_email(email=encoded_email))
        self.assertEqual(
            get_gravatar_url_for_email(email=raw_email),
            '%s%s' % (self._URL_BASE, md5(encoded_email).hexdigest()))
Beispiel #5
0
 def test_get_gravatar_url_for_unicode(self):
     """Testing get_gravatar_url with unicode characters"""
     raw_email = 'こんにちは@example.com'
     encoded_email = raw_email.encode('utf-8')
     user = User.objects.create_user(username='******', email=raw_email)
     self.assertEqual(get_gravatar_url(user=user),
                      get_gravatar_url_for_email(email=encoded_email))
Beispiel #6
0
def gravatar_url(email, size=None):
    """Return a Gravatar URL for an e-mail address.

    This is also influenced by the following Django settings:

    ``GRAVATAR_SIZE``:
        The default size for Gravatars.

    ``GRAVATAR_RATING``:
        The maximum allowed rating (one of ``'g'``, ``'pg'``, ``'r'``, or
        ``'x'``).

    ``GRAVATAR_DEFAULT``:
        The default image to show if the user hasn't specified a Gravatar (one
        of ``identicon``, ``monsterid``, or ``wavatar``).

    See https://gravatar.com for more information.

    Args:
        email (unicode):
            The e-mail address.

        size (int):
            An optional height and width of the image (in pixels). This will
            default to 80 if not specified.

    Returns:
        django.utils.safestring.SafeText:
        HTML for rendering the Gravatar.
    """
    return get_gravatar_url_for_email(email=email, size=size)
Beispiel #7
0
def gravatar_url(email, size=None):
    """Return a Gravatar URL for an e-mail address.

    This is also influenced by the following Django settings:

    ``GRAVATAR_SIZE``:
        The default size for Gravatars.

    ``GRAVATAR_RATING``:
        The maximum allowed rating (one of ``'g'``, ``'pg'``, ``'r'``, or
        ``'x'``).

    ``GRAVATAR_DEFAULT``:
        The default image to show if the user hasn't specified a Gravatar (one
        of ``identicon``, ``monsterid``, or ``wavatar``).

    See https://gravatar.com for more information.

    Args:
        email (unicode):
            The e-mail address.

        size (int):
            An optional height and width of the image (in pixels). This will
            default to 80 if not specified.

    Returns:
        django.utils.safestring.SafeText:
        HTML for rendering the Gravatar.
    """
    return get_gravatar_url_for_email(email=email, size=size)
Beispiel #8
0
    def test_get_gravatar_url_for_email_query_order(self):
        """Testing get_gravatar_url_for_email query string ordering"""
        email = '*****@*****.**'

        with self.settings(GRAVATAR_RATING='G', GRAVATAR_DEFAULT='my-default'):
            self.assertEqual(
                get_gravatar_url_for_email(email='*****@*****.**', size=128),
                '%s%s?s=128&r=G&d=my-default' %
                (self._URL_BASE, md5(email.encode('utf-8')).hexdigest()))
Beispiel #9
0
def gravatar_url(context, email, size=None):
    """
    Outputs the URL for a gravatar for the given email address.

    This can take an optional size of the image (defaults to 80 if not
    specified).

    This is also influenced by the following settings:

        GRAVATAR_SIZE    - Default size for gravatars
        GRAVATAR_RATING  - Maximum allowed rating (g, pg, r, x)
        GRAVATAR_DEFAULT - Default image set to show if the user hasn't
                           specified a gravatar (identicon, monsterid, wavatar)

    See http://www.gravatar.com/ for more information.
    """
    return get_gravatar_url_for_email(context['request'], email, size)
Beispiel #10
0
def gravatar_url(context, email, size=None):
    """
    Outputs the URL for a gravatar for the given email address.

    This can take an optional size of the image (defaults to 80 if not
    specified).

    This is also influenced by the following settings:

        GRAVATAR_SIZE    - Default size for gravatars
        GRAVATAR_RATING  - Maximum allowed rating (g, pg, r, x)
        GRAVATAR_DEFAULT - Default image set to show if the user hasn't
                           specified a gravatar (identicon, monsterid, wavatar)

    See http://www.gravatar.com/ for more information.
    """
    return get_gravatar_url_for_email(context['request'], email, size)
Beispiel #11
0
    def get_avatar_urls_uncached(self, user, size):
        """Return the Gravatar URLs for the requested user.

        Args:
            user (django.contrib.auth.models.User):
                The user whose avatar URLs are to be fetched.

            size (int):
                The size (in pixels) the avatar is to be rendered at.

        Returns
            dict:
            A dictionary containing the URLs of the user's avatars at normal-
            and high-DPI.
        """
        return {
            '%dx' % resolution: mark_safe(get_gravatar_url_for_email(
                email=user.email, size=(size * resolution)))
            for resolution in (1, 2, 3)
        }
Beispiel #12
0
    def get_avatar_urls_uncached(self, user, size):
        """Return the Gravatar URLs for the requested user.

        Args:
            user (django.contrib.auth.models.User):
                The user whose avatar URLs are to be fetched.

            size (int):
                The size (in pixels) the avatar is to be rendered at.

        Returns
            dict:
            A dictionary containing the URLs of the user's avatars at normal-
            and high-DPI.
        """
        return {
            '%dx' % resolution: mark_safe(
                get_gravatar_url_for_email(email=user.email,
                                           size=(size * resolution)))
            for resolution in (1, 2, 3)
        }
Beispiel #13
0
def gravatar_url(context, email, size=None):
    """
    Outputs the URL for a gravatar for the given email address.

    This can take an optional size of the image (defaults to 80 if not
    specified).

    This is also influenced by the following settings:

    ``GRAVATAR_SIZE``:
        Default size for gravatars.

    ``GRAVATAR_RATING``:
        Maximum allowed rating (``g``, ``pg``, ``r``, ``x``)

    ``GRAVATAR_DEFAULT``:
        Default image set to show if the user hasn't specified a gravatar
        (``identicon``, ``monsterid``, ``wavatar``)

    See http://www.gravatar.com/ for more information.
    """
    return get_gravatar_url_for_email(context['request'], email, size)
Beispiel #14
0
 def test_get_gravatar_url_whitespace(self):
     """Testing get_gravatar_url with whitespace characters"""
     user = User.objects.create_user(username='******',
                                     email=' [email protected] ')
     self.assertEqual(get_gravatar_url(user=user),
                      get_gravatar_url_for_email(email='*****@*****.**'))
Beispiel #15
0
 def test_get_gravatar_url_uppercase(self):
     """Testing get_gravatar_url with uppercase characters"""
     user = User.objects.create_user(username='******',
                                     email='*****@*****.**')
     self.assertEqual(get_gravatar_url(user=user),
                      get_gravatar_url_for_email(email='*****@*****.**'))
Beispiel #16
0
 def test_get_gravatar_url_for_email_whitespace(self):
     """Testing get_gravatar_url_for_email with whitespace characters"""
     self.assertEqual(get_gravatar_url_for_email(email=' [email protected] '),
                      get_gravatar_url_for_email(email='*****@*****.**'))