|
| 1 | +from wagtail.models import PageViewRestriction |
1 | 2 | import pytest |
2 | 3 | from api.cms.tests.factories import GenericPageFactory, SiteFactory |
3 | 4 |
|
@@ -48,6 +49,49 @@ def test_pages(graphql_client, locale): |
48 | 49 | } |
49 | 50 |
|
50 | 51 |
|
| 52 | +def test_restricted_pages_are_not_returned(graphql_client, locale): |
| 53 | + parent = GenericPageFactory() |
| 54 | + parent.save_revision().publish() |
| 55 | + page_1 = GenericPageFactory( |
| 56 | + slug="bubble-tea", |
| 57 | + locale=locale("en"), |
| 58 | + parent=parent, |
| 59 | + body__0__text_section__title__value="I've Got a Lovely Bunch of Coconuts", |
| 60 | + ) |
| 61 | + page_1.save_revision().publish() |
| 62 | + PageViewRestriction.objects.create( |
| 63 | + page=page_1, restriction_type="password", password="ticket" |
| 64 | + ) |
| 65 | + |
| 66 | + page_2 = GenericPageFactory( |
| 67 | + slug="chocolate", |
| 68 | + locale=locale("en"), |
| 69 | + parent=parent, |
| 70 | + body__0__text_section__title__value="There they are, all standing in a row", |
| 71 | + ) |
| 72 | + page_2.save_revision().publish() |
| 73 | + SiteFactory(hostname="pycon", port=80, root_page=parent) |
| 74 | + |
| 75 | + query = """ |
| 76 | + query Page ($hostname: String!, $language: String!) { |
| 77 | + cmsPages(hostname: $hostname, language: $language){ |
| 78 | + id |
| 79 | + } |
| 80 | + } |
| 81 | + """ |
| 82 | + |
| 83 | + response = graphql_client.query( |
| 84 | + query, variables={"hostname": "pycon", "language": "en"} |
| 85 | + ) |
| 86 | + |
| 87 | + assert response["data"] == { |
| 88 | + "cmsPages": [ |
| 89 | + {"id": str(parent.id)}, |
| 90 | + {"id": str(page_2.id)}, |
| 91 | + ] |
| 92 | + } |
| 93 | + |
| 94 | + |
51 | 95 | def test_pages_site_not_found(graphql_client): |
52 | 96 | query = """ |
53 | 97 | query Page ($hostname: String!, $language: String!) { |
|
0 commit comments