|
1 | 1 | from decimal import Decimal |
| 2 | +from conferences.tests.factories import ConferenceFactory |
2 | 3 | import pytest |
3 | 4 | from api.cms.tests.factories import GenericPageFactory, SiteFactory |
| 5 | +from wagtail.models import PageViewRestriction |
4 | 6 |
|
5 | 7 | pytestmark = pytest.mark.django_db |
6 | 8 |
|
@@ -68,6 +70,139 @@ def test_page(graphql_client, locale): |
68 | 70 | } |
69 | 71 |
|
70 | 72 |
|
| 73 | +def test_page_with_ticket_restriction_and_ticket_returns_content( |
| 74 | + graphql_client, locale, user, mock_has_ticket |
| 75 | +): |
| 76 | + graphql_client.force_login(user) |
| 77 | + conference = ConferenceFactory(code="pycon2025") |
| 78 | + mock_has_ticket(conference) |
| 79 | + |
| 80 | + parent = GenericPageFactory() |
| 81 | + page = GenericPageFactory( |
| 82 | + slug="bubble-tea", |
| 83 | + locale=locale("en"), |
| 84 | + parent=parent, |
| 85 | + title="Bubble", |
| 86 | + body__0__text_section__title__value="I've Got a Lovely Bunch of Coconuts", |
| 87 | + body__1__map__longitude=Decimal(3.14), |
| 88 | + body__2__homepage_hero__city="florence", |
| 89 | + body__3__homepage_hero__city=None, |
| 90 | + ) |
| 91 | + page.save_revision().publish() |
| 92 | + PageViewRestriction.objects.create( |
| 93 | + page=page, restriction_type="password", password="ticket" |
| 94 | + ) |
| 95 | + SiteFactory(hostname="pycon", port=80, root_page=parent) |
| 96 | + page.copy_for_translation(locale=locale("it")) |
| 97 | + query = """ |
| 98 | + query Page ($hostname: String!, $language: String!, $slug: String!) { |
| 99 | + cmsPage(hostname: $hostname, language: $language, slug: $slug){ |
| 100 | + ...on GenericPage { |
| 101 | + title |
| 102 | + slug |
| 103 | + body { |
| 104 | + ...on TextSection { |
| 105 | + title |
| 106 | + } |
| 107 | + ...on CMSMap { |
| 108 | + latitude |
| 109 | + longitude |
| 110 | + } |
| 111 | + ... on HomepageHero { |
| 112 | + city |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + """ |
| 119 | + |
| 120 | + response = graphql_client.query( |
| 121 | + query, variables={"hostname": "pycon", "slug": "bubble-tea", "language": "en"} |
| 122 | + ) |
| 123 | + |
| 124 | + assert response["data"] == { |
| 125 | + "cmsPage": { |
| 126 | + "title": "Bubble", |
| 127 | + "slug": "bubble-tea", |
| 128 | + "body": [ |
| 129 | + { |
| 130 | + "latitude": "43.766199999999997771737980656325817108154296875", # noqa: E501 |
| 131 | + "longitude": "3.140000000000000124344978758017532527446746826171875", # noqa: E501 |
| 132 | + }, |
| 133 | + { |
| 134 | + "city": "FLORENCE", |
| 135 | + }, |
| 136 | + { |
| 137 | + "city": None, |
| 138 | + }, |
| 139 | + ], |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + |
| 144 | +def test_page_with_ticket_restriction_without_ticket_returns_first_block( |
| 145 | + graphql_client, locale, user, mock_has_ticket |
| 146 | +): |
| 147 | + graphql_client.force_login(user) |
| 148 | + conference = ConferenceFactory(code="pycon2025") |
| 149 | + mock_has_ticket(conference, False) |
| 150 | + |
| 151 | + parent = GenericPageFactory() |
| 152 | + page = GenericPageFactory( |
| 153 | + slug="bubble-tea", |
| 154 | + locale=locale("en"), |
| 155 | + parent=parent, |
| 156 | + title="Bubble", |
| 157 | + body__0__text_section__title__value="I've Got a Lovely Bunch of Coconuts", |
| 158 | + body__1__map__longitude=Decimal(3.14), |
| 159 | + body__2__homepage_hero__city="florence", |
| 160 | + body__3__homepage_hero__city=None, |
| 161 | + ) |
| 162 | + page.save_revision().publish() |
| 163 | + PageViewRestriction.objects.create( |
| 164 | + page=page, restriction_type="password", password="ticket" |
| 165 | + ) |
| 166 | + SiteFactory(hostname="pycon", port=80, root_page=parent) |
| 167 | + page.copy_for_translation(locale=locale("it")) |
| 168 | + query = """ |
| 169 | + query Page ($hostname: String!, $language: String!, $slug: String!) { |
| 170 | + cmsPage(hostname: $hostname, language: $language, slug: $slug){ |
| 171 | + ...on GenericPage { |
| 172 | + title |
| 173 | + slug |
| 174 | + body { |
| 175 | + ...on TextSection { |
| 176 | + title |
| 177 | + } |
| 178 | + ...on CMSMap { |
| 179 | + latitude |
| 180 | + longitude |
| 181 | + } |
| 182 | + ... on HomepageHero { |
| 183 | + city |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + """ |
| 190 | + |
| 191 | + response = graphql_client.query( |
| 192 | + query, variables={"hostname": "pycon", "slug": "bubble-tea", "language": "en"} |
| 193 | + ) |
| 194 | + |
| 195 | + assert response["data"] == { |
| 196 | + "cmsPage": { |
| 197 | + "title": "Bubble", |
| 198 | + "slug": "bubble-tea", |
| 199 | + "body": [ |
| 200 | + {"title": "I've Got a Lovely Bunch of " "Coconuts"}, |
| 201 | + ], |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + |
71 | 206 | def test_page_returns_live_revision(graphql_client, locale): |
72 | 207 | parent = GenericPageFactory() |
73 | 208 | page = GenericPageFactory( |
|
0 commit comments