Beispiel #1
0
def test_page_multiple_roots():
    # Make sure the default root pages are removed created by wagtail
    # migrations
    Page.get_root_nodes().delete()
    assert Page.get_root_nodes().count() == 0

    wagtail_factories.PageFactory(parent=None)
    wagtail_factories.PageFactory(parent=None)
    wagtail_factories.PageFactory(parent=None)
    assert Page.get_root_nodes().count() == 3
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',
    )
    assert Image.objects.count() == 1
    image = Image.objects.first()

    assert page.body.stream_data == [
        ('char_array', ['foo', 'bar']),
        ('struct',
         StructValue(None, [
             ('title', 'My Title'),
             ('item',
              StructValue(None, [
                  ('label', 'my-label'),
                  ('value', 100),
              ])),
             ('items', []),
             ('image', None),
         ])),
        ('int_array', [100]),
        ('image', image),
    ]
    content = str(page.body)
    assert 'block-image' in content
Beispiel #3
0
def test_custom_page_streamfield_data():
    root_page = wagtail_factories.PageFactory(parent=None)
    page = MyTestPageFactory(parent=root_page,
                             body=[("char_array", ["bla-1", "bla-2"])])

    assert page.body[0].block_type == "char_array"
    assert page.body[0].value == ["bla-1", "bla-2"]
Beispiel #4
0
def test_page_multiple_nested():
    root = wagtail_factories.PageFactory(parent=None)
    page_1 = wagtail_factories.PageFactory(parent=root, slug="page-1")
    wagtail_factories.PageFactory(parent=page_1, slug="page-1-1")
    wagtail_factories.PageFactory(parent=page_1, slug="page-1-2")
    wagtail_factories.PageFactory(parent=page_1, slug="page-1-3")

    page_2 = wagtail_factories.PageFactory(parent=root, slug="page-2")
    wagtail_factories.PageFactory(parent=page_2, slug="page-2-1")
    wagtail_factories.PageFactory(parent=page_2, slug="page-2-2")
    wagtail_factories.PageFactory(parent=page_2, slug="page-2-3")
    wagtail_factories.PageFactory(parent=page_2, slug="page-2-4")

    assert len(root.get_children()) == 2
    assert len(page_1.get_children()) == 3
    assert len(page_2.get_children()) == 4
Beispiel #5
0
def test_page_multiple_nested_structure_at_once():
    page = wagtail_factories.PageFactory(slug='page-1-2-3',
                                         parent__slug='page-1-2',
                                         parent__parent__slug='page-1',
                                         parent__parent__parent=None)

    assert page.slug == 'page-1-2-3'
    assert page.get_parent().slug == 'page-1-2'
    assert page.get_parent().get_parent().slug == 'page-1'
    assert page.get_parent().get_parent().get_parent() is None
Beispiel #6
0
def test_get_or_create():
    root_page = wagtail_factories.PageFactory(parent=None)
    page_1 = MyTestPageGetOrCreateFactory(slug="foobar",
                                          parent__slug="root",
                                          parent__parent=root_page)
    page_2 = MyTestPageGetOrCreateFactory(slug="foobar",
                                          parent__slug="root",
                                          parent__parent=root_page)

    assert page_1.pk == page_2.pk
def test_custom_page_streamfield_data():
    root_page = wagtail_factories.PageFactory(parent=None)
    page = MyTestPageFactory(
        parent=root_page,
        body=[
            ('char_array', ['bla-1', 'bla-2'])
        ])

    assert page.body.stream_data == [
        ('char_array', ['bla-1', 'bla-2'])
    ]
Beispiel #8
0
def test_page_multiple_nested_structure_at_once():
    Page.objects.all().delete()

    page = wagtail_factories.PageFactory(
        slug="page-1-2-3",
        title="Page 1.2.3",
        parent__slug="page-1-2",
        parent__title="Page 1.2",
        parent__parent__slug="page-1",
        parent__parent__title="Page 1",
        parent__parent__parent=None,
    )

    assert Page.objects.count() == 3, Page.objects.all()

    assert page.slug == "page-1-2-3"
    assert page.get_parent().slug == "page-1-2"
    assert page.get_parent().get_parent().slug == "page-1"
    assert page.get_parent().get_parent().get_parent() is None
Beispiel #9
0
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",
    )
    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
Beispiel #10
0
def test_custom_page_streamfield():
    root_page = wagtail_factories.PageFactory(parent=None)
    page = MyTestPageFactory(parent=root_page)

    assert len(page.body) == 0
Beispiel #11
0
def test_page_no_args_or_kwargs():
    page = wagtail_factories.PageFactory(parent=None)
    assert page.title == "Test page"
    assert page.slug == "test-page"
