Example #1
0
    def test_friendship_actions(self):
        test_user1 = User.objects.get(username='******')
        test_user2 = User.objects.get(username='******')

        friends = UserFriends(test_user1)

        # Sending request
        self.client.login(username='******')
        self.client.post(reverse('send_friendship_request',
                args=['test_user2']))
        self.assertTrue(friends.sent_request_to(test_user2))

        # Accepting request
        self.client.login(username='******')
        self.client.post(reverse('accept_friendship_request',
                args=['test_user']))
        self.assertTrue(friends.is_friends_with(test_user2))

        # Ending friendship
        self.client.post(reverse('remove_friend',
                args=['test_user']))
        self.assertFalse(friends.is_friends_with(test_user2))

        # Refusing request
        self.client.post(reverse('send_friendship_request',
                args=['test_user']))
        self.client.login(username='******')
        self.client.post(reverse('refuse_friendship_request',
                args=['test_user2']))
        self.assertFalse(friends.has_request_from(test_user2))
Example #2
0
    def test_friendship_actions(self):
        test_user1 = User.objects.get(username="******")
        test_user2 = User.objects.get(username="******")

        friends = UserFriends(test_user1)

        # Sending request
        self.client.login(username="******")
        self.client.post(reverse("send_friendship_request", args=["test_user2"]))
        self.assertTrue(friends.sent_request_to(test_user2))

        # Accepting request
        self.client.login(username="******")
        self.client.post(reverse("accept_friendship_request", args=["test_user"]))
        self.assertTrue(friends.is_friends_with(test_user2))

        # Ending friendship
        self.client.post(reverse("remove_friend", args=["test_user"]))
        self.assertFalse(friends.is_friends_with(test_user2))

        # Refusing request
        self.client.post(reverse("send_friendship_request", args=["test_user"]))
        self.client.login(username="******")
        self.client.post(reverse("refuse_friendship_request", args=["test_user2"]))
        self.assertFalse(friends.has_request_from(test_user2))
Example #3
0
    def test_friendship_actions(self):
        test_user1 = User.objects.get(username='******')
        test_user2 = User.objects.get(username='******')

        friends = UserFriends(test_user1)

        # Sending request
        self.client.login(username='******')
        self.client.post(
            reverse('send_friendship_request', args=['test_user2']))
        self.assertTrue(friends.sent_request_to(test_user2))

        # Accepting request
        self.client.login(username='******')
        self.client.post(
            reverse('accept_friendship_request', args=['test_user']))
        self.assertTrue(friends.is_friends_with(test_user2))

        # Ending friendship
        self.client.post(reverse('remove_friend', args=['test_user']))
        self.assertFalse(friends.is_friends_with(test_user2))

        # Refusing request
        self.client.post(reverse('send_friendship_request',
                                 args=['test_user']))
        self.client.login(username='******')
        self.client.post(
            reverse('refuse_friendship_request', args=['test_user2']))
        self.assertFalse(friends.has_request_from(test_user2))
Example #4
0
    def isRequestSent(self, sender, recipient):
        friends_sender = UserFriends(sender)
        friends_recipient = UserFriends(recipient)

        result_a = friends_sender.sent_request_to(recipient)
        result_b = friends_recipient.has_request_from(sender)
        self.assertEquals(result_a, result_b)
        self.assertEquals(result_a, recipient in [x.recipient.user for x in friends_sender.my_requests.all()])
        self.assertEquals(result_a, sender in [x.sender.user for x in friends_recipient.requests_for_me.all()])

        return result_a
Example #5
0
def profile_view(request, username=None):
    shown_user = None

    if username is None:
        shown_user = request.user
    else:
        shown_user = get_object_or_404(User.objects, username=username)

    exp = Experience(shown_user)
    friends = UserFriends(request.user)
    is_friend = friends.is_friends_with(shown_user)
    pending_incoming_friendship_request = friends.has_request_from(shown_user)
    sent_friendship_request = friends.sent_request_to(shown_user)

    has_portal = False
    if 'oioioi.portals' in settings.INSTALLED_APPS:
        from oioioi.portals.models import Portal
        if Portal.objects.filter(owner=shown_user).exists():
            has_portal = True

    sections = []
    for func in profile_registry.items:
        response = func(request, shown_user)

        if isinstance(response, HttpResponseRedirect):
            return response

        if isinstance(response, TemplateResponse):
            sections.append(response.render().content)
        else:
            sections.append(response)

    return TemplateResponse(
        request, 'gamification/profile.html', {
            'shown_user':
            shown_user,
            'is_my_friend':
            is_friend,
            'exp':
            exp,
            'exp_percentage':
            int(100 * exp.current_experience /
                exp.required_experience_to_lvlup),
            'has_portal':
            has_portal,
            'pending_incoming_friendship_request':
            pending_incoming_friendship_request,
            'sent_friendship_request':
            sent_friendship_request,
            'sections':
            sections
        })
Example #6
0
    def isRequestSent(self, sender, recipient):
        friends_sender = UserFriends(sender)
        friends_recipient = UserFriends(recipient)

        result_a = friends_sender.sent_request_to(recipient)
        result_b = friends_recipient.has_request_from(sender)
        self.assertEquals(result_a, result_b)
        self.assertEquals(
            result_a, recipient
            in [x.recipient.user for x in friends_sender.my_requests.all()])
        self.assertEquals(
            result_a, sender in [
                x.sender.user for x in friends_recipient.requests_for_me.all()
            ])

        return result_a
Example #7
0
def profile_view(request, username=None):
    shown_user = None

    if username is None:
        shown_user = request.user
    else:
        shown_user = get_object_or_404(User.objects, username=username)

    exp = Experience(shown_user)
    friends = UserFriends(request.user)
    is_friend = friends.is_friends_with(shown_user)
    pending_incoming_friendship_request = friends.has_request_from(shown_user)
    sent_friendship_request = friends.sent_request_to(shown_user)

    has_portal = False
    if "oioioi.portals" in settings.INSTALLED_APPS:
        from oioioi.portals.models import Portal

        if Portal.objects.filter(owner=shown_user).exists():
            has_portal = True

    sections = []
    for func in profile_registry.items:
        response = func(request, shown_user)

        if isinstance(response, HttpResponseRedirect):
            return response

        if isinstance(response, TemplateResponse):
            sections.append(response.render().content)
        else:
            sections.append(response)

    return TemplateResponse(
        request,
        "gamification/profile.html",
        {
            "shown_user": shown_user,
            "is_my_friend": is_friend,
            "exp": exp,
            "exp_percentage": int(100 * exp.current_experience / exp.required_experience_to_lvlup),
            "has_portal": has_portal,
            "pending_incoming_friendship_request": pending_incoming_friendship_request,
            "sent_friendship_request": sent_friendship_request,
            "sections": sections,
        },
    )