Skip to content

Commit f60f7d4

Browse files
committed
update tests
1 parent 146bf53 commit f60f7d4

File tree

6 files changed

+160
-111
lines changed

6 files changed

+160
-111
lines changed

backend/api/visa/tests/mutations/test_update_invitation_letter_document.py

Lines changed: 133 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,19 @@ def _update_invitation_letter_document(client, **input):
1313
... on InvitationLetterDocument {
1414
id
1515
dynamicDocument {
16-
header
17-
footer
16+
header {
17+
content
18+
align
19+
margin
20+
}
21+
footer {
22+
content
23+
align
24+
margin
25+
}
26+
pageLayout {
27+
margin
28+
}
1829
pages {
1930
id
2031
title
@@ -34,8 +45,13 @@ def test_update_invitation_letter_document(admin_superuser, admin_graphql_api_cl
3445
document = InvitationLetterDocumentFactory(
3546
document=None,
3647
dynamic_document={
37-
"header": "header",
38-
"footer": "footer",
48+
"header": {"content": "header", "margin": "1cm 0 0 0", "align": "top-left"},
49+
"footer": {
50+
"content": "footer",
51+
"margin": "1cm 0 0 0",
52+
"align": "bottom-left",
53+
},
54+
"page_layout": {"margin": "0"},
3955
"pages": [
4056
{
4157
"id": "id",
@@ -51,8 +67,17 @@ def test_update_invitation_letter_document(admin_superuser, admin_graphql_api_cl
5167
input={
5268
"id": document.id,
5369
"dynamicDocument": {
54-
"header": "new header",
55-
"footer": "new footer",
70+
"header": {
71+
"content": "new header",
72+
"margin": "0",
73+
"align": "top-left",
74+
},
75+
"footer": {
76+
"content": "new footer",
77+
"margin": "0",
78+
"align": "bottom-left",
79+
},
80+
"pageLayout": {"margin": "1cm 0 1cm 0"},
5681
"pages": [
5782
{
5883
"id": "id",
@@ -66,8 +91,13 @@ def test_update_invitation_letter_document(admin_superuser, admin_graphql_api_cl
6691

6792
assert response["data"]["updateInvitationLetterDocument"]["id"] == str(document.id)
6893
assert response["data"]["updateInvitationLetterDocument"]["dynamicDocument"] == {
69-
"header": "new header",
70-
"footer": "new footer",
94+
"header": {"content": "new header", "margin": "0", "align": "top-left"},
95+
"footer": {
96+
"content": "new footer",
97+
"margin": "0",
98+
"align": "bottom-left",
99+
},
100+
"pageLayout": {"margin": "1cm 0 1cm 0"},
71101
"pages": [
72102
{
73103
"id": "id",
@@ -79,8 +109,9 @@ def test_update_invitation_letter_document(admin_superuser, admin_graphql_api_cl
79109

80110
document.refresh_from_db()
81111
assert document.dynamic_document == {
82-
"header": "new header",
83-
"footer": "new footer",
112+
"header": {"content": "new header", "margin": "0", "align": "top-left"},
113+
"footer": {"content": "new footer", "margin": "0", "align": "bottom-left"},
114+
"page_layout": {"margin": "1cm 0 1cm 0"},
84115
"pages": [
85116
{
86117
"id": "id",
@@ -103,8 +134,13 @@ def test_cannot_update_invitation_letter_document_with_static_doc(
103134
input={
104135
"id": document.id,
105136
"dynamicDocument": {
106-
"header": "new header",
107-
"footer": "new footer",
137+
"header": {"content": "new header", "margin": "0", "align": "top-left"},
138+
"footer": {
139+
"content": "new footer",
140+
"margin": "0",
141+
"align": "bottom-left",
142+
},
143+
"pageLayout": {"margin": "1cm 0 1cm 0"},
108144
"pages": [
109145
{
110146
"id": "id",
@@ -128,29 +164,35 @@ def test_update_non_existent_invitation_letter_document(
128164
admin_superuser, admin_graphql_api_client
129165
):
130166
admin_graphql_api_client.force_login(admin_superuser)
131-
167+
old_doc = {
168+
"header": {"content": "new header", "align": "top-left"},
169+
"footer": {"content": "new footer", "align": "bottom-left"},
170+
"pageLayout": {"margin": "1cm 0 1cm 0"},
171+
"pages": [
172+
{
173+
"id": "id",
174+
"title": "title",
175+
"content": "content",
176+
}
177+
],
178+
}
132179
document = InvitationLetterDocumentFactory(
133180
document=None,
134-
dynamic_document={
135-
"header": "header",
136-
"footer": "footer",
137-
"pages": [
138-
{
139-
"id": "id",
140-
"title": "title",
141-
"content": "content",
142-
}
143-
],
144-
},
181+
dynamic_document=old_doc,
145182
)
146183

147184
response = _update_invitation_letter_document(
148185
admin_graphql_api_client,
149186
input={
150187
"id": document.id + 1,
151188
"dynamicDocument": {
152-
"header": "new header",
153-
"footer": "new footer",
189+
"header": {"content": "new header", "margin": "0", "align": "top-left"},
190+
"footer": {
191+
"content": "new footer",
192+
"margin": "0",
193+
"align": "bottom-left",
194+
},
195+
"pageLayout": {"margin": "1cm 0 1cm 0"},
154196
"pages": [
155197
{
156198
"id": "id",
@@ -165,10 +207,16 @@ def test_update_non_existent_invitation_letter_document(
165207
assert (
166208
response["data"]["updateInvitationLetterDocument"]["__typename"] == "NotFound"
167209
)
210+
168211
document.refresh_from_db()
169-
assert document.dynamic_document == {
170-
"header": "header",
171-
"footer": "footer",
212+
assert document.dynamic_document == old_doc
213+
214+
215+
def test_update_invitation_letter_document_without_permission(admin_graphql_api_client):
216+
old_doc = {
217+
"header": {"content": "header", "align": "top-left"},
218+
"footer": {"content": "footer", "align": "bottom-left"},
219+
"pageLayout": {"margin": "1cm 0 1cm 0"},
172220
"pages": [
173221
{
174222
"id": "id",
@@ -177,31 +225,27 @@ def test_update_non_existent_invitation_letter_document(
177225
}
178226
],
179227
}
180-
181-
182-
def test_update_invitation_letter_document_without_permission(admin_graphql_api_client):
183228
document = InvitationLetterDocumentFactory(
184229
document=None,
185-
dynamic_document={
186-
"header": "header",
187-
"footer": "footer",
188-
"pages": [
189-
{
190-
"id": "id",
191-
"title": "title",
192-
"content": "content",
193-
}
194-
],
195-
},
230+
dynamic_document=old_doc,
196231
)
197232

198233
response = _update_invitation_letter_document(
199234
admin_graphql_api_client,
200235
input={
201236
"id": document.id,
202237
"dynamicDocument": {
203-
"header": "new header",
204-
"footer": "new footer",
238+
"header": {
239+
"content": "new header",
240+
"margin": "0 0 0 0",
241+
"align": "top-right",
242+
},
243+
"footer": {
244+
"content": "new footer",
245+
"margin": "0 0 0 0",
246+
"align": "bottom-center",
247+
},
248+
"pageLayout": {"margin": "1cm 0 1cm 0"},
205249
"pages": [
206250
{
207251
"id": "id",
@@ -215,9 +259,17 @@ def test_update_invitation_letter_document_without_permission(admin_graphql_api_
215259

216260
assert response["errors"][0]["message"] == "Cannot edit invitation letter document"
217261
document.refresh_from_db()
218-
assert document.dynamic_document == {
219-
"header": "header",
220-
"footer": "footer",
262+
assert document.dynamic_document == old_doc
263+
264+
265+
def test_update_invitation_letter_document_as_staff_without_permission(
266+
admin_user, admin_graphql_api_client
267+
):
268+
admin_graphql_api_client.force_login(admin_user)
269+
old_doc = {
270+
"header": {"content": "header", "align": "top-left"},
271+
"footer": {"content": "footer", "align": "bottom-left"},
272+
"pageLayout": {"margin": "1cm 0 1cm 0"},
221273
"pages": [
222274
{
223275
"id": "id",
@@ -227,34 +279,27 @@ def test_update_invitation_letter_document_without_permission(admin_graphql_api_
227279
],
228280
}
229281

230-
231-
def test_update_invitation_letter_document_as_staff_without_permission(
232-
admin_user, admin_graphql_api_client
233-
):
234-
admin_graphql_api_client.force_login(admin_user)
235-
236282
document = InvitationLetterDocumentFactory(
237283
document=None,
238-
dynamic_document={
239-
"header": "header",
240-
"footer": "footer",
241-
"pages": [
242-
{
243-
"id": "id",
244-
"title": "title",
245-
"content": "content",
246-
}
247-
],
248-
},
284+
dynamic_document=old_doc,
249285
)
250286

251287
response = _update_invitation_letter_document(
252288
admin_graphql_api_client,
253289
input={
254290
"id": document.id,
255291
"dynamicDocument": {
256-
"header": "new header",
257-
"footer": "new footer",
292+
"header": {
293+
"content": "new header",
294+
"margin": "1cm 0 0 0",
295+
"align": "top-right",
296+
},
297+
"footer": {
298+
"content": "new footer",
299+
"margin": "1cm 0 0 0",
300+
"align": "top-right",
301+
},
302+
"pageLayout": {"margin": "1cm 0 1cm 0"},
258303
"pages": [
259304
{
260305
"id": "id",
@@ -268,17 +313,7 @@ def test_update_invitation_letter_document_as_staff_without_permission(
268313

269314
assert response["errors"][0]["message"] == "Cannot edit invitation letter document"
270315
document.refresh_from_db()
271-
assert document.dynamic_document == {
272-
"header": "header",
273-
"footer": "footer",
274-
"pages": [
275-
{
276-
"id": "id",
277-
"title": "title",
278-
"content": "content",
279-
}
280-
],
281-
}
316+
assert document.dynamic_document == old_doc
282317

283318

284319
def test_update_invitation_letter_document_as_staff_user_with_permission(
@@ -289,8 +324,9 @@ def test_update_invitation_letter_document_as_staff_user_with_permission(
289324
document = InvitationLetterDocumentFactory(
290325
document=None,
291326
dynamic_document={
292-
"header": "header",
293-
"footer": "footer",
327+
"header": {"content": "header", "margin": "0", "align": "top-left"},
328+
"footer": {"content": "footer", "margin": "0", "align": "top-left"},
329+
"pageLayout": {"margin": "1cm 0 1cm 0"},
294330
"pages": [
295331
{
296332
"id": "id",
@@ -315,8 +351,17 @@ def test_update_invitation_letter_document_as_staff_user_with_permission(
315351
input={
316352
"id": document.id,
317353
"dynamicDocument": {
318-
"header": "new header",
319-
"footer": "new footer",
354+
"header": {
355+
"content": "new header",
356+
"margin": "0",
357+
"align": "bottom-left",
358+
},
359+
"footer": {
360+
"content": "new footer",
361+
"margin": "0",
362+
"align": "bottom-left",
363+
},
364+
"pageLayout": {"margin": "1cm 0 1cm 0"},
320365
"pages": [
321366
{
322367
"id": "id",
@@ -330,8 +375,9 @@ def test_update_invitation_letter_document_as_staff_user_with_permission(
330375

331376
assert response["data"]["updateInvitationLetterDocument"]["id"] == str(document.id)
332377
assert response["data"]["updateInvitationLetterDocument"]["dynamicDocument"] == {
333-
"header": "new header",
334-
"footer": "new footer",
378+
"header": {"content": "new header", "margin": "0", "align": "bottom-left"},
379+
"footer": {"content": "new footer", "margin": "0", "align": "bottom-left"},
380+
"pageLayout": {"margin": "1cm 0 1cm 0"},
335381
"pages": [
336382
{
337383
"id": "id",
@@ -343,8 +389,9 @@ def test_update_invitation_letter_document_as_staff_user_with_permission(
343389

344390
document.refresh_from_db()
345391
assert document.dynamic_document == {
346-
"header": "new header",
347-
"footer": "new footer",
392+
"header": {"content": "new header", "margin": "0", "align": "bottom-left"},
393+
"footer": {"content": "new footer", "margin": "0", "align": "bottom-left"},
394+
"page_layout": {"margin": "1cm 0 1cm 0"},
348395
"pages": [
349396
{
350397
"id": "id",

0 commit comments

Comments
 (0)