From 497bbb82738ffb59a6adaebae5732ace910b3883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 10 Nov 2016 09:34:32 +0100 Subject: [PATCH] Editing the name of a shot/task/asset now logs the old and new name in the activity --- attract/shots_and_assets/eve_hooks.py | 3 ++- attract/tasks/eve_hooks.py | 3 ++- tests/test_shots.py | 28 ++++++++++++++++++++++++++ tests/test_tasks.py | 29 +++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/attract/shots_and_assets/eve_hooks.py b/attract/shots_and_assets/eve_hooks.py index b91fcc1..1597505 100644 --- a/attract/shots_and_assets/eve_hooks.py +++ b/attract/shots_and_assets/eve_hooks.py @@ -76,8 +76,9 @@ def activity_after_replacing_shot_asset(shot_or_asset, original): val_shot = val_shot[:80] + u'…' if descr is None: + # A name change activity contains both the old and the new name. descr = 'changed "%s" to "%s" in %s "%s"' % \ - (human_key, val_shot, typename, shot_or_asset['name']) + (human_key, val_shot, typename, original['name']) else: descr = 'edited %s "%s"' % (typename, shot_or_asset['name']) diff --git a/attract/tasks/eve_hooks.py b/attract/tasks/eve_hooks.py index fd82fff..3a81108 100644 --- a/attract/tasks/eve_hooks.py +++ b/attract/tasks/eve_hooks.py @@ -154,7 +154,8 @@ def activity_after_replacing_task(task, original): val_task = val_task[:80] + u'…' if descr is None: - descr = 'changed %s to "%s" in task "%s"' % (human_key, val_task, task['name']) + # A name change activity contains both the old and the new name. + descr = 'changed %s to "%s" in task "%s"' % (human_key, val_task, original['name']) else: descr = 'edited task "%s"' % task['name'] diff --git a/tests/test_shots.py b/tests/test_shots.py index d46f4d4..e8efc51 100644 --- a/tests/test_shots.py +++ b/tests/test_shots.py @@ -170,6 +170,34 @@ class PatchShotTest(AbstractShotTest): self.assertEqual(123, dbnode['properties']['trim_start_in_frames']) self.assertEqual(u'on_hold', dbnode['properties']['status']) + @responses.activate + def test_patch_activity(self): + """Perform the edit, then check the resulting activity on the shot.""" + shot = self.create_shot() + self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token') + + url = '/api/nodes/%s' % shot._id + + # Only change the name -- the activity should contain both the old and the new name. + old_name = shot['name'] + new_name = u'"shot" is "geschoten" in Dutch' + patch = { + 'op': 'from-blender', + '$set': { + 'name': new_name, + } + } + self.patch(url, json=patch, auth_token='token') + + with self.app.test_request_context(): + acts = self.app.pillar_extensions['attract'].activities_for_node(shot._id) + self.assertEqual(2, acts['_meta']['total']) # Creation + edit + edit_act = acts['_items'][1] + self.assertIn(old_name, edit_act['verb']) + self.assertIn(new_name, edit_act['verb']) + + pass + @responses.activate def test_patch_from_web_happy(self): shot = self.create_shot() diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 266af5f..1f2bd77 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -84,6 +84,35 @@ class TaskWorkflowTest(AbstractAttractTest): self.assertEqual(u'nööw name', found['name']) self.assertEqual(u'€ ≠ ¥', found['description']) + @responses.activate + def test_edit_activity(self): + """Perform the edit, then check the resulting activity on the shot.""" + task = self.create_task() + + # Only change the name -- the activity should contain both the old and the new name. + old_name = task['name'] + new_name = u'nööw name' + + with self.app.test_request_context(): + # Log in as project admin user + pillar.auth.login_user(ctd.EXAMPLE_PROJECT_OWNER_ID) + + self.mock_blenderid_validate_happy() + self.mngr.edit_task(task._id, + task_type=task['properties'].task_type, + name=new_name, + description=task.description, + status=u'todo', + _etag=task._etag) + + with self.app.test_request_context(): + acts = self.app.pillar_extensions['attract'].activities_for_node(task['_id']) + self.assertEqual(2, acts['_meta']['total']) # Creation + edit + + edit_act = acts['_items'][1] + self.assertIn(old_name, edit_act['verb']) + self.assertIn(new_name, edit_act['verb']) + @responses.activate def test_load_save_task(self): """Test for the Eve hooks -- we should be able to PUT what we GET."""