Пример #1
0
    def test_get_feed_followed_user_and_activity_filter(self):
        """ Get personal feed with a followed user and an activity filter.
        """
        # set activity filter
        user = self.session.query(User).get(self.global_userids['contributor'])
        user.feed_filter_activities = ['hiking']

        # follow a user
        self.session.add(FollowedUser(
            followed_user_id=self.global_userids['contributor2'],
            follower_user_id=self.global_userids['contributor']))
        self.session.flush()

        headers = self.add_authorization_header(username='******')
        response = self.app.get('/personal-feed', status=200, headers=headers)
        body = response.json

        feed = body['feed']
        self.assertEqual(3, len(feed))

        self.assertEqual(
            self.outing.document_id, feed[0]['document']['document_id'])
        self.assertEqual(
            self.route.document_id, feed[1]['document']['document_id'])
        self.assertEqual(
            self.waypoint2.document_id, feed[2]['document']['document_id'])
Пример #2
0
    def setUp(self):  # noqa
        super(BaseFollowTest, self).setUp()

        self.contributor = self.session.query(User).get(
            self.global_userids['contributor'])
        self.contributor2 = self.session.query(User).get(
            self.global_userids['contributor2'])
        self.moderator = self.session.query(User).get(
            self.global_userids['moderator'])

        self.session.add(FollowedUser(
            followed_user_id=self.contributor2.id,
            follower_user_id=self.contributor.id))

        self.session.flush()
Пример #3
0
    def test_get_feed_followed_user_filter_ignored(self):
        """ Get personal feed with a followed user filter without area and
        activity filter (returns all changes). The followed users are ignored.
        """
        # follow a user
        self.session.add(FollowedUser(
            followed_user_id=self.global_userids['contributor2'],
            follower_user_id=self.global_userids['contributor']))
        self.session.flush()

        headers = self.add_authorization_header(username='******')
        response = self.app.get('/personal-feed', status=200, headers=headers)
        body = response.json

        feed = body['feed']
        self.assertEqual(4, len(feed))
Пример #4
0
    def post(self):
        """ Follow the given user.
        Creates a follower relation, so that the authenticated user is
        following the given user.


        Request:
            `POST` `/users/follow`

        Request body:
            {'user_id': @user_id@}

        """
        followed_user_id = self.request.validated['user_id']
        follower_user_id = self.request.authenticated_userid
        follower_relation = get_follower_relation(followed_user_id,
                                                  follower_user_id)

        if not follower_relation:
            DBSession.add(
                FollowedUser(followed_user_id=followed_user_id,
                             follower_user_id=follower_user_id))

        return {}
Пример #5
0
    def test_get_feed_followed_user_filter_followed_only(self):
        """ Get personal feed with a followed user and `feed_followed_only`.
        """
        # enable `feed_followed_only`
        user = self.session.query(User).get(self.global_userids['contributor'])
        user.feed_followed_only = True

        # follow a user
        self.session.add(FollowedUser(
            followed_user_id=self.global_userids['contributor2'],
            follower_user_id=self.global_userids['contributor']))
        self.session.flush()

        headers = self.add_authorization_header(username='******')
        response = self.app.get('/personal-feed', status=200, headers=headers)
        body = response.json

        feed = body['feed']
        self.assertEqual(2, len(feed))

        self.assertEqual(
            self.outing.document_id, feed[0]['document']['document_id'])
        self.assertEqual(
            self.waypoint2.document_id, feed[1]['document']['document_id'])