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 editorMock = mock_for_user(3, "user-3@example.com", "sme-dna|9op0091d6cuhjp30fe6ffth34") @patch("auth.atlas.atlas_token_decoder.jwt.decode", editorMock.jwt_decode) class TestProjectPermissions(BaseTestCase): update_project_data = { "targets": { "items": [{"id": "GRAS_122121", "image": None, "isSony": True, "name": "Mick Gordon"}], "type": "Artist", }, "name": "project_name", "endDate": "2020-10-11", "startDate": "2007-05-01", } 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]["id"], 1) self.soft_assert(self.assertEqual, project["userRoles"][0]["name"], "Editor") 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(200, 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_can_manage_project_team(self): url = "/projects/500/team" data = {"added": [{"userId": 6, "roleId": 4, "categoryIds": []}]} response = self.client.post(url, data=json.dumps(data), headers=self.headers) self.assertEqual(200, response.status_code)