# 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
#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class GravatarTests(unittest.TestCase):

    def assertURLEqual(self, url1, url2):
        parts1 = urlparse.urlparse(url1)
        parts2 = urlparse.urlparse(url2)
        self.assertEqual(parts1.scheme, parts2.scheme)
        self.assertEqual(parts1.hostname, parts2.hostname)
        self.assertEqual(parts1.netloc, parts2.netloc)
        self.assertEqual(parts1.params, parts2.params)
        self.assertEqual(parts1.path, parts2.path)
        self.assertEqual(parts1.port, parts2.port)
        self.assertEqual(urlparse.parse_qs(parts1.query),

# 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

#
# Yith Library Server is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.





class GravatarTests(unittest.TestCase):

    def assertURLEqual(self, url1, url2):
        parts1 = urlparse.urlparse(url1)
        parts2 = urlparse.urlparse(url2)
        self.assertEqual(parts1.scheme, parts2.scheme)
        self.assertEqual(parts1.hostname, parts2.hostname)
        self.assertEqual(parts1.netloc, parts2.netloc)
        self.assertEqual(parts1.params, parts2.params)
        self.assertEqual(parts1.path, parts2.path)
        self.assertEqual(parts1.port, parts2.port)
        self.assertEqual(urlparse.parse_qs(parts1.query),

                         urlparse.parse_qs(parts2.query))