wagtail / wagtail-factories

Factory boy classes for wagtail
http://wagtail-factories.readthedocs.io/en/latest/
MIT License
102 stars 40 forks source link

ListBlockFactory is not working in StruckBockFactory #47

Closed muhtarcangoktas closed 3 years ago

muhtarcangoktas commented 3 years ago

ListBlockFactory is not working in StruckBockFactory and this case hasn't been tested.

I added new item to items in test_custom_page_streamfield_data_complex

@pytest.mark.django_db
def test_custom_page_streamfield_data_complex():
    assert Image.objects.count() == 0

    root_page = wagtail_factories.PageFactory(parent=None)
    page = MyTestPageWithStreamFieldFactory(
        parent=root_page,
        body__0__char_array__0="foo",
        body__0__char_array__1="bar",
        body__2__int_array__0=100,
        body__1__struct__title="My Title",
        body__1__struct__item__value=100,
        body__1__struct__image__image=None,
        body__3__image__image__title="Blub",
        body__4__struct__items__0__label="Test",  # < Added
        body__4__struct__items__0__value=200  # < Added
    )
    assert Image.objects.count() == 1
    image = Image.objects.first()

    assert page.body[0].block_type == "char_array"
    assert page.body[0].value == ["foo", "bar"]

    assert page.body[1].block_type == "struct"
    assert page.body[1].value == StructValue(
        None,
        [
            ("title", "My Title"),
            (
                "item",
                StructValue(None, [("label", "my-label"), ("value", 100)]),
                ),
            ("items", []),
            ("image", None),
        ],
    )

    assert page.body[2].block_type == "int_array"
    assert page.body[2].value == [100]

    assert page.body[3].block_type == "image"
    assert page.body[3].value == image

    content = str(page.body)
    assert "block-image" in content

Error:

➜  wagtail-factories git:(master) ✗ make test
py.test --reuse-db
===================================================================== test session starts ======================================================================
platform darwin -- Python 3.9.0, pytest-6.0.1, py-1.10.0, pluggy-0.13.1
django: settings: tests.settings (from ini)
rootdir: /Users/muhtarcangoktas/Code/wagtail-factories, configfile: setup.cfg
plugins: django-3.9.0, Faker-8.11.0, cov-2.7.1, pythonpath-0.7.3
collected 22 items

tests/test_blocks.py ...F..                                                                                                                              [ 27%]
tests/test_factories.py ...............                                                                                                                  [ 95%]
tests/test_blocks.py .                                                                                                                                   [100%]

=========================================================================== FAILURES ===========================================================================
__________________________________________________________ test_custom_page_streamfield_data_complex ___________________________________________________________

    @pytest.mark.django_db
    def test_custom_page_streamfield_data_complex():
        assert Image.objects.count() == 0

        root_page = wagtail_factories.PageFactory(parent=None)
        page = MyTestPageWithStreamFieldFactory(
            parent=root_page,
            body__0__char_array__0="foo",
            body__0__char_array__1="bar",
            body__2__int_array__0=100,
            body__1__struct__title="My Title",
            body__1__struct__item__value=100,
            body__1__struct__image__image=None,
            body__3__image__image__title="Blub",
            body__4__struct__items__0__label="Test",
            body__4__struct__items__0__value=200
        )
>       assert Image.objects.count() == 1
E       assert 2 == 1
E        +  where 2 = <bound method BaseManager._get_queryset_methods.<locals>.create_method.<locals>.manager_method of <django.db.models.manager.ManagerFromImageQuerySet object at 0x107f99280>>()
E        +    where <bound method BaseManager._get_queryset_methods.<locals>.create_method.<locals>.manager_method of <django.db.models.manager.ManagerFromImageQuerySet object at 0x107f99280>> = <django.db.models.manager.ManagerFromImageQuerySet object at 0x107f99280>.count
E        +      where <django.db.models.manager.ManagerFromImageQuerySet object at 0x107f99280> = Image.objects

tests/test_blocks.py:100: AssertionError
======================================================================= warnings summary =======================================================================
tests/test_factories.py::test_page_multiple_roots
  /Users/muhtarcangoktas/Code/wagtail-factories/tests/urls.py:6: RemovedInDjango40Warning: django.conf.urls.url() is deprecated in favor of django.urls.re_path().
    urlpatterns += [url(r"^", include(wagtail_urls))]

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=================================================================== short test summary info ====================================================================
FAILED tests/test_blocks.py::test_custom_page_streamfield_data_complex - assert 2 == 1
=========================================================== 1 failed, 21 passed, 1 warning in 2.39s ============================================================
make: *** [test] Error 1