import json import pytest from unittest.mock import patch from tests.test_utils import FixtureLoader from models import models from tests import BaseTestCase, mock_for_user from tests.permissions.fixtures.fixture import fixture lablemateMock = mock_for_user(4, "user-4@example.com", "sme-dna|4rr0091d6cuhjp30fe6opth00", labels=[1]) @patch("auth.atlas.atlas_token_decoder.jwt.decode", lablemateMock.jwt_decode) class TestProjectPermissions(BaseTestCase): update_project_data = { "targets": { "items": [{"id": "artst1", "image": None, "isSony": True, "name": "Mick Gordon"}], "type": "Artist", }, "name": "project_name", "endDate": "2020-10-11", } def setUp(self): super().setUp() FixtureLoader(models=models).import_as_sql(fixture) def test_can_view_list(self): url = "/projects" response = self.execute_get(url, headers=self.headers) self.assertEqual(200, response.status_code) def test_can_view_project(self): url = "/projects/500" response = self.execute_get(url, headers=self.headers) project = response.json self.soft_assert(self.assertEqual, project["userRoles"][0]["categoryIds"], []) self.soft_assert(self.assertEqual, project["userRoles"][0]["id"], 2) self.soft_assert(self.assertEqual, project["userRoles"][0]["name"], "Labelmate") self.assert_all() self.assertEqual(200, response.status_code) def test_can_update_project(self): url = "/projects/500" response = self.execute_put(url, data=json.dumps(self.update_project_data), headers=self.headers) self.assertEqual(403, response.status_code) def test_can_view_project_team(self): url = "/projects/500/team" response = self.client.get(url, headers=self.headers) self.assertEqual(200, response.status_code) def test_cant_manage_project_team(self): url = "/projects/500/team" data = {"added": [{"userId": 6, "roleId": 3, "categoryIds": []}]} response = self.client.post(url, data=json.dumps(data), headers=self.headers) self.assertEqual(403, response.status_code) def test_cant_view_confidential_project(self): url = "/projects/503" response = self.client.get(url, headers=self.headers) self.assertEqual(403, response.status_code)