def test_can_validate_with_errors(self):
        block = TestingStreamBlock()
        block.validate(StreamValue(block, simple_value))

        with self.assertRaises(ValidationError):
            block.validate(StreamValue(block, simple_value),
                           {0: ErrorList([ValidationError('test error')])})
    def test_str_html(self):
        value = StreamValue(TestingStreamBlock(), [])
        self.assertEqual(str(value), '')

        value = StreamValue(TestingStreamBlock(), simple_value)
        self.assertEqual(
            str(value),
            '<div class="block-TestStructBlock"><div class="teststructblock">test</div></div>'
        )
    def test_repr(self):
        value = StreamValue(TestingStreamBlock(), [])
        self.assertEqual(repr(value), '[]')

        value = StreamValue(TestingStreamBlock(), simple_value)
        self.assertEqual(
            repr(value),
            "[<StreamChild id=a71848c8-b773-4ca1-b764-97f439da27ab block=<TestStructBlock> value=StructValue([('value', 'test')])>]"
        )
 def test_to_json(self):
     value = StreamValue(TestingStreamBlock(), simple_value)
     self.assertEqual(value.to_json(), [{
         "id": "a71848c8-b773-4ca1-b764-97f439da27ab",
         "type": "TestStructBlock",
         "value": {
             "value": "test"
         }
     }])
 def test_get_item_when_streamchild(self):
     block = TestStructBlock()
     child = StreamValue.StreamChild(
         block,
         block.to_python({'value': {
             "value": "some value"
         }}),
         id="2042b810-1d85-41cc-92bb-b056e36f47e9")
     value = StreamValue(TestingStreamBlock(), [child])
     self.assertIs(value[0], child)
 def test_to_json(self):
     block = TestingStreamBlock()
     self.assertEqual(block.to_json(None), [])
     self.assertEqual(block.to_json(StreamValue(block, simple_value)),
                      simple_value)
     with self.assertRaises(AttributeError):
         block.to_json("bad type")
 def test_get_item_without_dict_value(self):
     value = StreamValue(TestingStreamBlock(), [{
         "id": str(uuid.uuid4()),
         "type": "TestStructBlock",
         "value": "not a dict"
     }])
     self.assertIsInstance(value[0].block, TestStructBlock)
 def test_get_item_with_missing_type(self):
     value = StreamValue(TestingStreamBlock(), [{
         "id": str(uuid.uuid4()),
         "value": {
             "one": "One",
             "two": 2
         }
     }])
     self.assertIsInstance(value[0].block, UnknownBlock)
 def test_can_find_block_by_name(self):
     value = StreamValue(TestingStreamBlock(), [{
         "id": "2042b810-1d85-41cc-92bb-b056e36f47e9",
         "type": "test",
         "value": {
             "value": "some value"
         },
     }])
     self.assertIsInstance(value[0], BoundBlock)
     self.assertIsInstance(value[0].block, TestStructBlock)
 def test_get_item_bad_data(self):
     '''If we have some bad data in the raw value then we need to throw an error.'''
     value = StreamValue(TestingStreamBlock(), ["one"])
     with self.assertRaises(ValueError):
         value[0]
 def test_get_item(self):
     value = StreamValue(TestingStreamBlock(), simple_value)
     first_item = value[0]
     self.assertIsInstance(first_item, StreamValue.StreamChild)
     self.assertEqual(first_item.id, simple_value[0]['id'])
 def test_get_searchable_content(self):
     block = TestingStreamBlock()
     content = block.get_searchable_content(StreamValue(
         block, simple_value))
     self.assertEqual(len(content), 1)
     self.assertEqual(content, ["test"])
 def test_can_create(self):
     StreamValue(TestingStreamBlock(), [])
     StreamValue(TestingStreamBlock(), simple_value)
     StreamValue(TestingStreamBlock(), simple_value[0])
    def test_len(self):
        value = StreamValue(TestingStreamBlock(), [])
        self.assertEqual(len(value), 0)

        value = StreamValue(TestingStreamBlock(), simple_value)
        self.assertEqual(len(value), 1)
 def test_get_item_with_missing_value(self):
     value = StreamValue(TestingStreamBlock(), [{
         "id": str(uuid.uuid4()),
         "type": "TestStructBlock",
     }])
     self.assertIsInstance(value[0].block, TestStructBlock)