<commit_before>from django.test import RequestFactory
from django.core.urlresolvers import reverse

from bluebottle.test.factory_models.accounts import BlueBottleUserFactory
from bluebottle.test.factory_models.projects import ProjectFactory
from bluebottle.test.factory_models.rewards import RewardFactory
from bluebottle.test.utils import BluebottleTestCase


# RequestFactory used for integration tests.
factory = RequestFactory()


class ProjectPermissionsTestCase(BluebottleTestCase):
    """
    Tests for the Project API permissions.
    """
    def setUp(self):
        super(ProjectPermissionsTestCase, self).setUp()
        self.init_projects()

        self.owner = BlueBottleUserFactory.create()
        self.owner_token = "JWT {0}".format(self.owner.get_jwt_token())

        self.not_owner = BlueBottleUserFactory.create()
        self.not_owner_token = "JWT {0}".format(self.not_owner.get_jwt_token())
        self.project = ProjectFactory.create(owner=self.owner)
        RewardFactory.create(project=self.project)
        RewardFactory.create(project=self.project)

        self.project_manage_url = reverse(
            'project_manage_detail', kwargs={'slug': self.project.slug}
        )

        self.project_detail_url = reverse(
            'project_detail', kwargs={'slug': self.project.slug}
        )

    def test_manage_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_manage_url, token=self.owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )
        self.assertEqual(
            response.data['permissions']['PUT'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], True
        )

        self.assertEqual(
            response.data['related_permissions']['donations']['GET'], True
        )
        self.assertEqual(
            response.data['related_permissions']['donations']['POST'], True
        )


    def test_manage_non_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_manage_url, token=self.not_owner_token)
        self.assertEqual(response.status_code, 403)

    def test_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url, token=self.owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], True
        )


    def test_non_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url, token=self.not_owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], False
        )

    def test_anonymous_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], False
        )

        self.assertEqual(
            response.data['related_permissions']['donations']['GET'], False
        )
        self.assertEqual(
            response.data['related_permissions']['donations']['POST'], True
        )


<commit_msg>Fix styling<commit_after>from django.test import RequestFactory
from django.core.urlresolvers import reverse

from bluebottle.test.factory_models.accounts import BlueBottleUserFactory
from bluebottle.test.factory_models.projects import ProjectFactory
from bluebottle.test.factory_models.rewards import RewardFactory
from bluebottle.test.utils import BluebottleTestCase


# RequestFactory used for integration tests.
factory = RequestFactory()


class ProjectPermissionsTestCase(BluebottleTestCase):
    """
    Tests for the Project API permissions.
    """
    def setUp(self):
        super(ProjectPermissionsTestCase, self).setUp()
        self.init_projects()

        self.owner = BlueBottleUserFactory.create()
        self.owner_token = "JWT {0}".format(self.owner.get_jwt_token())

        self.not_owner = BlueBottleUserFactory.create()
        self.not_owner_token = "JWT {0}".format(self.not_owner.get_jwt_token())
        self.project = ProjectFactory.create(owner=self.owner)
        RewardFactory.create(project=self.project)
        RewardFactory.create(project=self.project)

        self.project_manage_url = reverse(
            'project_manage_detail', kwargs={'slug': self.project.slug}
        )

        self.project_detail_url = reverse(
            'project_detail', kwargs={'slug': self.project.slug}
        )

    def test_manage_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_manage_url, token=self.owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )
        self.assertEqual(
            response.data['permissions']['PUT'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], True
        )

        self.assertEqual(
            response.data['related_permissions']['donations']['GET'], True
        )
        self.assertEqual(
            response.data['related_permissions']['donations']['POST'], True
        )

    def test_manage_non_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_manage_url, token=self.not_owner_token)
        self.assertEqual(response.status_code, 403)

    def test_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url, token=self.owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], True
        )

    def test_non_owner_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url, token=self.not_owner_token)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], False
        )

    def test_anonymous_permissions(self):
        # view allowed
        response = self.client.get(self.project_detail_url)
        self.assertEqual(response.status_code, 200)

        self.assertEqual(
            response.data['permissions']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['GET'], True
        )

        self.assertEqual(
            response.data['related_permissions']['rewards']['POST'], False
        )

        self.assertEqual(
            response.data['related_permissions']['donations']['GET'], False
        )
        self.assertEqual(
            response.data['related_permissions']['donations']['POST'], True
        )

{'fraction_non_alphanumeric': 0.11700581395348837, 'fraction_numerical': 0.004118217054263566, 'mean_word_length': 2.7531818181818184, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6951090', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2194, 'n_words': 327}