Beispiel #1
0
 def test_profile_avatar_anonymous(self):
     email_hash = "00000000000000000000000000000000"
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48&d=%s" % (
         email_hash,
         settings.STATIC_URL + settings.DEFAULT_AVATAR,
     )
     eq_(gravatar_url, profile_avatar(AnonymousUser()))
Beispiel #2
0
    def extract_document(cls, obj_id, obj=None):
        """Extracts interesting thing from a Thread and its Posts"""
        if obj is None:
            model = cls.get_model()
            obj = model.objects.select_related('user').get(pk=obj_id)

        if not obj.user.is_active:
            raise UnindexMeBro()

        d = {}
        d['id'] = obj.pk
        d['model'] = cls.get_mapping_type_name()
        d['url'] = obj.get_absolute_url()
        d['indexed_on'] = int(time.time())

        d['username'] = obj.user.username
        d['display_name'] = obj.display_name

        d['iusername'] = obj.user.username.lower()
        d['idisplay_name'] = obj.display_name.lower()

        from kitsune.users.helpers import profile_avatar
        d['avatar'] = profile_avatar(obj.user, size=120)

        d['suggest'] = {
            'input': [
                d['iusername'],
                d['idisplay_name']
            ],
            'output': _(u'{displayname} ({username})').format(
                displayname=d['display_name'], username=d['username']),
            'payload' : {'user_id': d['id'] },
        }

        return d
Beispiel #3
0
 def test_creator_is_object(self):
     serializer = api.QuestionSerializer(instance=self.question)
     eq_(serializer.data['creator'], {
         'username': self.question.creator.username,
         'display_name': Profile.objects.get(user=self.question.creator).display_name,
         'avatar': profile_avatar(self.question.creator),
     })
Beispiel #4
0
def usernames(request):
    """An API to provide auto-complete data for user names."""
    term = request.GET.get('term', '')
    query = request.GET.get('query', '')
    pre = term or query

    if not pre:
        return []
    if not request.user.is_authenticated():
        return []
    with statsd.timer('users.api.usernames.search'):
        profiles = (
            Profile.objects.filter(Q(name__istartswith=pre))
            .values_list('user_id', flat=True))
        users = (
            User.objects.filter(
                Q(username__istartswith=pre) | Q(id__in=profiles))
            .extra(select={'length': 'Length(username)'})
            .order_by('length').select_related('profile'))

        if not waffle.switch_is_active('users-dont-limit-by-login'):
            last_login = datetime.now() - timedelta(weeks=12)
            users = users.filter(last_login__gte=last_login)

        return [{'username': u.username,
                 'display_name': display_name_or_none(u),
                 'avatar': profile_avatar(u, 24)}
                for u in users[:10]]
Beispiel #5
0
def usernames(request):
    """An API to provide auto-complete data for user names."""
    term = request.GET.get('term', '')
    query = request.GET.get('query', '')
    pre = term or query

    if not pre:
        return []
    if not request.user.is_authenticated():
        return []
    with statsd.timer('users.api.usernames.search'):
        profiles = (Profile.objects.filter(
            Q(name__istartswith=pre)).values_list('user_id', flat=True))
        users = (User.objects.filter(
            Q(username__istartswith=pre)
            | Q(id__in=profiles)).extra(select={
                'length': 'Length(username)'
            }).order_by('length').select_related('profile'))

        if not waffle.switch_is_active('users-dont-limit-by-login'):
            last_login = datetime.now() - timedelta(weeks=12)
            users = users.filter(last_login__gte=last_login)

        return [{
            'username': u.username,
            'display_name': display_name_or_none(u),
            'avatar': profile_avatar(u, 24)
        } for u in users[:10]]
