Exemplo n.º 1
0
    def test_fetch_user_name(self, rget, rlogging):
        def mocked_get(url, **options):
            if 'peterbe' in url:
                return Response(VOUCHED_FOR)
            if 'tmickel' in url:
                return Response(NOT_VOUCHED_FOR)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, 'Peter Bengtsson')
        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, None)
Exemplo n.º 2
0
    def test_fetch_user_name(self, rget, rlogging):
        def mocked_get(url, **options):
            if 'peterbe' in url:
                return Response(VOUCHED_FOR)
            if 'tmickel' in url:
                return Response(NOT_VOUCHED_FOR)
            raise NotImplementedError(url)

        rget.side_effect = mocked_get

        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, 'Peter Bengtsson')
        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, None)
Exemplo n.º 3
0
    def test_fetch_user_name_no_user_name(self, rget, rlogging):
        def mocked_get(url, **options):
            if 'peterbe' in url:
                return Response(VOUCHED_FOR_NO_USERNAME)
            raise NotImplementedError(url)
        rget.side_effect = mocked_get

        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, '')
Exemplo n.º 4
0
    def test_fetch_user_name_no_user_name(self, rget, rlogging):
        def mocked_get(url, **options):
            if 'peterbe' in url:
                return Response(VOUCHED_FOR_NO_USERNAME)
            raise NotImplementedError(url)

        rget.side_effect = mocked_get

        result = mozillians.fetch_user_name('*****@*****.**')
        eq_(result, '')
Exemplo n.º 5
0
def user_name(request):
    if (request.user.is_authenticated() and not request.user.get_full_name()
            and request.user.email):
        # try to look it up on Mozillians
        # but first, if this fails the name won't get update and we'll keep
        # trying over and over
        cache_key = 'mozillians-fullname-query-%s' % request.user.pk
        if not cache.get(cache_key):
            full_name = fetch_user_name(request.user.email)
            if full_name:
                first_name, last_name = _first_last_name(full_name)
                request.user.first_name = first_name
                request.user.last_name = last_name
                request.user.save()
            cache.set(cache_key, 1, 60 * 60 * 24)

    name = ''
    if request.user.is_authenticated():
        name = request.user.get_full_name()
    return {'name': name}
Exemplo n.º 6
0
def user_name(request):
    if (
        request.user.is_authenticated() and
        not request.user.get_full_name() and
        request.user.email
    ):
        # try to look it up on Mozillians
        # but first, if this fails the name won't get update and we'll keep
        # trying over and over
        cache_key = 'mozillians-fullname-query-%s' % request.user.pk
        if not cache.get(cache_key):
            full_name = fetch_user_name(request.user.email)
            if full_name:
                first_name, last_name = _first_last_name(full_name)
                request.user.first_name = first_name
                request.user.last_name = last_name
                request.user.save()
            cache.set(cache_key, 1, 60 * 60 * 24)

    name = ''
    if request.user.is_authenticated():
        name = request.user.get_full_name()
    return {'name': name}