<commit_before>from tests.base import ApiDBTestCase

from zou.app.services import projects_service


class PermissionTestCase(ApiDBTestCase):
    def setUp(self):
        super(PermissionTestCase, self).setUp()

        self.generate_fixture_user_cg_artist()
        self.user_cg_artist_id = self.user_cg_artist["id"]
        self.generate_fixture_user_manager()
        self.generate_fixture_project_status()
        self.generate_fixture_project()
        self.project_id = self.project.id

    def tearDown(self):
        self.log_out()

    def test_admin_can_create_project(self):
        self.log_in(self.user["email"])
        data = {"name": "Cosmos Landromat 2"}
        self.post("data/projects/", data, 201)

    def test_admin_can_edit_project(self):
        self.log_in(self.user["email"])

    def test_admin_can_read_project(self):
        self.log_in(self.user["email"])

    def test_cg_artist_cannot_create_project(self):
        self.log_in_cg_artist()
        data = {"name": "Cosmos Landromat 2"}
        self.post("data/projects/", data, 403)

    def test_cg_artist_cannot_edit_project(self):
        self.log_in_cg_artist()
        data = {"name": "Cosmos Landromat 2 edited"}
        self.put("data/projects/%s" % self.project_id, data, 403)

    def test_cg_artist_can_read_open_projects(self):
        self.log_in_cg_artist()
        self.get("data/projects/open")

    def test_manager_cannot_create_person(self):
        self.log_in_manager()
        data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "<EMAIL>",
        }
        self.post("data/persons/new", data, 403)

    def test_admin_can_create_person(self):
        self.log_in_admin()
        data = {
            "first_name": "John",
            "last_name": "Doe",<commit_msg>Added tests for task-types and task-status permissions.<commit_after>from tests.base import ApiDBTestCase

from zou.app.services import projects_service


class PermissionTestCase(ApiDBTestCase):
    def setUp(self):
        super(PermissionTestCase, self).setUp()

        self.generate_fixture_user_cg_artist()
        self.user_cg_artist_id = self.user_cg_artist["id"]
        self.generate_fixture_user_manager()
        self.generate_fixture_project_status()
        self.generate_fixture_project()
        self.project_id = self.project.id

    def tearDown(self):
        self.log_out()

    def test_admin_can_create_project(self):
        self.log_in(self.user["email"])
        data = {"name": "Cosmos Landromat 2"}
        self.post("data/projects/", data, 201)

    def test_admin_can_edit_project(self):
        self.log_in(self.user["email"])

    def test_admin_can_read_project(self):
        self.log_in(self.user["email"])

    def test_cg_artist_cannot_create_project(self):
        self.log_in_cg_artist()
        data = {"name": "Cosmos Landromat 2"}
        self.post("data/projects/", data, 403)

    def test_cg_artist_cannot_edit_project(self):
        self.log_in_cg_artist()
        data = {"name": "Cosmos Landromat 2 edited"}
        self.put("data/projects/%s" % self.project_id, data, 403)

    def test_cg_artist_can_read_open_projects(self):
        self.log_in_cg_artist()
        self.get("data/projects/open")

    def test_cg_artist_can_read_project_task_types(self):
        self.generate_fixture_department()
        self.generate_fixture_task_type()
        task_type_id = self.task_type_concept.id
        projects_service.add_task_type_setting(self.project_id, task_type_id, 1)
        self.log_in_cg_artist()
        user_id = str(self.user_cg_artist["id"])
        projects_service.add_team_member(self.project_id, user_id)
        result = self.get("data/projects/%s/task-types" % self.project_id, 200)

        self.assertIsInstance(result, list)
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]['id'], str(task_type_id))

    def test_cg_artist_can_read_project_task_statuses(self):
        self.log_in_cg_artist()
        user_id = str(self.user_cg_artist["id"])
        projects_service.add_team_member(self.project_id, user_id)
        self.get("data/projects/%s/settings/task-status" % self.project_id, 200)

    def test_manager_cannot_create_person(self):
        self.log_in_manager()
        data = {
            "first_name": "John",
            "last_name": "Doe",
            "email": "<EMAIL>",
        }
        self.post("data/persons/new", data, 403)

    def test_admin_can_create_person(self):
        self.log_in_admin()
        data = {
            "first_name": "John",
            "last_name": "Doe",
{'fraction_non_alphanumeric': 0.1171875, 'fraction_numerical': 0.008463541666666666, 'mean_word_length': 2.997398091934085, 'pattern_counts': {'":': 16, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4600497', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1511, 'n_words': 221}