Exemplo n.º 1
0
    def test_cant_retrieve_reported_and_approved_hashtag(self):
        """
        should not be able to retrieve a reported and approved hashtag and return 403
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        hashtag = make_hashtag()
        hashtag_name = hashtag.name

        reporter = make_user()
        report_category = make_moderation_category()
        reporter.report_hashtag_with_name(hashtag_name=hashtag_name,
                                          category_id=report_category.pk)

        global_moderator = make_global_moderator()

        moderated_object = ModeratedObject.get_or_create_moderated_object_for_hashtag(
            hashtag=hashtag, category_id=report_category.pk)
        global_moderator.approve_moderated_object(
            moderated_object=moderated_object)

        url = self._get_url(hashtag_name=hashtag_name)

        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 2
0
    def test_cannot_retrieve_soft_deleted_community(self):
        """
        should not be able to retrieve a soft deleted community and return 403
        """
        global_moderator = make_global_moderator()

        user = make_user()
        headers = make_authentication_headers_for_user(user)

        community_owner = make_user()
        community = make_community(creator=community_owner)
        community_name = community.name

        community_reporter = make_user()
        moderation_category = make_moderation_category()
        community_reporter.report_community(community=community,
                                            category_id=moderation_category.pk)

        moderated_object = ModeratedObject.get_or_create_moderated_object_for_community(
            community=community, category_id=moderation_category.pk)
        global_moderator.approve_moderated_object(
            moderated_object=moderated_object)
        global_moderator.verify_moderated_object(
            moderated_object=moderated_object)

        url = self._get_url(community_name=community_name)

        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemplo n.º 3
0
    def test_can_retrieve_foreign_user_reported_hashtag(self):
        """
        should be able to retrieve a foreign user reported hashtag and return 200
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        hashtag = make_hashtag()
        hashtag_name = hashtag.name

        reporter = make_user()
        report_category = make_moderation_category()
        reporter.report_hashtag_with_name(hashtag_name=hashtag_name,
                                          category_id=report_category.pk)

        url = self._get_url(hashtag_name=hashtag_name)

        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        parsed_response = json.loads(response.content)

        self.assertIn('name', parsed_response)
        response_name = parsed_response['name']
        self.assertEqual(response_name, hashtag_name)
Exemplo n.º 4
0
    def test_cant_retrieve_pending_moderated_objects_communities_of_administrated_communities(self):
        """
        should not be able to retrieve pending moderated objects communities of non administrated communities
        :return:
        """

        user = make_user()

        amount_of_pending_moderated_objects = 5

        amount_of_administrated_communities = 5

        post_reporter = make_user()

        for i in range(0, amount_of_administrated_communities):
            community_creator = make_user()
            community = make_community(creator=community_creator)
            user.join_community_with_name(community_name=community.name)

            for j in range(0, amount_of_pending_moderated_objects):
                post_creator = make_user()
                post_creator.join_community_with_name(community_name=community.name)
                post = post_creator.create_community_post(community_name=community.name, text=make_fake_post_text())
                post_reporter.report_post(post=post, category_id=make_moderation_category().pk)

        url = self._get_url()
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response_communities = json.loads(response.content)

        self.assertEqual(0, len(response_communities))