Beispiel #6
0
    def test_correct_fields(self):
        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        serializer = api.NotificationSerializer(instance=notification)

        eq_(serializer.data['is_read'], False)
        eq_(serializer.data['actor'], {
            'type': 'user',
            'username': followed.user.username,
            'display_name': followed.name,
            'avatar': profile_avatar(followed.user),
        })
        eq_(serializer.data['verb'], 'asked')
        eq_(serializer.data['action_object']['type'], 'question')
        eq_(serializer.data['action_object']['id'], q.id)
        eq_(serializer.data['target'], None)
        # Check that the serialized data is in the correct format. If it is
        # not, this will throw an exception.
        datetime.strptime(serializer.data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')
Beispiel #7
0
    def extract_document(cls, obj_id, obj=None):
        """Extracts interesting thing from a Thread and its Posts"""
        if obj is None:
            model = cls.get_model()
            obj = model.objects.select_related('user').get(pk=obj_id)

        if not obj.user.is_active:
            raise UnindexMeBro()

        d = {}
        d['id'] = obj.pk
        d['model'] = cls.get_mapping_type_name()
        d['url'] = obj.get_absolute_url()
        d['indexed_on'] = int(time.time())

        d['username'] = obj.user.username
        d['display_name'] = obj.display_name

        d['iusername'] = obj.user.username.lower()
        d['idisplay_name'] = obj.display_name.lower()

        from kitsune.users.helpers import profile_avatar
        d['avatar'] = profile_avatar(obj.user, size=120)

        d['suggest'] = {
            'input': [d['iusername'], d['idisplay_name']],
            'output':
            _(u'{displayname} ({username})').format(
                displayname=d['display_name'], username=d['username']),
            'payload': {
                'user_id': d['id']
            },
        }

        return d
Beispiel #8
0
 def test_creator_is_object(self):
     serializer = api.QuestionSerializer(instance=self.question)
     eq_(serializer.data['creator'], {
         'username': self.question.creator.username,
         'display_name': Profile.objects.get(user=self.question.creator).display_name,
         'avatar': profile_avatar(self.question.creator),
     })
Beispiel #9
0
 def test_profile_avatar(self):
     self.u.profile.avatar = 'images/foo.png'
     self.u.profile.save()
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
         email_hash)
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #10
0
    def test_correct_fields(self):
        follower = profile()
        followed = profile()
        q = question(creator=followed.user, save=True)
        # The above might make follows, which this test isn't about. Clear them out.
        Follow.objects.all().delete()
        follow(follower.user, followed.user)

        # Make a new action for the above. This should trigger notifications
        action.send(followed.user, verb='asked', action_object=q)
        act = Action.objects.order_by('-id')[0]
        notification = Notification.objects.get(action=act)

        serializer = api.NotificationSerializer(instance=notification)

        eq_(serializer.data['is_read'], False)
        eq_(
            serializer.data['actor'], {
                'type': 'user',
                'username': followed.user.username,
                'display_name': followed.name,
                'avatar': profile_avatar(followed.user),
            })
        eq_(serializer.data['verb'], 'asked')
        eq_(serializer.data['action_object']['type'], 'question')
        eq_(serializer.data['action_object']['id'], q.id)
        eq_(serializer.data['target'], None)
        # Check that the serialized data is in the correct format. If it is
        # not, this will throw an exception.
        datetime.strptime(serializer.data['timestamp'], '%Y-%m-%dT%H:%M:%SZ')
Beispiel #11
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar="images/foo.png")
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48&d=%s" % (
         email_hash,
         settings.MEDIA_URL + "images/foo.png",
     )
     eq_(gravatar_url, profile_avatar(self.u))
Beispiel #12
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48&d=%s" % (
         email_hash,
         settings.STATIC_URL + settings.DEFAULT_AVATAR,
     )
     eq_(gravatar_url, profile_avatar(self.u))
Beispiel #13
0
 def _names(self, *users):
     return sorted(
         {
             'username': u.username,
             'display_name': Profile.objects.get(user=u).name,
             'avatar': profile_avatar(u),
         }
         for u in users)
Beispiel #14
0
 def _names(self, *users):
     return sorted(
         {
             'username': u.username,
             'display_name': Profile.objects.get(user=u).name,
             'avatar': profile_avatar(u),
         }
         for u in users)
Beispiel #15
0
 def test_profile_avatar_anonymous(self):
     email_hash = '00000000000000000000000000000000'
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
         email_hash, settings.STATIC_URL + settings.DEFAULT_AVATAR)
     eq_(gravatar_url, profile_avatar(AnonymousUser()))
Beispiel #16
0
 def get_avatar_url(self, obj):
     return profile_avatar(obj.user)
