def test_are_friends(self):
     """Testing if correctly identifies two authors as friends or not"""
     user1 = User.objects.get(username="******")
     user2 = User.objects.get(username="******")
     author1 = Author.objects.get(user=user1)
     author2 = Author.objects.get(user=user2)
     response = FriendRequest.make_request(author1, author2)
     response2 = FriendRequest.is_friend(author1, author2)
     response3 = FriendRequest.accept_request(author2, author1)
     response4 = FriendRequest.is_friend(author1, author2)
     response5 = FriendRequest.is_friend(author2, author1)
     self.assertEquals(True, response)
     self.assertEquals(False, response2)
     self.assertEquals(True, response3)
     self.assertEquals(True, response4)
     self.assertEquals(True, response5)
 def test_are_friends(self):
     """Testing if correctly identifies two authors as friends or not"""
     user1 = User.objects.get(username="******")
     user2 = User.objects.get(username="******")
     author1 = Author.objects.get(user=user1)
     author2 = Author.objects.get(user=user2)
     response = FriendRequest.make_request(author1, author2)
     response2 = FriendRequest.is_friend(author1, author2)
     response3 = FriendRequest.accept_request(author2, author1)
     response4 = FriendRequest.is_friend(author1, author2)
     response5 = FriendRequest.is_friend(author2, author1)
     self.assertEquals(True, response)
     self.assertEquals(False, response2)
     self.assertEquals(True, response3)
     self.assertEquals(True, response4)
     self.assertEquals(True, response5)
def accept_friendship(request):
    """Handles a post request to accept a friend request."""
    context = RequestContext(request)

    if request.method == 'POST':
        if request.user.is_authenticated():
            friend_requester = request.POST['friend_requester']
            requester = User.objects.get(username=friend_requester)
            requester2 = Author.objects.get(user=requester)
            author = Author.objects.get(user=request.user)
            status = FriendRequest.accept_request(requester2, author)
            print(status)
            if status:
                messages.info(request, 'Friend request has been accepted.')
            return redirect('/author/friends', context)
        else:
            _render_error('login.html', 'Please log in.', context)
def accept_friendship(request):
    """Handles a post request to accept a friend request."""
    context = RequestContext(request)

    if request.method == 'POST':
        if request.user.is_authenticated():
            friend_requester = request.POST['friend_requester']
            requester = User.objects.get(username=friend_requester)
            requester2 = Author.objects.get(user=requester)
            author = Author.objects.get(user=request.user)
            status = FriendRequest.accept_request(requester2, author)
            print(status)
            if status:
                messages.info(request, 'Friend request has been accepted.')
            return redirect('/author/friends', context)
        else:
            _render_error('login.html', 'Please log in.', context)
    def test_friend_list(self):
        """Testing if successfully returns a list of friends"""
        c = Client()
        c.login(username='******', password='******')
        user1 = User.objects.get(username="******")
        user2 = User.objects.get(username="******")
        author1 = Author.objects.get(user=user1)
        author2 = Author.objects.get(user=user2)
        response = FriendRequest.make_request(author2, author1)
        response2 = FriendRequest.accept_request(author1, author2)

        url = '/author/' + str(user1.id) + '/Friends'
        response = c.get(url)
        self.assertEquals(response.status_code, 200)
        response = response.context['friendList']
        response = response.split(':')
        self.assertEquals(response, ['myuser2'])
    def test_friend_list(self):
        """Testing if successfully returns a list of friends"""
        c = Client()
        c.login(username='******', password='******')
        user1 = User.objects.get(username="******")
        user2 = User.objects.get(username="******")
        author1 = Author.objects.get(user=user1)
        author2 = Author.objects.get(user=user2)
        response = FriendRequest.make_request(author2, author1)
        response2 = FriendRequest.accept_request(author1, author2)

        url = '/author/' + str(user1.id) + '/Friends'
        response = c.get(url)
        self.assertEquals(response.status_code, 200)
        response=response.context['friendList']
        response=response.split(':')
        self.assertEquals(response, ['myuser2'])