Allow limited PATCHing of shots from Blender and Web.

Soon PATCH should become the only way in which shots are edited, so
we should possibly remove PUT permissions.
This commit is contained in:
2016-09-23 17:17:07 +02:00
parent 56567532ff
commit 13c67e3ab8
2 changed files with 235 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-
import unittest
import responses
from bson import ObjectId
@@ -12,7 +14,7 @@ import pillar.tests.common_test_data as ctd
from abstract_attract_test import AbstractAttractTest
class ShotManagerTest(AbstractAttractTest):
class AbstractShotTest(AbstractAttractTest):
def setUp(self, **kwargs):
AbstractAttractTest.setUp(self, **kwargs)
@@ -45,6 +47,7 @@ class ShotManagerTest(AbstractAttractTest):
self.assertIsInstance(shot, pillarsdk.Node)
return shot
class ShotManagerTest(AbstractShotTest):
@responses.activate
def test_tasks_for_shot(self):
shot1 = self.create_shot()
@@ -117,3 +120,144 @@ class ShotManagerTest(AbstractAttractTest):
self.assertEqual(u'todo', found['properties']['status'])
self.assertEqual(u'Shoot the Pad Thai', found['description'])
self.assertNotIn(u'notes', found['properties'])
class NodeSetattrTest(unittest.TestCase):
def test_simple(self):
from attract.shots import node_setattr
node = {}
node_setattr(node, 'a', 5)
self.assertEqual({'a': 5}, node)
node_setattr(node, 'b', {'complexer': 'value'})
self.assertEqual({'a': 5, 'b': {'complexer': 'value'}}, node)
def test_dotted(self):
from attract.shots import node_setattr
node = {}
self.assertRaises(KeyError, node_setattr, node, 'a.b', 5)
node = {'b': {}}
node_setattr(node, 'b.simple', 'value')
self.assertEqual({'b': {'simple': 'value'}}, node)
node_setattr(node, 'b.complex', {'yes': 'value'})
self.assertEqual({'b': {'simple': 'value',
'complex': {'yes': 'value'}}}, node)
node_setattr(node, 'b.complex', {'yes': 5})
self.assertEqual({'b': {'simple': 'value',
'complex': {'yes': 5}}}, node)
def test_none_simple(self):
from attract.shots import node_setattr
node = {}
node_setattr(node, 'a', None)
node_setattr(node, None, 'b')
self.assertEqual({'a': None, None: 'b'}, node)
def test_none_dotted(self):
from attract.shots import node_setattr
node = {}
self.assertRaises(KeyError, node_setattr, node, 'a.b', None)
node = {'b': {}}
node_setattr(node, 'b.simple', None)
self.assertEqual({'b': {'simple': None}}, node)
node_setattr(node, 'b.complex', {'yes': None})
self.assertEqual({'b': {'simple': None,
'complex': {'yes': None}}}, node)
node_setattr(node, 'b.complex', {None: 5})
self.assertEqual({'b': {'simple': None,
'complex': {None: 5}}}, node)
class PatchShotTest(AbstractShotTest):
@responses.activate
def test_patch_from_blender_happy(self):
shot = self.create_shot()
self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token')
url = '/api/nodes/%s' % shot._id
patch = {
'op': 'from-blender',
'$set': {
'properties.trim_start_in_frames': 123,
'properties.duration_in_edit_in_frames': 4215,
'properties.cut_in_timeline_in_frames': 1245,
'properties.status': 'todo',
}
}
self.patch(url, json=patch, auth_token='token')
@responses.activate
def test_patch_bad_op(self):
shot = self.create_shot()
self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token')
url = '/api/nodes/%s' % shot._id
patch = {'properties.status': 'todo'}
self.patch(url, json=patch, auth_token='token', expected_status=400)
@responses.activate
def test_patch_from_blender_bad_fields(self):
shot = self.create_shot()
self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token')
url = '/api/nodes/%s' % shot._id
patch = {
'op': 'from-blender',
'$set': {
'invalid.property': 'JE MOEDER',
}
}
self.patch(url, json=patch, auth_token='token', expected_status=400)
@responses.activate
def test_patch_from_blender_bad_status(self):
shot = self.create_shot()
self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token')
url = '/api/nodes/%s' % shot._id
patch = {
'op': 'from-blender',
'$set': {
'properties.status': 'JE MOEDER',
}
}
self.patch(url, json=patch, auth_token='token', expected_status=422)
@responses.activate
def test_patch_unauthenticated(self):
shot = self.create_shot()
url = '/api/nodes/%s' % shot._id
patch = {
'op': 'from-blender',
'$set': {
'properties.status': 'in_progress',
}
}
self.patch(url, json=patch, expected_status=403)
@responses.activate
def test_patch_bad_user(self):
shot = self.create_shot()
self.create_user(24 * 'a')
self.create_valid_auth_token(24 * 'a', 'other')
url = '/api/nodes/%s' % shot._id
patch = {
'op': 'from-blender',
'$set': {
'properties.status': 'in_progress',
}
}
self.patch(url, json=patch, auth_token='other', expected_status=403)