Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit c496867

Browse files
committed
Test speakers update view.
1 parent 6da9c52 commit c496867

File tree

1 file changed

+69
-31
lines changed

1 file changed

+69
-31
lines changed

tests/test_new_cfp.py

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414

1515
from tests.common_tools import redirects_to, template_used
1616

17+
pytestmark = mark.django_db
18+
1719

18-
@mark.django_db
1920
@mark.parametrize(
2021
"url",
2122
[
2223
reverse("cfp:step1_submit_proposal"),
2324
# using some random uuid because we just need to resolve url
2425
reverse("cfp:step2_add_speakers", args=["ABCDEFI"]),
2526
reverse("cfp:step3_thanks", args=["ABCDEFI"]),
27+
reverse("cfp:update", args=["ABCDEFI"]),
28+
reverse("cfp:update_speakers", args=["ABCDEFI"]),
2629
],
2730
)
2831
def test_if_cfp_pages_are_login_required(client, url):
@@ -32,7 +35,6 @@ def test_if_cfp_pages_are_login_required(client, url):
3235
assert redirects_to(response, "/accounts/login/")
3336

3437

35-
@mark.django_db
3638
def test_if_cfp_pages_are_unavailable_if_cfp_is_undefined(user_client):
3739
Conference.objects.create(
3840
code=settings.CONFERENCE_CONFERENCE,
@@ -45,7 +47,6 @@ def test_if_cfp_pages_are_unavailable_if_cfp_is_undefined(user_client):
4547
assert template_used(response, "ep19/bs/cfp/cfp_is_closed.html")
4648

4749

48-
@mark.django_db
4950
def test_if_cfp_pages_are_unavailable_if_cfp_is_in_the_future(user_client):
5051
Conference.objects.create(
5152
code=settings.CONFERENCE_CONFERENCE,
@@ -59,7 +60,6 @@ def test_if_cfp_pages_are_unavailable_if_cfp_is_in_the_future(user_client):
5960
assert template_used(response, "ep19/bs/cfp/cfp_is_closed.html")
6061

6162

62-
@mark.django_db
6363
def test_if_cfp_pages_are_unavailable_if_cfp_is_in_the_past(user_client):
6464
Conference.objects.create(
6565
code=settings.CONFERENCE_CONFERENCE,
@@ -74,7 +74,6 @@ def test_if_cfp_pages_are_unavailable_if_cfp_is_in_the_past(user_client):
7474
assert template_used(response, "ep19/bs/cfp/cfp_is_closed.html")
7575

7676

77-
@mark.django_db
7877
def test_if_cfp_pages_are_available_if_cfp_is_active(user_client):
7978
Conference.objects.create(
8079
code=settings.CONFERENCE_CONFERENCE,
@@ -89,7 +88,6 @@ def test_if_cfp_pages_are_available_if_cfp_is_active(user_client):
8988
assert template_used(response, "ep19/bs/cfp/step1_talk_info.html")
9089

9190

92-
@mark.django_db
9391
def test_validation_errors_are_handled_on_step1(user_client):
9492
"""
9593
NOTE(artcz)
@@ -108,7 +106,6 @@ def test_validation_errors_are_handled_on_step1(user_client):
108106
assert template_used(response, "ep19/bs/cfp/step1_talk_info.html")
109107

110108

111-
@mark.django_db
112109
def test_if_user_can_submit_talk_details_and_is_redirect_to_step2(user_client):
113110
STEP1_CORRECT_REDIRECT_302 = 302
114111

@@ -154,7 +151,6 @@ def test_if_user_can_submit_talk_details_and_is_redirect_to_step2(user_client):
154151
)
155152

156153

157-
@mark.django_db
158154
def test_validation_errors_are_handled_on_step2(user_client):
159155
"""
160156
NOTE(artcz)
@@ -174,7 +170,6 @@ def test_validation_errors_are_handled_on_step2(user_client):
174170
assert template_used(response, "ep19/bs/cfp/step2_add_speaker.html")
175171

176172

177-
@mark.django_db
178173
def test_if_user_can_add_a_speaker_to_a_proposal(user_client):
179174
create_conference_with_open_cfp()
180175
STEP2_CORRECT_REDIRECT_302 = 302
@@ -213,7 +208,6 @@ def test_if_user_can_add_a_speaker_to_a_proposal(user_client):
213208
)
214209

215210

216-
@mark.django_db
217211
def test_if_correct_thanks_page_is_rendered(user_client):
218212
create_conference_with_open_cfp()
219213
talk = TalkFactory()
@@ -223,7 +217,6 @@ def test_if_correct_thanks_page_is_rendered(user_client):
223217
assert template_used(response, "ep19/bs/cfp/step3_thanks.html")
224218

225219

226-
@mark.django_db
227220
def test_thanks_page_contains_link_to_preview_proposal(user_client):
228221
create_conference_with_open_cfp()
229222
talk = TalkFactory()
@@ -235,7 +228,6 @@ def test_thanks_page_contains_link_to_preview_proposal(user_client):
235228
assert preview_link in response.content.decode()
236229

237230

238-
@mark.django_db
239231
def test_preview_page_renders_correct_content(user_client):
240232
create_conference_with_open_cfp()
241233
talk = TalkFactory()
@@ -250,8 +242,7 @@ def test_preview_page_renders_correct_content(user_client):
250242
assert talk.abstract_extra in response.content.decode()
251243

252244

253-
@mark.django_db
254-
def test_preview_page_contains_edit_link_if_cfp_is_open_and_user_is_author(
245+
def test_preview_page_contains_edit_links_if_cfp_is_open_and_user_is_author(
255246
user_client
256247
):
257248
create_conference_with_open_cfp()
@@ -261,13 +252,14 @@ def test_preview_page_contains_edit_link_if_cfp_is_open_and_user_is_author(
261252
talk.save()
262253
preview_url = reverse("cfp:preview", args=[talk.slug])
263254
edit_link = reverse("cfp:update", args=[talk.uuid])
255+
speaker_edit_link = reverse("cfp:update_speakers", args=[talk.uuid])
264256

265257
response = user_client.get(preview_url)
266258

267259
assert edit_link in response.content.decode()
260+
assert speaker_edit_link in response.content.decode()
268261

269262

270-
@mark.django_db
271263
def test_preview_page_doesnt_contain_edit_link_if_cfp_is_open_but_user_is_not_author( # NOQA
272264
user_client
273265
):
@@ -276,13 +268,14 @@ def test_preview_page_doesnt_contain_edit_link_if_cfp_is_open_but_user_is_not_au
276268
talk.setAbstract("some abstract")
277269
preview_url = reverse("cfp:preview", args=[talk.slug])
278270
edit_link = reverse("cfp:update", args=[talk.uuid])
271+
speaker_edit_link = reverse("cfp:update_speakers", args=[talk.uuid])
279272

280273
response = user_client.get(preview_url)
281274

282275
assert edit_link not in response.content.decode()
276+
assert speaker_edit_link not in response.content.decode()
283277

284278

285-
@mark.django_db
286279
def test_preview_page_doesnt_contain_edit_link_if_cfp_is_closed_and_user_is_author( # NOQA
287280
user_client
288281
):
@@ -296,13 +289,14 @@ def test_preview_page_doesnt_contain_edit_link_if_cfp_is_closed_and_user_is_auth
296289
talk.setAbstract("some abstract")
297290
preview_url = reverse("cfp:preview", args=[talk.slug])
298291
edit_link = reverse("cfp:update", args=[talk.uuid])
292+
speaker_edit_link = reverse("cfp:update_speakers", args=[talk.uuid])
299293

300294
response = user_client.get(preview_url)
301295

302296
assert edit_link not in response.content.decode()
297+
assert speaker_edit_link not in response.content.decode()
303298

304299

305-
@mark.django_db
306300
def test_regular_user_cant_access_program_wg_download(user_client):
307301
LOGIN_REQUIRED_302 = 302
308302
Conference.objects.create(
@@ -315,7 +309,6 @@ def test_regular_user_cant_access_program_wg_download(user_client):
315309
assert redirects_to(response, "/admin/login/")
316310

317311

318-
@mark.django_db
319312
def test_admin_user_can_access_program_wg_download(admin_client):
320313
Conference.objects.create(
321314
code=settings.CONFERENCE_CONFERENCE,
@@ -327,35 +320,46 @@ def test_admin_user_can_access_program_wg_download(admin_client):
327320
assert response.json() == {"talks": []}
328321

329322

330-
@mark.django_db
331-
def test_update_page_works_if_cfp_is_open_and_user_is_author(user_client):
323+
@mark.parametrize(
324+
"page_name, template",
325+
[
326+
("cfp:update", "ep19/bs/cfp/update_proposal.html"),
327+
("cfp:update_speakers", "ep19/bs/cfp/update_speakers.html"),
328+
],
329+
)
330+
def test_update_pages_work_if_cfp_is_open_and_user_is_author(user_client, page_name, template):
332331
create_conference_with_open_cfp()
333332
talk = TalkFactory()
334333
talk.setAbstract("some abstract")
335334
talk.created_by = user_client.user
336335
talk.save()
337-
edit_url = reverse("cfp:update", args=[talk.uuid])
336+
edit_url = reverse(page_name, args=[talk.uuid])
338337

339338
response = user_client.get(edit_url)
340339

341340
assert response.status_code == 200
342-
assert template_used(response, "ep19/bs/cfp/update_proposal.html")
341+
assert template_used(response, template)
343342

344343

345-
@mark.django_db
346-
def test_update_page_doesnt_work_if_cfp_is_open_but_user_is_not_author(
347-
user_client
344+
@mark.parametrize(
345+
"page_name",
346+
[
347+
"cfp:update",
348+
"cfp:update_speakers",
349+
],
350+
)
351+
def test_update_pages_dont_work_if_cfp_is_open_but_user_is_not_author(
352+
user_client, page_name,
348353
):
349354
create_conference_with_open_cfp()
350355
talk = TalkFactory()
351356
talk.setAbstract("some abstract")
352-
edit_url = reverse("cfp:update", args=[talk.uuid])
357+
edit_url = reverse(page_name, args=[talk.uuid])
353358

354359
response = user_client.get(edit_url)
355360
assert response.status_code == 403
356361

357362

358-
@mark.django_db
359363
def test_preview_page_doesnt_work_if_cfp_is_closed_and_user_is_author(
360364
user_client
361365
):
@@ -375,7 +379,6 @@ def test_preview_page_doesnt_work_if_cfp_is_closed_and_user_is_author(
375379
assert response.status_code == 403
376380

377381

378-
@mark.django_db
379382
def test_validation_errors_are_handled_on_update_proposal(user_client):
380383
"""
381384
NOTE(artcz)
@@ -399,7 +402,6 @@ def test_validation_errors_are_handled_on_update_proposal(user_client):
399402
assert template_used(response, "ep19/bs/cfp/update_proposal.html")
400403

401404

402-
@mark.django_db
403405
def test_update_proposal_updates_proposal(user_client):
404406
create_conference_with_open_cfp()
405407
talk = TalkFactory()
@@ -441,8 +443,45 @@ def test_update_proposal_updates_proposal(user_client):
441443
assert talk_dict["speakers"] == []
442444

443445

446+
def test_update_speaker_updated_speaker(user_client):
447+
create_conference_with_open_cfp()
448+
talk = TalkFactory()
449+
talk.setAbstract("some abstract")
450+
talk.created_by = user_client.user
451+
talk.save()
452+
453+
edit_url = reverse("cfp:update_speakers", args=[talk.uuid])
454+
speaker_data = dict(
455+
users_given_name="new name",
456+
is_minor=True,
457+
job_title="goat",
458+
phone="+48123456789",
459+
gender="yes",
460+
company="widgets inc",
461+
company_homepage="www.widgets.inc",
462+
bio="this is my bio",
463+
)
464+
465+
response = user_client.post(edit_url, speaker_data)
466+
467+
assert response.status_code == 302
468+
assert redirects_to(response, reverse("cfp:preview", args=[talk.slug]))
469+
470+
user = user_client.user
471+
user.refresh_from_db()
472+
attendee_profile = user.attendeeprofile
473+
attendee_profile.refresh_from_db()
474+
assert user.first_name == speaker_data["users_given_name"]
475+
assert attendee_profile.phone == speaker_data["phone"]
476+
assert attendee_profile.is_minor == speaker_data["is_minor"]
477+
assert attendee_profile.job_title == speaker_data["job_title"]
478+
assert attendee_profile.gender == speaker_data["gender"]
479+
assert attendee_profile.company == speaker_data["company"]
480+
assert speaker_data["company_homepage"] in attendee_profile.company_homepage
481+
assert attendee_profile.getBio().body == speaker_data["bio"]
482+
483+
444484
# Mark with django db only because AddSpeakerToTalkForm is a ModelForm
445-
@mark.django_db
446485
@mark.parametrize(
447486
"valid_phone", ["+48123456789", "+44 7 123 456 789", "+1 858 712 8966"]
448487
)
@@ -459,7 +498,6 @@ def test_speaker_form_accepts_valid_international_mobile_numbers(valid_phone):
459498

460499

461500
# Mark with django db only because AddSpeakerToTalkForm is a ModelForm
462-
@mark.django_db
463501
@mark.parametrize(
464502
"invalid_phone",
465503
["SOME RANODM TEXT", "+4471343956789", "+4412445367"],

0 commit comments

Comments
 (0)