From 5ee3c0d54f1e55edf8d8cbeb62fd00ba8a35752b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 4 Nov 2016 16:31:03 +0100 Subject: [PATCH] Ensure used_in_edit is always set on new shots. --- attract/shots/eve_hooks.py | 12 ++++++++++++ tests/test_shots.py | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/attract/shots/eve_hooks.py b/attract/shots/eve_hooks.py index 514ace1..5013faf 100644 --- a/attract/shots/eve_hooks.py +++ b/attract/shots/eve_hooks.py @@ -79,6 +79,17 @@ def activity_after_creating_shots(nodes): activity_after_creating_shot(node) +@only_for_shot +def set_default_used_in_edit(shot): + """Ensures that used_in_edit is always set.""" + shot.setdefault('properties', {}).setdefault('used_in_edit', True) + + +def nodes_set_default_used_in_edit(nodes): + for node in nodes: + set_default_used_in_edit(node) + + @only_for_shot def activity_after_deleting_shot(shot): register_shot_activity(shot, 'deleted shot "%s"' % shot['name']) @@ -86,6 +97,7 @@ def activity_after_deleting_shot(shot): def setup_app(app): app.on_replaced_nodes += activity_after_replacing_shot + app.on_insert_nodes += nodes_set_default_used_in_edit app.on_inserted_nodes += activity_after_creating_shots app.on_deleted_item_nodes += activity_after_deleting_shot app.on_deleted_resource_nodes += activity_after_deleting_shot diff --git a/tests/test_shots.py b/tests/test_shots.py index 527360c..763ff20 100644 --- a/tests/test_shots.py +++ b/tests/test_shots.py @@ -347,7 +347,7 @@ class PatchShotTest(AbstractShotTest): url = '/api/nodes/%s' % shot._id dbnode = self.get(url, auth_token='token').json() - self.assertNotIn('used_in_edit', dbnode['properties']) + self.assertTrue(dbnode['properties']['used_in_edit']) patch = {'op': 'unlink'} self.patch(url, json=patch, auth_token='token') @@ -383,12 +383,12 @@ class PatchShotTest(AbstractShotTest): self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token') url = '/api/nodes/%s' % shot._id + self.patch(url, json={'op': 'unlink'}, auth_token='token') dbnode = self.get(url, auth_token='token').json() - self.assertNotIn('used_in_edit', dbnode['properties']) + self.assertFalse(dbnode['properties']['used_in_edit']) - patch = {'op': 'relink'} - self.patch(url, json=patch, auth_token='token') + self.patch(url, json={'op': 'relink'}, auth_token='token') dbnode = self.get(url, auth_token='token').json() self.assertTrue(dbnode['properties']['used_in_edit'])