Using patch to edit shots from web-frontend.

This commit is contained in:
2016-10-04 14:16:58 +02:00
parent 459ba6c89f
commit 91abe917cd
4 changed files with 82 additions and 23 deletions

View File

@@ -91,6 +91,7 @@ class ShotManagerTest(AbstractShotTest):
@responses.activate
def test_edit_shot(self):
shot = self.create_shot()
pre_edit_shot = shot.to_dict()
with self.app.test_request_context():
# Log in as project admin user
@@ -98,25 +99,27 @@ class ShotManagerTest(AbstractShotTest):
self.mock_blenderid_validate_happy()
self.assertRaises(sdk_exceptions.PreconditionFailed,
self.smngr.edit_shot,
shot_id=shot['_id'],
name=u'ผัดไทย',
description=u'Shoot the Pad Thai',
status='todo',
_etag='jemoeder')
# No Etag checking, see T49555
# self.assertRaises(sdk_exceptions.PreconditionFailed,
# self.smngr.edit_shot,
# shot_id=shot['_id'],
# name=u'ผัดไทย',
# description=u'Shoot the Pad Thai',
# status='todo',
# _etag='jemoeder')
self.smngr.edit_shot(shot_id=shot['_id'],
name=u'ผัดไทย',
description=u'Shoot the Pad Thai',
status='todo',
notes=None,
_etag=shot._etag)
# Test directly with MongoDB
with self.app.test_request_context():
nodes_coll = self.app.data.driver.db['nodes']
found = nodes_coll.find_one(ObjectId(shot['_id']))
self.assertEqual(u'ผัดไทย', found['name'])
self.assertEqual(pre_edit_shot['name'], found['name']) # shouldn't be edited.
self.assertEqual(u'todo', found['properties']['status'])
self.assertEqual(u'Shoot the Pad Thai', found['description'])
self.assertNotIn(u'notes', found['properties'])
@@ -189,14 +192,66 @@ class PatchShotTest(AbstractShotTest):
patch = {
'op': 'from-blender',
'$set': {
'name': u'"shot" is "geschoten" in Dutch',
'properties.trim_start_in_frames': 123,
'properties.duration_in_edit_in_frames': 4215,
'properties.cut_in_timeline_in_frames': 1245,
'properties.status': 'todo',
'properties.status': u'on_hold',
}
}
self.patch(url, json=patch, auth_token='token')
dbnode = self.get(url, auth_token='token').json()
self.assertEqual(u'"shot" is "geschoten" in Dutch', dbnode['name'])
self.assertEqual(123, dbnode['properties']['trim_start_in_frames'])
self.assertEqual(u'on_hold', dbnode['properties']['status'])
@responses.activate
def test_patch_from_web_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-web',
'$set': {
'description': u'Таким образом, этот человек заходит в бар, и говорит…',
'properties.notes': u'Два бокала вашей лучшей водки, пожалуйста.',
'properties.status': u'final',
}
}
self.patch(url, json=patch, auth_token='token')
dbnode = self.get(url, auth_token='token').json()
self.assertEqual(u'Таким образом, этот человек заходит в бар, и говорит…',
dbnode['description'])
self.assertEqual(u'Два бокала вашей лучшей водки, пожалуйста.',
dbnode['properties']['notes'])
self.assertEqual(u'final', dbnode['properties']['status'])
self.assertEqual(u'New shot', dbnode['name'])
@responses.activate
def test_patch_from_web_happy_nones(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-web',
'$set': {
'description': None,
'properties.notes': None,
'properties.status': u'final',
}
}
self.patch(url, json=patch, auth_token='token')
dbnode = self.get(url, auth_token='token').json()
self.assertNotIn('description', dbnode)
self.assertNotIn('notes', dbnode['properties'])
self.assertEqual(u'final', dbnode['properties']['status'])
self.assertEqual(u'New shot', dbnode['name'])
@responses.activate
def test_patch_bad_op(self):
shot = self.create_shot()