Example #1
0
    def test_get_author_data(self):
        db_user, author_string, some_boolean = lib.get_author_data(0)
        self.assertFalse(some_boolean)
        self.assertIsNone(db_user)

        user = DBDiscussionSession.query(User).get(1)
        _, author_string, some_boolean = lib.get_author_data(1, gravatar_on_right_side=False)
        self.assertTrue(some_boolean)
        self.assertIn('{}'.format(user.nickname), author_string)
        self.assertIn('right', author_string)

        _, author_string, some_boolean = lib.get_author_data(1, gravatar_on_right_side=True)
        self.assertTrue(some_boolean)
        self.assertIn('{}'.format(user.nickname), author_string)
        self.assertIn('left', author_string)
Example #2
0
def get_name_link_of_arguments_author(argument, nickname, with_link=True):
    """
    Will return author of the argument, if the first supporting user

    :param argument: Argument
    :param nickname: User.nickname
    :param with_link:
    :return:
    """
    user, link, is_valid = get_author_data(argument.author_uid, False, True)
    db_author_of_argument = DBDiscussionSession.query(User).get(
        argument.author_uid)
    gender = db_author_of_argument.gender if db_author_of_argument else 'n'

    db_anonymous_user = DBDiscussionSession.query(User).filter_by(
        nickname=nick_of_anonymous_user).first()

    # if the data of arguments author is not okay, get the first user, who agrees with the argument
    if argument.author_uid == db_anonymous_user.uid or not is_valid:
        # get nick of current user
        nickname = nickname if nickname is not None else nick_of_anonymous_user
        db_current_user = DBDiscussionSession.query(User).filter_by(
            nickname=nickname).first()

        db_author_of_argument = get_author_or_first_supporter_of_element(
            argument.uid, db_current_user.uid, True)

        if db_author_of_argument:
            user, link, is_valid = get_author_data(
                db_author_of_argument.uid,
                gravatar_on_right_side=False,
                linked_with_users_page=with_link)
            db_author_of_argument = DBDiscussionSession.query(User).get(
                db_author_of_argument.uid)
            gender = db_author_of_argument.gender if db_author_of_argument else 'n'
        else:
            return {'user': None, 'text': '', 'gender': 'n', 'is_valid': False}

    return {
        'user': user,
        'link': link if is_valid else '',
        'gender': gender,
        'is_valid': is_valid
    }