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') self.assertEqual(gravatar.get_image_url(), 'http://localhost/default_gravatar.png') request = DummyRequest() request.user = {'email': ''} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_image_url(), 'http://localhost/default_gravatar.png') request = DummyRequest() request.user = {'email': '*****@*****.**'} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual( gravatar.get_image_url(), 'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=32&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png') gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual( gravatar.get_image_url(100), 'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=100&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png')
def test_email_hash(self): request = DummyRequest() gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email_hash('*****@*****.**'), 'd4c74594d841139328695756648b6bd6') self.assertEqual(gravatar.get_email_hash('*****@*****.**'), 'd4c74594d841139328695756648b6bd6')
def test_get_image_url_with_size(self): request = DummyRequest() request.user = User(email='*****@*****.**') gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertURLEqual( gravatar.get_image_url(100), 'https://www.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=100&d=http%3A%2F%2Flocalhost%2Fdefault_gravatar.png')
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': '*****@*****.**'} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertTrue(gravatar.has_avatar())
def test_get_email(self): request = DummyRequest() request.user = None gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), None) request = DummyRequest() request.user = {} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), None) request = DummyRequest() request.user = {'email': ''} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), None) request = DummyRequest() request.user = {'email': '*****@*****.**'} gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), '*****@*****.**')
def test_get_image_url_empty_email(self): request = DummyRequest() request.user = User(email='') gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertURLEqual(gravatar.get_image_url(), 'http://localhost/default_gravatar.png')
def test_get_image_url_no_user(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')
def test_has_avatar_valid_user(self): request = DummyRequest() request.user = User(email='*****@*****.**') gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertTrue(gravatar.has_avatar())
def test_has_avatar_no_user(self): request = DummyRequest() request.user = None gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertFalse(gravatar.has_avatar())
def test_get_email_valid_email(self): request = DummyRequest() request.user = User(email='*****@*****.**') gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), '*****@*****.**')
def test_get_email_default_user(self): request = DummyRequest() request.user = User() gravatar = Gravatar(request, 'http://localhost/default_gravatar.png') self.assertEqual(gravatar.get_email(), None)