Beispiel #17
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     eq_('%simages/foo.png' % settings.MEDIA_URL, profile_avatar(self.u))
Beispiel #18
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR,
         profile_avatar(self.u))
Beispiel #19
0
 def get_avatar_url(self, profile):
     request = self.context.get('request')
     size = request.REQUEST.get('avatar_size', 48) if request else 48
     return profile_avatar(profile.user, size=size)
Beispiel #20
0
 def test_profile_avatar_anonymous(self):
     email_hash = '00000000000000000000000000000000'
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
         email_hash)
     assert profile_avatar(AnonymousUser()).startswith(gravatar_url)
Beispiel #21
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
         email_hash)
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #22
0
 def test_profile_avatar_anonymous(self):
     email_hash = '00000000000000000000000000000000'
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
         email_hash)
     assert profile_avatar(AnonymousUser()).startswith(gravatar_url)
Beispiel #23
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
         email_hash, settings.STATIC_URL + settings.DEFAULT_AVATAR)
     eq_(gravatar_url, profile_avatar(self.u))
Beispiel #24
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     eq_('%simages/foo.png' % settings.MEDIA_URL, profile_avatar(self.u))
Beispiel #25
0
 def test_profile_avatar_anonymous(self):
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR,
         profile_avatar(AnonymousUser()))
Beispiel #26
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR,
         profile_avatar(self.u))
Beispiel #27
0
 def get_avatar_url(self, profile):
     return profile_avatar(profile.user)
Beispiel #28
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48' % (
         email_hash)
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #29
0
 def test_profile_avatar_unicode(self):
     self.u.email = u"rá[email protected]"
     self.u.save()
     gravatar_url = "https://secure.gravatar.com/"
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #30
0
 def test_profile_avatar_unicode(self):
     self.u.email = u'rá[email protected]'
     self.u.save()
     profile(user=self.u)
     gravatar_url = 'https://secure.gravatar.com/'
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #31
0
 def get_avatar_url(self, profile):
     request = self.context.get('request')
     size = request.REQUEST.get('avatar_size', 48) if request else 48
     return profile_avatar(profile.user, size=size)
Beispiel #32
0
 def get_avatar_url(self, profile):
     return profile_avatar(profile.user)
Beispiel #33
0
 def test_profile_avatar(self):
     self.u.profile.avatar = "images/foo.png"
     self.u.profile.save()
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48" % (email_hash)
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #34
0
 def test_profile_avatar_anonymous(self):
     eq_(settings.STATIC_URL + settings.DEFAULT_AVATAR,
         profile_avatar(AnonymousUser()))
Beispiel #35
0
 def test_profile_avatar_default(self):
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = "https://secure.gravatar.com/avatar/%s?s=48" % (email_hash)
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #36
0
 def test_profile_avatar_default(self):
     profile(user=self.u)
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/{0!s}?s=48'.format((
         email_hash))
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #37
0
 def test_profile_avatar_anonymous(self):
     email_hash = '00000000000000000000000000000000'
     gravatar_url = '//www.gravatar.com/avatar/%s?s=48&d=%s' % (
         email_hash, settings.STATIC_URL + settings.DEFAULT_AVATAR)
     eq_(gravatar_url, profile_avatar(AnonymousUser()))
Beispiel #38
0
 def get_avatar_url(self, obj):
     return profile_avatar(obj.user)
Beispiel #39
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = '//www.gravatar.com/avatar/%s?s=48&d=%s' % (
         email_hash, settings.MEDIA_URL + 'images/foo.png')
     eq_(gravatar_url, profile_avatar(self.u))
Beispiel #40
0
 def test_profile_avatar_unicode(self):
     self.u.email = u'rá[email protected]'
     self.u.save()
     profile(user=self.u)
     gravatar_url = 'https://secure.gravatar.com/'
     assert profile_avatar(self.u).startswith(gravatar_url)
Beispiel #41
0
 def test_profile_avatar(self):
     profile(user=self.u, avatar='images/foo.png')
     email_hash = hashlib.md5(self.u.email.lower()).hexdigest()
     gravatar_url = 'https://secure.gravatar.com/avatar/%s?s=48&d=%s' % (
         email_hash, settings.MEDIA_URL + 'images/foo.png')
     eq_(gravatar_url, profile_avatar(self.u))