def test_list_block_factory():
    value = MyBlockFactory(items__0__label='label-1',
                           items__0__value=1,
                           items__1__label='label-2',
                           items__1__value=2,
                           image__image=None)

    assert value == StructValue(None, [
        ('title', 'my title'),
        ('item', OrderedDict([
            ('label', 'my-label'),
            ('value', 100),
        ])),
        ('items', [
            StructValue(None, [
                ('label', 'label-1'),
                ('value', 1),
            ]),
            StructValue(None, [
                ('label', 'label-2'),
                ('value', 2),
            ]),
        ]),
        ('image', None),
    ])
def test_block_factory_subkwarg():
    value = MyBlockFactory(item__label="my-label",
                           item__value=20,
                           image__image=None)

    assert value == OrderedDict([
        ("title", "my title"),
        ("item", OrderedDict([("label", "my-label"), ("value", 20)])),
        ("items", []),
        ("image", None),
    ])
def test_block_factory_build():
    value = MyBlockFactory.build(image__image__title="blub")

    image = value.pop("image")
    assert image.title == "blub"

    assert value == OrderedDict([
        ("title", "my title"),
        ("item", OrderedDict([("label", "my-label"), ("value", 100)])),
        ("items", []),
    ])
def test_block_factory():
    value = MyBlockFactory(image__image__title="blub")

    assert value == OrderedDict([
        ("title", "my title"),
        ("item", OrderedDict([("label", "my-label"), ("value", 100)])),
        ("items", []),
        ("image", Image.objects.first()),
    ])

    assert value["image"].title == "blub"
def test_block_factory_subkwarg():
    value = MyBlockFactory(item__label='my-label',
                           item__value=20,
                           image__image=None)

    assert value == OrderedDict([
        ('title', 'my title'),
        ('item', OrderedDict([
            ('label', 'my-label'),
            ('value', 20),
        ])),
        ('items', []),
        ('image', None),
    ])
def test_block_factory_build():
    value = MyBlockFactory.build(image__image__title='blub')

    image = value.pop('image')
    assert image.title == 'blub'

    assert value == OrderedDict([
        ('title', 'my title'),
        ('item', OrderedDict([
            ('label', 'my-label'),
            ('value', 100),
        ])),
        ('items', []),
    ])
def test_block_factory():
    value = MyBlockFactory(image__image__title='blub')

    assert value == OrderedDict([
        ('title', 'my title'),
        ('item', OrderedDict([
            ('label', 'my-label'),
            ('value', 100),
        ])),
        ('items', []),
        ('image', Image.objects.first()),
    ])

    assert value['image'].title == 'blub'
def test_list_block_factory():
    value = MyBlockFactory(
        items__0__label="label-1",
        items__0__value=1,
        items__1__label="label-2",
        items__1__value=2,
        image__image=None,
    )

    assert value == StructValue(
        None,
        [
            ("title", "my title"),
            ("item", OrderedDict([("label", "my-label"), ("value", 100)])),
            (
                "items",
                [
                    StructValue(None, [("label", "label-1"), ("value", 1)]),
                    StructValue(None, [("label", "label-2"), ("value", 2)]),
                ],
            ),
            ("image", None),
        ],
    )