Пример #1
0
def get_profile_url(obj):
    """ returns profile url of user """
    if not obj.user:
        return get_gravatar_img(obj.email)
    profile = get_profile_instance(obj.user)
    if profile:
        return profile.get_absolute_url()
    return get_gravatar_img(obj.email)
Пример #2
0
def get_img_path(obj):
    """ returns url of profile image of a user """
    profile = get_profile_instance(obj.user)
    if not profile:
        return get_gravatar_img(obj.email)
    for field in profile.__class__._meta.get_fields():
        if hasattr(field, 'upload_to'):
            return field.value_from_object(profile).url
    return get_gravatar_img(obj.email)
Пример #3
0
    def test_get_gravatar_img(self):
        # email is not provided
        self.assertEqual(get_gravatar_img(''), '/static/img/default.png')

        # email is provided
        self.assertTrue(get_gravatar_img('test').startswith('https://www.gravatar.com/avatar/'))

        # gravatar is disabled
        patch.object(settings, 'COMMENT_USE_GRAVATAR', True).start()
        self.assertEqual(get_gravatar_img(''), '/static/img/default.png')
Пример #4
0
    def test_get_gravatar_img(self):
        with patch.object(settings, 'COMMENT_USE_GRAVATAR', True):
            # email is not provided
            default_profile_pic_loc = settings.COMMENT_DEFAULT_PROFILE_PIC_LOC
            self.assertEqual(get_gravatar_img(''), default_profile_pic_loc)

            # email is provided
            self.assertTrue(get_gravatar_img('test').startswith('https://www.gravatar.com/avatar/'))

        # gravatar is disabled
        with patch.object(settings, 'COMMENT_USE_GRAVATAR', False):
            self.assertEqual(get_gravatar_img(''), default_profile_pic_loc)
Пример #5
0
 def test_disabling(self):
     self.assertEqual(get_gravatar_img(''),
                      settings.COMMENT_DEFAULT_PROFILE_PIC_LOC)
Пример #6
0
 def test_with_email(self):
     self.assertTrue(
         get_gravatar_img('test').startswith(
             'https://www.gravatar.com/avatar/'))
Пример #7
0
 def test_without_email(self):
     self.assertEqual(get_gravatar_img(''),
                      settings.COMMENT_DEFAULT_PROFILE_PIC_LOC)