From 5b677af33b5bc7af2a1ed851f9288bcac3e313d2 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 3 Feb 2017 17:02:34 +0000 Subject: [PATCH] Fix StreamValue != operator on Python 2 --- wagtail/wagtailcore/blocks/stream_block.py | 3 +++ wagtail/wagtailcore/tests/test_blocks.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/wagtail/wagtailcore/blocks/stream_block.py b/wagtail/wagtailcore/blocks/stream_block.py index 40f6a29a2e..1c15904d95 100644 --- a/wagtail/wagtailcore/blocks/stream_block.py +++ b/wagtail/wagtailcore/blocks/stream_block.py @@ -361,6 +361,9 @@ class StreamValue(collections.Sequence): return self.stream_data == other.stream_data + def __ne__(self, other): + return not self.__eq__(other) + def __len__(self): return len(self.stream_data) diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 517d08fc42..726ee53f1a 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -2203,6 +2203,20 @@ class TestStreamBlock(SimpleTestCase): self.assertEqual(stream_value[0].block_type, 'heading') self.assertEqual(stream_value[0].value, 'A different default heading') + def test_stream_value_equality(self): + block = blocks.StreamBlock([ + ('text', blocks.CharBlock()), + ]) + value1 = block.to_python([{'type': 'text', 'value': 'hello'}]) + value2 = block.to_python([{'type': 'text', 'value': 'hello'}]) + value3 = block.to_python([{'type': 'text', 'value': 'goodbye'}]) + + self.assertTrue(value1 == value2) + self.assertFalse(value1 != value2) + + self.assertFalse(value1 == value3) + self.assertTrue(value1 != value3) + class TestPageChooserBlock(TestCase): fixtures = ['test.json']