Exemple #1
0
 def test_new_multiple(self, activeClient, testUser3, testUser4):
     request1 = FriendRequest.create(requestor_id=testUser3.id,
                                     friend_id=current_user.id)
     request2 = FriendRequest.create(requestor_id=testUser4.id,
                                     friend_id=current_user.id)
     self.form = {"name": [request1.id, request2.id]}
     response = self.postRequest(activeClient)
     assert response.status_code == 200
     print(response.data.decode())
     flash = escape(
         f"You are now friends with {request1.requestor.full_name} & {request2.requestor.full_name}."
     )
     assert flash.encode() in response.data
Exemple #2
0
 def test_withPendingSentRequestApproval(self, activeClient, testUser3):
     FriendRequest.create(requestor_id=current_user.id,
                          friend_id=testUser3.id)
     response = self.getRequest(activeClient)
     page = response.data.decode()
     assert response.status_code == 200
     pendingCount = b"Pending<span>(1)</span>"
     assert pendingCount in response.data
     sentRequests = r'<h5>Sent</h5>\s*<ul>\s*<li>Mark Johnson</li>\s*</ul>'
     match = re.search(sentRequests, page)
     assert match is not None
     recRequests = r'<h5>Received</h5>\s*<ul>\s*<li>None</li>\s*</ul>'
     match = re.search(sentRequests, page)
     assert match is not None
Exemple #3
0
 def test_withPendingReceivedRequestApproval(self, activeClient, testUser3):
     FriendRequest.create(requestor_id=testUser3.id,
                          friend_id=current_user.id)
     response = self.getRequest(activeClient)
     assert response.status_code == 200
     pendingCount = b"Pending<span>(1)</span>"
     assert pendingCount in response.data
     page = response.data.decode()
     sentRequests = r'<h5>Sent</h5>\s*<ul>\s*<li>None</li>\s*</ul>'
     match = re.search(sentRequests, page)
     assert match is not None
     recRequest = r'<h5>Received[\s\S]*<ul class="nobullets" id="name"><li><input\s*id="name-0" name="name" type="checkbox" value="1">\s*<label for="name-0">Mark Johnson</label>'
     match = re.search(recRequest, page)
     assert match is not None
Exemple #4
0
 def test_delete(self, testUser):
     FriendRequest.create(requestor_id=testUser.id, friend_id=4)
     GroupRequest.create(requestor_id=testUser.id, group_id=2)
     assert testUser.address.user_id == 2
     assert len(User.query.all()) == 4
     assert len(testUser.reviews) == 4
     assert len(Review.query.all()) == 7
     assert len(FriendRequest.query.all()) == 1
     assert len(GroupRequest.query.all()) == 1
     testUser.delete()
     testUser = User.query.get(2)
     assert testUser is None
     assert Review.query.filter_by(user_id=2).all() == []
     assert FriendRequest.query.filter_by(requestor_id=2).all() == []
     assert GroupRequest.query.filter_by(requestor_id=2).all() == []
     assert len(User.query.all()) == 3
Exemple #5
0
def invite_new_friend(user_id):
    user = User.query.filter_by(id=user_id).first()
    user_name = user.username
    req = FriendRequest(user1=current_user.get_id(), user2=user_id)
    db.session.add(req)
    db.session.commit()
    return redirect('/user/' + user_name)
Exemple #6
0
def test_friend_request(new_user, new_user1):
    """
    Tests if the friend request system's request status works.
    """
    friend_request = FriendRequest(author=new_user,
                                   requester_username=new_user.username,
                                   friend_username=new_user1.username,
                                   request_status=True)
    assert friend_request.request_status == True
Exemple #7
0
 def test_addFriend(self, testUser, testUser4):
     assert len(testUser.receivedfriendrequests) == 0
     request = FriendRequest.create(friend_id=testUser.id,
                                    requestor_id=testUser4.id)
     assert len(testUser.receivedfriendrequests) == 1
     assert len(testUser4.sentfriendrequests) == 1
     testUser.add(testUser4, request)
     assert testUser4 in testUser.friends
     assert len(testUser.receivedfriendrequests) == 0
     assert len(testUser4.sentfriendrequests) == 0
Exemple #8
0
def friend_verify(token):
    """Verify friend request add token and add person to friend list."""
    friendrequest = FriendRequest.verify_token(token)
    if not friendrequest:
        msg = "Friend request verification failed. Please either log in to "\
              "submit new request or have requestor re-submit."
    else:
        approver = friendrequest.requested_friend
        friend = friendrequest.requestor
        approver.add(friend, friendrequest)
        msg = f"You are now friends with {friend.full_name}."
        if not approver.email_verified:
            approver.update(email_verified=True)
    flash(msg)
    return redirect(url_for('auth.welcome'))
Exemple #9
0
def add_friend(user_id):
    check = FriendRequest.query.filter_by(
        user_sent_from=session['user_id'],
        user_sent_to=user_id).first()  #get friend request
    friends = are_friends(session['user_id'], user_id)
    if check == None and not friends:
        fq = FriendRequest(user_sent_from=session['user_id'],
                           user_sent_to=user_id)
        db.session.add(fq)
        db.session.commit()
        flash('Friend request sent!')
        return redirect(url_for('users.profile', user_id=user_id))
    else:
        if friends == True:
            flash('Already friends')
        else:
            flash('Request already sent')
        return redirect(url_for('users.profile', user_id=user_id))
Exemple #10
0
def friendadd():
    """Send friend request to add friend."""
    form = FriendSearchForm()
    if form.validate_on_submit():
        request_args = {"requestor_id": current_user.id,
                        "friend_id": form.id.data}
        request = FriendRequest.query.filter_by(**request_args).first()
        if not request:
            request = FriendRequest.create(**request_args)
        request.send()
        flash(
            f"Friend request sent to {request.requested_friend.full_name}."
            "  Awaiting confirmation."
        )
        return redirect(url_for('relationship.network_friends'))
    else:
        flash(
            f"Friend request unsucessful.  {' '.join(form.id.errors)}"
            f"  Please correct errors and resubmit."
        )
        return friends_render(form, 422)
Exemple #11
0
def testFriendrequest2(dbSession, testUser, testUser3):
    request = FriendRequest.create(friend_id=testUser.id,
                                   requestor_id=testUser3.id)
    return request