Exemplo n.º 5
0
    def test_no_suspension_penalties_do_not_prevent_access(self):
        """
        no suspension penalties should not prevent access to the API
        :return:
        """
        global_moderator = make_global_moderator()

        user = make_user()

        reporter_user = make_user()
        report_category = make_moderation_category(
            severity=ModerationCategory.SEVERITY_MEDIUM)

        reporter_user.report_user_with_username(username=user.username,
                                                category_id=report_category.pk)

        moderated_object = ModeratedObject.get_or_create_moderated_object_for_user(
            user=user, category_id=report_category.pk)

        global_moderator.approve_moderated_object(
            moderated_object=moderated_object)

        url = self._get_url()
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(status.HTTP_200_OK, response.status_code)
Exemplo n.º 6
0
    def test_cant_search_for_reported_and_approved_hashtag(self):
        """
        should not be able to search for a reported and approved hashtag and return 200
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        reporter = make_user()

        hashtag_name = make_hashtag_name()
        hashtag = make_hashtag(name=hashtag_name)

        report_category = make_moderation_category()
        reporter.report_hashtag_with_name(hashtag_name=hashtag_name,
                                          category_id=report_category.pk)

        global_moderator = make_global_moderator()

        moderated_object = ModeratedObject.get_or_create_moderated_object_for_hashtag(
            hashtag=hashtag, category_id=report_category.pk)
        global_moderator.approve_moderated_object(
            moderated_object=moderated_object)

        url = self._get_url()
        response = self.client.get(url, {'query': hashtag.name}, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        parsed_response = json.loads(response.content)
        self.assertEqual(len(parsed_response), 0)
Exemplo n.º 7
0
    def test_can_retrieve_moderation_categories(self):
        """
        should be able to retrieve all moderationCategories and return 200
        """
        user = make_user()

        amount_of_moderationCategories = 5
        moderation_categories_ids = []

        for i in range(0, amount_of_moderationCategories):
            moderationCategory = make_moderation_category()
            moderation_categories_ids.append(moderationCategory.pk)

        url = self._get_url()
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response_moderation_categories = json.loads(response.content)

        self.assertEqual(len(response_moderation_categories),
                         len(moderation_categories_ids))

        for response_moderationCategory in response_moderation_categories:
            response_moderation_category_id = response_moderationCategory.get(
                'id')
            self.assertIn(response_moderation_category_id,
                          moderation_categories_ids)
Exemplo n.º 8
0
    def test_cannot_retrieve_reported_posts_from_community(self):
        """
        should not be able to retrieve reported posts of a community
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        community_creator = make_user()
        community = make_community(creator=community_creator)
        user.join_community_with_name(community_name=community.name)

        community_name = community.name

        amount_of_community_posts = 5

        for i in range(0, amount_of_community_posts):
            community_member = make_user()
            community_member.join_community_with_name(
                community_name=community_name)
            community_member_post = community_member.create_community_post(
                community_name=community.name, text=make_fake_post_text())
            moderation_category = make_moderation_category()
            user.report_post(post=community_member_post,
                             category_id=moderation_category.pk)

        url = self._get_url(community_name=community.name)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response_posts = json.loads(response.content)

        self.assertEqual(0, len(response_posts))
Exemplo n.º 9
0
    def test_can_retrieve_pending_moderated_objects_communities_of_moderated_communities(
            self):
        """
        should be able to retrieve pending moderated objects communities of moderated communities
        :return:
        """

        user = make_user()

        amount_of_pending_moderated_objects = 5

        amount_of_moderated_communities = 5
        moderated_commmunities_ids = []

        post_reporter = make_user()

        for i in range(0, amount_of_moderated_communities):
            community_creator = make_user()
            community = make_community(creator=community_creator)
            user.join_community_with_name(community_name=community.name)
            community_creator.add_moderator_with_username_to_community_with_name(
                community_name=community.name, username=user.username)

            for j in range(0, amount_of_pending_moderated_objects):
                post_creator = make_user()
                post_creator.join_community_with_name(
                    community_name=community.name)
                post = post_creator.create_community_post(
                    community_name=community.name, text=make_fake_post_text())
                post_reporter.report_post(
                    post=post, category_id=make_moderation_category().pk)

            moderated_commmunities_ids.append(community.pk)

        url = self._get_url()
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response_communities = json.loads(response.content)

        self.assertEqual(len(response_communities),
                         len(moderated_commmunities_ids))

        for response_community in response_communities:
            response_community_id = response_community.get('id')
            response_community_pending_moderated_objects_count = response_community.get(
                'pending_moderated_objects_count')
            self.assertIn(response_community_id, moderated_commmunities_ids)
            self.assertEqual(
                amount_of_pending_moderated_objects,
                response_community_pending_moderated_objects_count)