def django_db_setup(django_db_setup, django_db_blocker, tmpdir_factory):
    """
    Configure the DB for Testing.
    We also configure a MEDIA_ROOT temporary directory
    """
    media_dir = "_media_store"
    media_storage = tmpdir_factory.mktemp(media_dir)
    tmpdir_factory.mktemp(media_dir).join("images")
    tmpdir_factory.mktemp(media_dir).join("original_images")
    settings.MEDIA_ROOT = str(media_storage)
    with django_db_blocker.unblock():
        # create superuser
        UserFactory(
            is_staff=True, is_superuser=True,
        )
        root_page = wagtail_factories.PageFactory(parent=None)
        home_page = HomePageFactory(parent=root_page, title="Home", slug="home")
        # Create a Site with the new homepage set as the root
        Site.objects.all().delete()
        Site.objects.create(
            hostname="www.example.com",
            root_page=home_page,
            site_name="Test Site",
            is_default_site=True,
        )
        # create AboutPage
        # AboutPageFactory(parent=home_page, title="About", url_path="/about", slug="about")
        AboutPageFactory(parent=home_page, title="About", slug="about")
        # create BlogPage
        article_index_page = ArticleIndexPageFactory(
            parent=home_page,
            title="Blog",
            slug="blog",
            introduction=fake.text(max_nb_chars=254),
        )
        # create some Articles
        ArticleFactory(
            parent=article_index_page,
            live=True,
            article_type="Post",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            author=fake.name(),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=False,
            article_type="Post",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            author=fake.name(),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=True,
            article_type="Shout",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=True,
            article_type="Info",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            author=fake.name(),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=False,
            article_type="Info",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=True,
            article_type="Misc",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            content=fake_content(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=True,
            article_type="URL",
            cover_picture=wagtail_factories.ImageFactory(),
            summary=fake.text(max_nb_chars=254),
            author=fake.name(),
            external_url=fake.uri(),
        )
        ArticleFactory(
            parent=article_index_page,
            live=False,
            article_type="URL",
            cover_picture=wagtail_factories.ImageFactory(),
            author="Foo Bar",
            summary=fake.text(max_nb_chars=254),
            external_url="https://www.freecodecamp.org/news/mechanical-engineering-to-software-developer/",
        )
        # Create People
        fake_phone_num = fake.e164(region_code="US", valid=True, possible=True)
        PeopleFactory.create_batch(
            size=4,
            image=wagtail_factories.ImageFactory(),
            phone_number=fake_phone_num,
            status="published",
        )
        PeopleFactory.create_batch(
            size=3,
            image=wagtail_factories.ImageFactory(),
            phone_number=fake_phone_num,
            status="draft",
        )
        PeopleFactory(
            # no image for this one
            phone_number=fake_phone_num,
            first_name="Jane",
            last_name="Doe",
            status="draft",
        )
        # create ContactPage
        contact_page = ContactPageFactory(
            parent=home_page,
            title="Contact",
            slug="contact",
            # address=fake.address()
        )
        # create contact details for ContactPage
        phone_01 = ContactPagePhoneNumber(
            phone_number=fake.e164(region_code="CA", valid=True, possible=True),
        )
        phone_02 = ContactPagePhoneNumber(
            phone_number=fake.e164(region_code="CA", valid=True, possible=True),
        )
        email_01 = ContactPageEmailAddress(email_address=fake.company_email,)
        email_02 = ContactPageEmailAddress(email_address=fake.company_email,)
        contact_page.phone_numbers = [phone_01, phone_02]
        contact_page.email_addresses = [email_01, email_02]
        contact_page.save()

        # add some documents
        doc1 = factory.django.FileField(filename="document_01.pdf")
        doc2 = factory.django.FileField(filename="document_02.pdf")
        SimpleDocFactory(title="Document 1", file=doc1)
        SimpleDocFactory(title="Document 2", file=doc2)
Beispiel #13
0
def test_custom_page_streamfield_data_dict():
    assert Image.objects.count() == 0

    root_page = wagtail_factories.PageFactory(parent=None)
    params = OrderedDict({
        'parent':
        root_page,
        'body': [
            {
                'char_array': [
                    'foo',
                    'bar',
                ],
            },
            {
                'struct': {
                    'title': 'My Title',
                    'item': {
                        'value': 100,
                    },
                    'image': {
                        'image': None,
                    },
                },
            },
            {
                'int_array': [
                    100,
                ],
            },
            {
                'image': {
                    'image': {
                        'title': 'Blub',
                    },
                },
            },
        ],
    })

    page = DictToParameteredAttribute(MyTestPageWithStreamFieldFactory,
                                      params=params)

    assert Image.objects.count() == 1
    image = Image.objects.first()

    assert page.body.stream_data == [
        ('char_array', ['foo', 'bar']),
        ('struct',
         StructValue(None, [
             ('title', 'My Title'),
             ('item',
              StructValue(None, [
                  ('label', 'my-label'),
                  ('value', 100),
              ])),
             ('items', []),
             ('image', None),
         ])),
        ('int_array', [100]),
        ('image', image),
    ]
    content = str(page.body)
    assert 'block-image' in content
Beispiel #14
0
def root_page():
    Page.objects.all().delete()
    return wagtail_factories.PageFactory(parent=None)