Example #1
0
def branch_with_user(root_page,
                     *,
                     permissions=[],
                     password='******',
                     is_superuser=False,
                     is_staff=False):
    """Returns a listing page with a child page, user group, user & client.

    For Wagtail permission model check:
    http://docs.wagtail.io/en/v2.0/topics/permissions.html#page-permissions
    """
    # ensure that only permissions supported by Wagtail are used
    available_permissions = [p for p, _, _ in PAGE_PERMISSION_TYPES]
    assert not (set(permissions) - set(available_permissions))

    listing_page = exred.ArticleListingPageFactory(parent=root_page)
    article_page = exred.ArticlePageFactory(parent=listing_page)

    group = GroupFactory()
    group.permissions.add(Permission.objects.get(codename='access_admin'))
    set_permissions(listing_page, group, permissions)

    user = UserFactory(is_superuser=is_superuser,
                       is_staff=is_staff,
                       groups=[group])
    user_password = password or 'test'
    user.set_password(user_password)
    user.save()

    client = Client()
    client.login(username=user.username, password=user_password)

    return Branch(listing_page, article_page, group, user, client)
Example #2
0
def test_homepage(admin_client, root_page):

    home_page = factories.HomePageFactory.create(
        parent=root_page
    )

    # news
    article_listing_page = factories.ArticleListingPageFactory(
        slug=settings.EU_EXIT_NEWS_LISTING_PAGE_SLUG
    )
    for _ in range(5):
        factories.ArticlePageFactory.create(
            parent=article_listing_page
        )
    factories.ArticlePageFactory.create(
        parent=root_page
    )

    # guidance
    topic_landing_page = factories.TopicLandingPageFactory(
        slug=cms.GREAT_ADVICE_SLUG
    )
    for _ in range(5):
        factories.ArticleListingPageFactory.create(
            parent=topic_landing_page
        )

    url = reverse('api:api:pages:detail', kwargs={'pk': home_page.pk})
    response = admin_client.get(url)
    assert response.status_code == 200
    assert 'articles' in response.json()
    assert 'advice' in response.json()
    assert len(response.json()['advice']) == 5
    assert len(response.json()['articles']) == 5