<commit_before>from ckan.lib import search
from ckan.plugins import toolkit
try:
    from ckan.tests import helpers
    from ckan.tests import factories
except ImportError:
    from ckan.new_tests import helpers
    from ckan.new_tests import factories
from ckan.tests.helpers import assert_in

from ckanext.issues.tests import factories as issue_factories
from ckanext.issues import model


class TestModeration(helpers.FunctionalTestBase):
    @classmethod
    def setup_class(cls):
        super(TestModeration, cls).setup_class()
        helpers.reset_db()
        search.clear()

    def setup(self):
        self.user = factories.User()
        self.organization = factories.Organization(user=self.user)

        self.dataset = factories.Dataset(user=self.user,
                                         owner_org=self.organization['name'],
                                         private=True)

        self.issue = issue_factories.Issue(user=self.user,
                                           user_id=self.user['id'],
                                           dataset_id=self.dataset['id'])

    def test_moderate_all_organization_issues(self):
        app = self._get_test_app()
        env = {'REMOTE_USER': self.user['name'].encode('ascii')}

        issue = model.Issue.get(self.issue['id'])
        issue.visibility = 'hidden'
        issue.save()

        response = app.get(
            url=toolkit.url_for('issues_moderate_reported_issues',
                                organization_id=self.organization['id']),
            extra_environ=env,
        )
        assert_in(self.issue['title'], response)
        assert_in(self.issue['description'], response)


class TestCommentModeration(helpers.FunctionalTestBase):
    @classmethod
    def setup_class(cls):
        super(TestCommentModeration, cls).setup_class()
        helpers.reset_db()
        search.clear()

    def setup(self):
        self.user = factories.User()
        self.organization = factories.Organization(user=self.user)

        self.dataset = factories.Dataset(user=self.user,
                                         owner_org=self.organization['name'],
                                         private=True)

        self.issue = issue_factories.Issue(user=self.user,
                                           user_id=self.user['id'],
                                           dataset_id=self.dataset['id'])
        self.comment = issue_factories.IssueComment(
            dataset_id=self.dataset['id'],
            issue_number=self.issue['number'],
            comment='this is a comment',
        )

    def test_moderate_all_organization_issues(self):
        app = self._get_test_app()
        env = {'REMOTE_USER': self.user['name'].encode('ascii')}

        comment = model.Issue.get(self.issue['id'])
        comment.visibility = 'hidden'
        comment.save()

        response = app.get(
            url=toolkit.url_for('issues_moderate_reported_comments',
                                organization_id=self.organization['id']),
            extra_environ=env,
        )
        assert_in(self.comment['comment'], response)<commit_msg>fix test<commit_after>from ckan.lib import search
from ckan.plugins import toolkit
try:
    from ckan.tests import helpers
    from ckan.tests import factories
except ImportError:
    from ckan.new_tests import helpers
    from ckan.new_tests import factories
from ckan.tests.helpers import assert_in

from ckanext.issues.tests import factories as issue_factories
from ckanext.issues import model


class TestModeration(helpers.FunctionalTestBase):
    @classmethod
    def setup_class(cls):
        super(TestModeration, cls).setup_class()
        helpers.reset_db()
        search.clear()

    def setup(self):
        self.user = factories.User()
        self.organization = factories.Organization(user=self.user)

        self.dataset = factories.Dataset(user=self.user,
                                         owner_org=self.organization['name'],
                                         private=True)

        self.issue = issue_factories.Issue(user=self.user,
                                           user_id=self.user['id'],
                                           dataset_id=self.dataset['id'])

    def test_moderate_all_organization_issues(self):
        app = self._get_test_app()
        env = {'REMOTE_USER': self.user['name'].encode('ascii')}

        issue = model.Issue.get(self.issue['id'])
        issue.visibility = 'hidden'
        issue.save()

        response = app.get(
            url=toolkit.url_for('issues_moderate_reported_issues',
                                organization_id=self.organization['id']),
            extra_environ=env,
        )
        assert_in(self.issue['title'], response)
        assert_in(self.issue['description'], response)


class TestCommentModeration(helpers.FunctionalTestBase):
    @classmethod
    def setup_class(cls):
        super(TestCommentModeration, cls).setup_class()
        helpers.reset_db()
        search.clear()

    def setup(self):
        self.user = factories.User()
        self.organization = factories.Organization(user=self.user)

        self.dataset = factories.Dataset(user=self.user,
                                         owner_org=self.organization['name'])

        self.issue = issue_factories.Issue(user=self.user,
                                           user_id=self.user['id'],
                                           dataset_id=self.dataset['id'])
        self.comment = issue_factories.IssueComment(
            dataset_id=self.dataset['id'],
            issue_number=self.issue['number'],
            comment='this is a comment',
        )

    def test_moderate_all_organization_issues(self):
        app = self._get_test_app()
        env = {'REMOTE_USER': self.user['name'].encode('ascii')}

        comment = model.IssueComment.get(self.comment['id'])
        comment.visibility = 'hidden'
        comment.save()

        response = app.get(
            url=toolkit.url_for('issues_moderate_reported_comments',
                                organization_id=self.organization['id']),
            extra_environ=env,
        )
        assert_in(self.comment['comment'], response)
{'fraction_non_alphanumeric': 0.10447043742989906, 'fraction_numerical': 0.0, 'mean_word_length': 2.044878048780488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4734444', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1610, 'n_words': 269}