Ejemplo n.º 1
0
    def test_get_user_by_username(self):
        from notaliens.identity.models import User
        from notaliens.people.models import get_user_by_username

        options = mock.Mock()

        query2 = mock.Mock()
        options2 = mock.Mock()

        query3 = mock.Mock()
        options3 = mock.Mock()
        query3.options = options3

        query2.options = options2

        options.return_value = query2

        options2.return_value = query3
        query = mock.Mock()
        query.return_value = query

        filter_ = mock.Mock()

        query.options = options

        filter_.return_value = query

        query.filter = filter_

        session = mock.Mock()
        session.query = query



        with mock.patch('notaliens.people.models.joinedload') as joinedload:
            with mock.patch('notaliens.people.models.FromCache') as FromCache:  # nopep8
                with mock.patch('notaliens.people.models.RelationshipCache') as RelationshipCache:  # nopep8
                    FromCache.return_value = 'foo'
                    RelationshipCache.return_value = 'bar'

                    get_user_by_username(session, 'sontek')

                    query.assert_called_with(User)
                    joinedload.assert_called_with('profile')

                    options.assert_called_with(joinedload('profile'))
                    options2.assert_called_with('foo')

                    options3.assert_called_with('bar')


        query.one.assert_called()
Ejemplo n.º 2
0
    def test_get_user_by_username(self):
        from notaliens.identity.models import User
        from notaliens.people.models import get_user_by_username

        options = mock.Mock()

        query2 = mock.Mock()
        options2 = mock.Mock()

        query3 = mock.Mock()
        options3 = mock.Mock()
        query3.options = options3

        query2.options = options2

        options.return_value = query2

        options2.return_value = query3
        query = mock.Mock()
        query.return_value = query

        filter_ = mock.Mock()

        query.options = options

        filter_.return_value = query

        query.filter = filter_

        session = mock.Mock()
        session.query = query

        with mock.patch('notaliens.people.models.joinedload') as joinedload:
            with mock.patch('notaliens.people.models.FromCache'
                            ) as FromCache:  # nopep8
                with mock.patch('notaliens.people.models.RelationshipCache'
                                ) as RelationshipCache:  # nopep8
                    FromCache.return_value = 'foo'
                    RelationshipCache.return_value = 'bar'

                    get_user_by_username(session, 'sontek')

                    query.assert_called_with(User)
                    joinedload.assert_called_with('profile')

                    options.assert_called_with(joinedload('profile'))
                    options2.assert_called_with('foo')

                    options3.assert_called_with('bar')

        query.one.assert_called()
Ejemplo n.º 3
0
def people_profile_view(request):
    user = get_user_by_username(
        request.db_session,
        request.matchdict['username']
    )

    region = get_region_by_postal(request.db_session, user.profile.postal)

    data = {}

    if region:
        data['near_by'] = [u for u in get_users(
            request,
            distance_settings={
                'distance': 50,
                'lat': region.latitude,
                'lon': region.longitude
            },
        )['users'] if u['pk'] != user.pk][:5]

    data['user'] = user

    return {
        'data': data
    }
Ejemplo n.º 4
0
def people_profile_view(request):
    user = get_user_by_username(request.db_session,
                                request.matchdict['username'])

    region = get_region_by_postal(request.db_session, user.profile.postal)

    data = {}

    data['near_by'] = [
        u for u in get_users(
            request,
            distance_settings={
                'distance': 50,
                'lat': region.latitude,
                'lon': region.longitude
            },
        )['users'] if u['pk'] != user.pk
    ][:5]

    data['user'] = user

    return {'data': data}