예제 #1
0
    def test_can_write_now(self):

        self.user1.user.is_active = True
        self.user1.user.can_write = True
        self.assertTrue(self.user1.can_write_now())

        # Was banned in the past, ban no longer active
        profile = ProfileFactory()
        profile.can_write = True
        profile.end_ban_read = datetime.now() - timedelta(days=1)
        self.assertTrue(profile.can_write_now())

        profile = ProfileFactory()
        profile.can_write = False
        profile.is_active = True
        self.assertFalse(profile.can_write_now())

        # Ban is active
        profile = ProfileFactory()
        profile.can_write = False
        profile.end_ban_write = datetime.now() + timedelta(days=1)
        self.assertFalse(profile.can_write_now())

        self.user1.user.is_active = False
        self.user1.user.can_write = True
        self.assertFalse(self.user1.can_write_now())
예제 #2
0
파일: tests.py 프로젝트: Arnaud-D/zds-site
    def test_failure_reaction_karma_with_sanctioned_user(self):
        author = ProfileFactory()
        reaction = ContentReactionFactory(author=author.user, position=1, related_content=self.content)

        profile = ProfileFactory()
        profile.can_read = False
        profile.can_write = False
        profile.save()

        self.client.force_login(profile.user)
        response = self.client.put(reverse("api:content:reaction-karma", args=(reaction.pk,)))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
예제 #3
0
    def test_members_are_contactable(self):
        """
        The PM button is displayed to logged in users, except if it's the profile
        of a banned user.
        """
        user_ban = ProfileFactory()
        user_ban.can_read = False
        user_ban.can_write = False
        user_ban.save()
        user_1 = ProfileFactory()
        user_2 = ProfileFactory()

        phrase = "Envoyer un message"

        # The PM button is hidden for anonymous users
        result = self.client.get(reverse("member-detail",
                                         args=[user_1.user.username]),
                                 follow=False)
        self.assertNotContains(result, phrase)

        # Also for anonymous users viewing banned members profiles
        result = self.client.get(reverse("member-detail",
                                         args=[user_ban.user.username]),
                                 follow=False)
        self.assertNotContains(result, phrase)

        self.client.force_login(user_2.user)

        # If an user is logged in, the PM button is shown for other normal users
        result = self.client.get(reverse("member-detail",
                                         args=[user_1.user.username]),
                                 follow=False)
        self.assertContains(result, phrase)

        # But not for banned users
        result = self.client.get(reverse("member-detail",
                                         args=[user_ban.user.username]),
                                 follow=False)
        self.assertNotContains(result, phrase)

        self.client.logout()
        self.client.force_login(user_1.user)

        # Neither for his own profile
        result = self.client.get(reverse("member-detail",
                                         args=[user_1.user.username]),
                                 follow=False)
        self.assertNotContains(result, phrase)

        self.client.logout()
예제 #4
0
    def test_failure_post_karma_with_sanctioned_user(self):
        profile = ProfileFactory()
        category, forum = create_category_and_forum()
        topic = create_topic_in_forum(forum, profile)
        another_profile = ProfileFactory()
        post = PostFactory(topic=topic, author=another_profile.user, position=2)

        profile = ProfileFactory()
        profile.can_read = False
        profile.can_write = False
        profile.save()

        self.client.force_login(profile.user)
        response = self.client.put(reverse("api:forum:post-karma", args=(post.pk,)))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
예제 #5
0
    def test_reachable_manager(self):
        # profile types
        profile_normal = ProfileFactory()
        profile_superuser = ProfileFactory()
        profile_superuser.user.is_superuser = True
        profile_superuser.user.save()
        profile_inactive = ProfileFactory()
        profile_inactive.user.is_active = False
        profile_inactive.user.save()
        profile_bot = ProfileFactory()
        profile_bot.user.username = settings.ZDS_APP["member"]["bot_account"]
        profile_bot.user.save()
        profile_anonymous = ProfileFactory()
        profile_anonymous.user.username = settings.ZDS_APP["member"][
            "anonymous_account"]
        profile_anonymous.user.save()
        profile_external = ProfileFactory()
        profile_external.user.username = settings.ZDS_APP["member"][
            "external_account"]
        profile_external.user.save()
        profile_ban_def = ProfileFactory()
        profile_ban_def.can_read = False
        profile_ban_def.can_write = False
        profile_ban_def.save()
        profile_ban_temp = ProfileFactory()
        profile_ban_temp.can_read = False
        profile_ban_temp.can_write = False
        profile_ban_temp.end_ban_read = datetime.now() + timedelta(days=1)
        profile_ban_temp.save()
        profile_unban = ProfileFactory()
        profile_unban.can_read = False
        profile_unban.can_write = False
        profile_unban.end_ban_read = datetime.now() - timedelta(days=1)
        profile_unban.save()
        profile_ls_def = ProfileFactory()
        profile_ls_def.can_write = False
        profile_ls_def.save()
        profile_ls_temp = ProfileFactory()
        profile_ls_temp.can_write = False
        profile_ls_temp.end_ban_write = datetime.now() + timedelta(days=1)
        profile_ls_temp.save()

        # groups

        bot = Group(name=settings.ZDS_APP["member"]["bot_group"])
        bot.save()

        # associate account to groups
        bot.user_set.add(profile_anonymous.user)
        bot.user_set.add(profile_external.user)
        bot.user_set.add(profile_bot.user)
        bot.save()

        # test reachable user
        profiles_reacheable = Profile.objects.contactable_members().all()
        self.assertIn(profile_normal, profiles_reacheable)
        self.assertIn(profile_superuser, profiles_reacheable)
        self.assertNotIn(profile_inactive, profiles_reacheable)
        self.assertNotIn(profile_anonymous, profiles_reacheable)
        self.assertNotIn(profile_external, profiles_reacheable)
        self.assertNotIn(profile_bot, profiles_reacheable)
        self.assertIn(profile_unban, profiles_reacheable)
        self.assertNotIn(profile_ban_def, profiles_reacheable)
        self.assertNotIn(profile_ban_temp, profiles_reacheable)
        self.assertIn(profile_ls_def, profiles_reacheable)
        self.assertIn(profile_ls_temp, profiles_reacheable)