# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/user/gravatar.py
# class Gravatar(object):
# 
#     def __init__(self, request, default_image_url):
#         self.request = request
#         self.default_image_url = default_image_url
# 
#     def get_email_hash(self, email):
#         return hashlib.md5(email.lower().encode('utf-8')).hexdigest()
# 
#     def get_image_url(self, size=32):
#         default_image_url = self.default_image_url
# 
#         email = self.get_email()
#         if not email:
#             return default_image_url
# 
#         email_hash = self.get_email_hash(email)
#         parameters = {
#             'd': default_image_url,
#             's': size,
#             }
#         gravatar_url = 'https://www.gravatar.com/avatar/%s?%s' % (
#             email_hash, url_encode(parameters))
# 
#         return gravatar_url
# 
#     def has_avatar(self):
#         return self.get_email() is not None
# 
#     def get_email(self):
#         user = self.request.user
#         if user is None:
#             return None
# 
#         email = user.get('email', '')
#         if not email:
#             return None
# 
#         return email


import unittest
from pyramid.testing import DummyRequest
from yithlibraryserver.compat import urlparse
from yithlibraryserver.user.gravatar import Gravatar
        self.assertEqual(gravatar.get_email(), 'john@example.com')

    def test_has_avatar(self):
        request = DummyRequest()
        request.user = None
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertFalse(gravatar.has_avatar())

        request = DummyRequest()
        request.user = {'email': 'john@example.com'}
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertTrue(gravatar.has_avatar())

    def test_email_hash(self):
        request = DummyRequest()
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertEqual(gravatar.get_email_hash('john@example.com'),
                         'd4c74594d841139328695756648b6bd6')
        self.assertEqual(gravatar.get_email_hash('JOHN@EXAMPLE.COM'),
                         'd4c74594d841139328695756648b6bd6')

    def test_get_image_url(self):
        request = DummyRequest()
        request.user = None
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertEqual(gravatar.get_image_url(),
                         'http://localhost/default_gravatar.png')

        request = DummyRequest()
        request.user = {}

# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/user/gravatar.py
# class Gravatar(object):
# 
#     def __init__(self, request, default_image_url):
#         self.request = request
#         self.default_image_url = default_image_url
# 
#     def get_email_hash(self, email):
#         return hashlib.md5(email.lower().encode('utf-8')).hexdigest()
# 
#     def get_image_url(self, size=32):
#         default_image_url = self.default_image_url
# 
#         email = self.get_email()
#         if not email:
#             return default_image_url
# 
#         email_hash = self.get_email_hash(email)
#         parameters = {
#             'd': default_image_url,
#             's': size,
#             }
#         gravatar_url = 'https://www.gravatar.com/avatar/%s?%s' % (
#             email_hash, url_encode(parameters))
# 
#         return gravatar_url
# 
#     def has_avatar(self):
#         return self.get_email() is not None
# 
#     def get_email(self):
#         user = self.request.user
#         if user is None:
#             return None
# 
#         email = user.get('email', '')
#         if not email:
#             return None
# 
#         return email


# Path: yithlibraryserver/user/tests/test_gravatar.py
import unittest
from pyramid.testing import DummyRequest
from yithlibraryserver.compat import urlparse
from yithlibraryserver.user.gravatar import Gravatar

        self.assertEqual(gravatar.get_email(), 'john@example.com')

    def test_has_avatar(self):
        request = DummyRequest()
        request.user = None
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertFalse(gravatar.has_avatar())

        request = DummyRequest()
        request.user = {'email': 'john@example.com'}
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertTrue(gravatar.has_avatar())

    def test_email_hash(self):
        request = DummyRequest()
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertEqual(gravatar.get_email_hash('john@example.com'),
                         'd4c74594d841139328695756648b6bd6')
        self.assertEqual(gravatar.get_email_hash('JOHN@EXAMPLE.COM'),
                         'd4c74594d841139328695756648b6bd6')

    def test_get_image_url(self):
        request = DummyRequest()
        request.user = None
        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')
        self.assertEqual(gravatar.get_image_url(),
                         'http://localhost/default_gravatar.png')

        request = DummyRequest()
        request.user = {}

        gravatar = Gravatar(request, 'http://localhost/default_gravatar.png')