From a285458b48f201356f199e76bcb0f9e82cc81dee Mon Sep 17 00:00:00 2001 From: Justin Crown Date: Fri, 28 Jun 2019 10:27:25 -0700 Subject: [PATCH] video_saved signal noop when raw --- tests/test_models.py | 23 +++++++++++++++++++++++ wagtailvideos/models.py | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 tests/test_models.py diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..b95ec59 --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,23 @@ +from __future__ import unicode_literals + +from unittest.mock import Mock + +from django.core.files.uploadedfile import SimpleUploadedFile +from django.test import TestCase, override_settings +from wagtail.tests.utils import WagtailTestUtils + +from tests.utils import create_test_video_file +from wagtailvideos.models import Video, video_saved + +class TestVideoModel(WagtailTestUtils, TestCase): + + def test_post_save_signal_raw(self): + ''' + When called with the 'raw' kwarg, the post_save signal handler should + do nothing. We will test this by asserting that it never calls save + on the instance. + ''' + mocked_instance = Mock() + del mocked_instance._from_signal + video_saved(Video, mocked_instance, raw=True) + assert not mocked_instance.save.called diff --git a/wagtailvideos/models.py b/wagtailvideos/models.py index 122b2ba..5133b50 100644 --- a/wagtailvideos/models.py +++ b/wagtailvideos/models.py @@ -324,6 +324,9 @@ def video_saved(sender, instance, **kwargs): if not ffmpeg.installed(): return + if 'raw' in kwargs and kwargs['raw']: + return + if hasattr(instance, '_from_signal'): return