Exemple #1
0
    def test_get_profile_preview_not_found(self):
        with patch.object(Persistence, "get_one") as mocked_user_get, \
             self.assertRaises(UserNotFoundException) as context:
            mocked_user_get.side_effect = MagicMock(return_value=None)

            User.get_profile_preview("pepe")

        exc = context.exception
        self.assertEqual(exc.error_code, 404)
Exemple #2
0
    def _format_feed_flash(srz_flash):
        uploader = srz_flash['username']
        profile_preview = User.get_profile_preview(uploader)

        srz_flash['name'] = profile_preview['name']
        srz_flash['profile_pic'] = profile_preview['profile_pic']
        return srz_flash
Exemple #3
0
    def _format_feed_story(story_id):
        serialized_story = Story.get_story(story_id)
        uploader = serialized_story['username']
        profile_preview = User.get_profile_preview(uploader)

        serialized_story['name'] = profile_preview['name']
        serialized_story['profile_pic'] = profile_preview['profile_pic']
        return serialized_story
Exemple #4
0
 def get_friends(username):
     """Returns a list of username friends as profile previews, or raises UserNotFoundException
     if none was found."""
     Logger(__name__).info(
         'Retrieving friends for user {}.'.format(username))
     friend_ids = Friendship._get_friends_of(username)
     return [
         User.get_profile_preview(friend_id) for friend_id in friend_ids
     ]
Exemple #5
0
    def test_get_profile_preview_successful(self):
        with patch.object(Persistence, "get_one") as mocked_user_get:

            aux_user_obj = user_mock_without_stories_or_friends
            aux_username = aux_user_obj['username']
            expected_preview = {
                "username": aux_user_obj['username'],
                "profile_pic": aux_user_obj['profile_pic'],
                "name": aux_user_obj['name']
            }
            mocked_user_get.side_effect = MagicMock(return_value=aux_user_obj)
            self.assertEqual(User.get_profile_preview(aux_username), expected_preview)
Exemple #6
0
    def get(self, username):
        try:
            # get token from header
            token = self._get_token_from_header()

            # identify with token
            callee_user = Token.identify(token)

            # get profile info from user username
            profile_preview = User.get_profile_preview(username)

            # generate response
            self.logger.info(
                'User profile preview found for: {}'.format(username))
            output = profile_preview

            # return response
            return ResponseBuilder.build_response(output)

        except (UserNotFoundException, ExpiredTokenException,
                MissingFieldException, InvalidTokenException) as e:
            return ResponseBuilder.build_error_response(
                e.message, e.error_code)