Exemplo n.º 10
0
    def test_can_retrieve_moderated_rejected_posts_from_community(self):
        """
        should be able to retrieve moderated rejected posts of a community
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        community_creator = make_user()
        community = make_community(creator=community_creator, type='P')
        community_moderator = make_user()
        community_moderator.join_community_with_name(
            community_name=community.name)
        community_creator.add_moderator_with_username_to_community_with_name(
            username=community_moderator.username,
            community_name=community.name)

        community_name = community.name
        post_reporter = make_user()
        community_posts_ids = []

        amount_of_community_posts = 5

        for i in range(0, amount_of_community_posts):
            community_member = make_user()
            community_member.join_community_with_name(
                community_name=community_name)
            community_member_post = community_member.create_community_post(
                community_name=community.name, text=make_fake_post_text())
            community_posts_ids.append(community_member_post.pk)
            moderation_category = make_moderation_category()
            post_reporter.report_post(post=community_member_post,
                                      category_id=moderation_category.pk)

            moderated_object = ModeratedObject.get_or_create_moderated_object_for_post(
                post=community_member_post, category_id=moderation_category.pk)

            community_moderator.reject_moderated_object(
                moderated_object=moderated_object)

        url = self._get_url(community_name=community.name)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        response_posts = json.loads(response.content)

        self.assertEqual(len(response_posts), len(community_posts_ids))

        for response_post in response_posts:
            response_post_id = response_post.get('id')
            self.assertIn(response_post_id, community_posts_ids)
Exemplo n.º 11
0
    def test_cant_retrieve_reported_following_user_post(self):
        """
        should not be able to retrieve reported following user post
        """
        user = make_user()

        following_user = make_user()
        user.follow_user_with_id(user_id=following_user.pk)

        following_user_post = following_user.create_public_post(text=make_fake_post_text())
        user.report_post(post=following_user_post, category_id=make_moderation_category().pk)

        url = self._get_url(post=following_user_post)
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 12
0
    def test_cant_retrieve_reported_hashtag(self):
        """
        should not be able to retrieve a reported hashtag and return 403
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        hashtag = make_hashtag()
        hashtag_name = hashtag.name

        report_category = make_moderation_category()
        user.report_hashtag_with_name(hashtag_name=hashtag_name,
                                      category_id=report_category.pk)

        url = self._get_url(hashtag_name=hashtag_name)

        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 13
0
    def test_cant_retrieve_reported_connected_user_post(self):
        """
        should not be able to retrieve reported connected user post
        """
        user = make_user()

        connected_user = make_user()
        user.connect_with_user_with_id(user_id=connected_user.pk)
        connected_user_post_circle = make_circle(creator=connected_user)
        connected_user.confirm_connection_with_user_with_id(user_id=user.pk,
                                                            circles_ids=[connected_user_post_circle.pk])
        connected_user_post = connected_user.create_encircled_post(text=make_fake_post_text(),
                                                                   circles_ids=[connected_user_post_circle.pk])
        user.report_post(post=connected_user_post, category_id=make_moderation_category().pk)

        url = self._get_url(post=connected_user_post)
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Exemplo n.º 14
0
    def test_can_search_for_foreign_user_reported_hashtag(self):
        """
        should be able to search for a foreign usre reported hashtag and return 200
        """
        user = make_user()
        headers = make_authentication_headers_for_user(user)

        reporter = make_user()

        hashtag_name = make_hashtag_name()
        hashtag = make_hashtag(name=hashtag_name)

        report_category = make_moderation_category()
        reporter.report_hashtag_with_name(hashtag_name=hashtag_name,
                                          category_id=report_category.pk)

        url = self._get_url()
        response = self.client.get(url, {'query': hashtag.name}, **headers)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        parsed_response = json.loads(response.content)
        self.assertEqual(len(parsed_response), 1)
Exemplo n.º 15
0
    def test_cant_retrieve_reported_community_post(self):
        """
        should not be able to retrieve reported community post
        """
        user = make_user()

        community_creator = make_user()

        community = make_community(creator=community_creator)

        post_creator = make_user()

        user.join_community_with_name(community_name=community.name)
        post_creator.join_community_with_name(community_name=community.name)

        post = post_creator.create_community_post(community_name=community.name, text=make_fake_post_text())
        user.report_post(post=post, category_id=make_moderation_category().pk)

        url = self._get_url(post=post)
        headers = make_authentication_headers_for_user(user)
        response = self.client.get(url, **headers)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)