<commit_before>import json

from rest_framework import status

from hs_core.hydroshare import resource
from hs_access_control.models import PrivilegeCodes
from .base import HSRESTTestCase
from hs_core.hydroshare import users


class TestSetAccessRules(HSRESTTestCase):
    def setUp(self):
        super(TestSetAccessRules, self).setUp()
        self.secondUser = users.create_account(
            '<EMAIL>',
            username='testuser1',
            first_name='some_first_name1',
            last_name='some_last_name1',
            groups=[],
            superuser=False)
        self.testGroup = self.user.uaccess.create_group(
            title="Test Group",
            description="Group for testing")

    def tearDown(self):
        super(TestSetAccessRules, self).tearDown()
        self.secondUser.delete()
        self.testGroup.delete()

    def test_DEPRECATED_set_access_rules(self):
        rtype = 'GenericResource'
        title = 'My Test resource'
        keywords = ('foo', 'bar')
        abstract = 'This is a resource used for testing /hsapi/accessRules'
        new_res = resource.create_resource(rtype,
                                           self.user,
                                           title,
                                           keywords=keywords)
        new_res.metadata.create_element('description', abstract=abstract)
        res_id = new_res.short_id
        self.resources_to_delete.append(res_id)

        sysmeta_url = "/hsapi/sysmeta/{res_id}/".format(res_id=res_id)
        response = self.client.get(sysmeta_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        self.assertEqual(content['resource_type'], rtype)
        self.assertEqual(content['resource_title'], title)
        self.assertFalse(content['public'])

        access_url = "/hsapi/resource/accessRules/{res_id}/".format(res_id=res_id)
        response = self.client.put(access_url, {'public': True})
        # the resource does not have content file, so it cannot be made public
        self.assertEqual(response.status_code, status.status.HTTP_403_FORBIDDEN)

        response = self.client.get(sysmeta_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        self.assertFalse(content['public'])
<commit_msg>updated comment just to kick off jenkin build for the PR<commit_after>import json

from rest_framework import status

from hs_core.hydroshare import resource
from hs_access_control.models import PrivilegeCodes
from .base import HSRESTTestCase
from hs_core.hydroshare import users


class TestSetAccessRules(HSRESTTestCase):
    def setUp(self):
        super(TestSetAccessRules, self).setUp()
        self.secondUser = users.create_account(
            '<EMAIL>',
            username='testuser1',
            first_name='some_first_name1',
            last_name='some_last_name1',
            groups=[],
            superuser=False)
        self.testGroup = self.user.uaccess.create_group(
            title="Test Group",
            description="Group for testing")

    def tearDown(self):
        super(TestSetAccessRules, self).tearDown()
        self.secondUser.delete()
        self.testGroup.delete()

    def test_DEPRECATED_set_access_rules(self):
        rtype = 'GenericResource'
        title = 'My Test resource'
        keywords = ('foo', 'bar')
        abstract = 'This is a resource used for testing /hsapi/accessRules'
        new_res = resource.create_resource(rtype,
                                           self.user,
                                           title,
                                           keywords=keywords)
        new_res.metadata.create_element('description', abstract=abstract)
        res_id = new_res.short_id
        self.resources_to_delete.append(res_id)

        sysmeta_url = "/hsapi/sysmeta/{res_id}/".format(res_id=res_id)
        response = self.client.get(sysmeta_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        self.assertEqual(content['resource_type'], rtype)
        self.assertEqual(content['resource_title'], title)
        self.assertFalse(content['public'])

        access_url = "/hsapi/resource/accessRules/{res_id}/".format(res_id=res_id)
        response = self.client.put(access_url, {'public': True})
        # this test resource does not have content file, so it cannot be made public
        self.assertEqual(response.status_code, status.status.HTTP_403_FORBIDDEN)

        response = self.client.get(sysmeta_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        content = json.loads(response.content)
        self.assertFalse(content['public'])

{'fraction_non_alphanumeric': 0.09618988132417239, 'fraction_numerical': 0.004996876951905059, 'mean_word_length': 2.5323529411764705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4732056', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1303, 'n_words': 253}